<s> import sure <EOL> from mock import MagicMock <EOL> from testfixtures import LogCapture <EOL> from django . test import TestCase <EOL> from tools . mongo import MongoFlushMixin <EOL> from tasks . models import Tasks <EOL> from . . import travis_ci <EOL> class TravisCiServiceCase ( MongoFlushMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> mongo_flush = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> super ( TravisCiServiceCase , self ) . setUp ( ) <EOL> self . _orig_requests = travis_ci . requests <EOL> travis_ci . requests = MagicMock ( ) <EOL> def tearDown ( self ) : <EOL> travis_ci . requests = self . _orig_requests <EOL> def _create_task ( self ) : <EOL> """<STR_LIT>""" <EOL> task_id = Tasks . save ( { <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:15> , <EOL> } <EOL> } ) <EOL> return Tasks . find_one ( task_id ) <EOL> def test_fail_if_already_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _create_task ( ) <EOL> data = self . _create_task ( ) <EOL> with LogCapture ( ) as log_capture : <EOL> travis_ci . travis_ci_service ( data ) . should . be . none <EOL> list ( log_capture . actual ( ) ) [ <NUM_LIT:0> ] . should . contain ( '<STR_LIT>' ) <EOL> Tasks . find ( { } ) . count ( ) . should . be . equal ( <NUM_LIT:1> ) <EOL> def test_fail_on_travis_api_error ( self ) : <EOL> """<STR_LIT>""" <EOL> travis_ci . requests . get . side_effect = Exception <EOL> data = self . _create_task ( ) <EOL> with LogCapture ( ) as log_capture : <EOL> travis_ci . travis_ci_service ( data ) . should . be . none <EOL> list ( log_capture . actual ( ) ) [ <NUM_LIT:0> ] . should . contain ( '<STR_LIT>' ) <EOL> Tasks . find ( { } ) . count ( ) . should . be . equal ( <NUM_LIT:0> ) <EOL> def test_fail_on_wrong_project ( self ) : <EOL> """<STR_LIT>""" <EOL> travis_ci . requests . get . return_value = MagicMock ( <EOL> json = MagicMock ( return_value = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> ) <EOL> data = self . _create_task ( ) <EOL> with LogCapture ( ) as log_capture : <EOL> travis_ci . travis_ci_service ( data ) . should . be . none <EOL> list ( log_capture . actual ( ) ) [ <NUM_LIT:0> ] . should . contain ( '<STR_LIT>' ) <EOL> Tasks . find ( { } ) . count ( ) . should . be . equal ( <NUM_LIT:0> ) <EOL> def test_success ( self ) : <EOL> """<STR_LIT>""" <EOL> travis_ci . requests . get . return_value = MagicMock ( <EOL> json = MagicMock ( return_value = { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> } ) <EOL> ) <EOL> data = self . _create_task ( ) <EOL> travis_ci . travis_ci_service ( data ) . should . be . equal ( data [ '<STR_LIT>' ] ) </s>
