Ejemplo n.º 1
0
 def testIfVerifiedVerifyZeroInteractionsStillRaises(self):
     when(Dog).bark('Miau')
     rex = Dog()
     rex.bark('Miau')
     verify(Dog).bark('Miau')
     with pytest.raises(VerificationError):
         verifyZeroInteractions(Dog)
Ejemplo n.º 2
0
 def testIfVerifiedVerifyZeroInteractionsStillRaises(self):
     when(Dog).bark('Miau')
     rex = Dog()
     rex.bark('Miau')
     verify(Dog).bark('Miau')
     with pytest.raises(VerificationError):
         verifyZeroInteractions(Dog)
Ejemplo n.º 3
0
    def test_market_open_does_not_trade(self):
        price = None
        self.exec_hanlder.accept_orders([self.order_1, self.order_4])
        self._set_price_for_now(price)
        self.exec_hanlder.on_market_open(...)

        verifyZeroInteractions(self.portfolio, self.spied_monitor)
def test_search_transliteration_empty(query, expected, fragment_finder,
                                      fragment_repository):
    spy2(fragment_repository.query_by_transliteration)
    query = TransliterationQuery(query)
    test_result = fragment_finder.search_transliteration(query)
    verifyZeroInteractions(fragment_repository)
    assert test_result == expected
    unstub()
Ejemplo n.º 5
0
    def test_no_orders_executed_on_market_open(self):
        self.exec_hanlder.on_market_open(...)
        verifyZeroInteractions(self.portfolio, self.spied_monitor)

        actual_orders = self.exec_hanlder.get_open_orders()
        expected_orders = [
            self.stop_loss_order_1, self.stop_loss_order_2,
            self.stop_loss_order_3
        ]
        assert_lists_equal(expected_orders, actual_orders)
Ejemplo n.º 6
0
    def test_compare_and_update_no_update(self):
        when(sut).check_and_update_wp(ANY(), ANY()).thenReturn(False)
        when(sut).check_and_update_plugins(ANY()).thenReturn(False)
        when(repush).RepositoryPusher(ANY())

        self.assertFalse(sut.compare_and_update(self.dummy_repo_path, "42"))

        verify(sut, times=1).check_and_update_wp(self.dummy_repo_path,
                                                 self.dummy_latest_version)
        verify(sut, times=1).check_and_update_plugins(self.dummy_repo_path)
        verifyZeroInteractions(repush)
Ejemplo n.º 7
0
 def test_store_When_channel_has_no_icon_Then_do_nothing(self):
     # Setup
     channel = Channel({'name':'Bogus Channel', 'icon':None, 'chanid': '9', 'callsign': 'WXYZ'})
     conn = Mock()
     downloader = MythChannelIconResolver(conn)
      
     # Test 
     downloader.store(channel, 'bogusDestDir')
 
     # Verify
     verifyZeroInteractions(conn)
Ejemplo n.º 8
0
    def test_rpc_cast_with_consumer_exception(self):
        mock_conn = mock()
        when(rpc).create_connection(new=True).thenRaise(IOError("host down"))
        exp_msg = RpcMsgMatcher("prepare", "memory_mb", "databases", "users", "device_path", "mount_point")

        with testtools.ExpectedException(exception.GuestError, ".* host down"):
            self.api.prepare("2048", "db1", "user1", "/dev/vdt", "/mnt/opt")

        verify(rpc).create_connection(new=True)
        verifyZeroInteractions(mock_conn)
        verify(rpc, never).cast(any(), any(), exp_msg)
Ejemplo n.º 9
0
    def test_3_orders_fill_only_at_open(self):
        self.exec_hanlder.accept_orders(
            [self.order_1, self.order_2, self.order_3])
        self._set_price_for_now(101)
        self.exec_hanlder.on_market_close(...)

        verifyZeroInteractions(self.portfolio, self.spied_monitor)

        actual_orders = self.exec_hanlder.get_open_orders()
        expected_orders = [self.order_1, self.order_2, self.order_3]
        assert_lists_equal(expected_orders, actual_orders)
Ejemplo n.º 10
0
    def test_process_img_repo_for_no_update_required(self):
        when(updater).compare_and_update(ANY(), ANY()).thenReturn(False)
        when(app).wait_for_build(ANY(), ANY())
        when(rpi.ReleasePipeline)
        when(pipe.Pipeline)

        app.process_img_repo(self.dummy_repo, self.dummy_img_repo_path, self.dummy_latest_version)

        verify(updater, times=1).compare_and_update(self.dummy_img_repo_path, self.dummy_latest_version)
        verify(app, times=0).wait_for_build(ANY(), ANY())
        verifyZeroInteractions(rpi.ReleasePipeline, pipe.Pipeline)
Ejemplo n.º 11
0
def test_start_process(dummy_kwargs):
    command = mock()
    when(command).run(async_=True)
    context = _run_context.RunContext(**dummy_kwargs)
    setattr(context, '_command', command)
    assert context.start_time == 0
    verifyZeroInteractions()
    context.start_process()
    assert context.start_time != 0
    verifyStubbedInvocationsAreUsed()
    verifyNoUnwantedInteractions()
Ejemplo n.º 12
0
 def test_getSeasonAndEpisode_When_found_in_cache_Then_return_cached_copy(self):
     # Given
     key = self.provider.createEpisodeKey('getSeasonAndEpisode', self.program)
     self.provider.imagePathsByKey[key] = ('5','12')
                     
     # When
     season, episode = self.provider.getSeasonAndEpisode(self.program)
     
     # Then
     self.assertEqual('5', season)
     self.assertEqual('12', episode)
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 13
0
 def test_getSeasonAndEpisode_When_found_in_cache_Then_return_cached_copy(self):
     # Given
     key = self.provider.createEpisodeKey('getSeasonAndEpisode', self.program)
     self.provider.imagePathsByKey[key] = ('5','12')
                     
     # When
     season, episode = self.provider.getSeasonAndEpisode(self.program)
     
     # Then
     self.assertEqual('5', season)
     self.assertEqual('12', episode)
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 14
0
    def test_order_not_executed_when_bar_for_today_is_incomplete(self):
        self._set_bar_for_today(open=None,
                                high=110.0,
                                low=100.0,
                                close=105.0,
                                volume=100000000.0)
        self.exec_hanlder.on_market_close(...)
        verifyZeroInteractions(self.portfolio, self.spied_monitor)

        actual_orders = self.exec_hanlder.get_open_orders()
        expected_orders = [self.stop_loss_order_1, self.stop_loss_order_2]
        assert_lists_equal(expected_orders, actual_orders)
Ejemplo n.º 15
0
 def test_getPosters_When_not_struck_out_and_delegate_returns_posters_Then_return_posters(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     when(self.delegate).getPosters(any()).thenReturn(['blah.png'])
     
     # Test
     posters = provider.getPosters(self.program)
     
     # Verify
     self.assertEqual('blah.png', posters[0])
     self.assertNotIn(self.program.title(), provider.struckOut.values())
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 16
0
 def test_getPosters_When_not_struck_out_and_delegate_returns_posters_Then_return_posters(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     when(self.delegate).getPosters(any()).thenReturn(['blah.png'])
     
     # Test
     posters = provider.getPosters(self.program)
     
     # Verify
     self.assertEqual('blah.png', posters[0])
     self.assertNotIn(self.program.title(), provider.struckOut.values())
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 17
0
    def test_rpc_cast_with_consumer_exception(self):
        mock_conn = mock()
        when(rpc).create_connection(new=True).thenRaise(IOError('host down'))
        exp_msg = RpcMsgMatcher('prepare', 'memory_mb', 'databases', 'users',
                                'device_path', 'mount_point')

        with testtools.ExpectedException(exception.GuestError, '.* host down'):
            self.api.prepare('2048', 'db1', 'user1', '/dev/vdt', '/mnt/opt')

        verify(rpc).create_connection(new=True)
        verifyZeroInteractions(mock_conn)
        verify(rpc, never).cast(any(), any(), exp_msg)
Ejemplo n.º 18
0
    def test_rpc_cast_with_consumer_exception(self):
        mock_conn = mock()
        when(rpc).create_connection(new=True).thenRaise(IOError('host down'))
        exp_msg = RpcMsgMatcher('prepare', 'memory_mb', 'databases', 'users',
                                'device_path', 'mount_point')

        with testtools.ExpectedException(exception.GuestError, '.* host down'):
            self.api.prepare('2048', 'db1', 'user1', '/dev/vdt', '/mnt/opt')

        verify(rpc).create_connection(new=True)
        verifyZeroInteractions(mock_conn)
        verify(rpc, never).cast(any(), any(), exp_msg)
Ejemplo n.º 19
0
 def test_enterText_Should_DoNothing_When_UserCancelsOperation(self):
     # Setup
     xbmc.Keyboard.stubConfirmed = False
     control = Mock()
     validator = Mock()
     updater = Mock()
     
     # Test
     enterText(control=control, validator=validator.validate, updater=updater.update)
     
     # Verify
     verifyZeroInteractions(validator)
     verifyZeroInteractions(updater)
Ejemplo n.º 20
0
 def test_getSeasonAndEpisode_When_not_struck_out_and_delegate_returns_season_and_episode_Then_return_season_and_episode(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     when(self.delegate).getSeasonAndEpisode(any()).thenReturn(('1','2',))
     
     # Test
     season, episode = provider.getSeasonAndEpisode(self.program)
     
     # Verify
     self.assertEqual('1', season)
     self.assertEqual('2', episode)
     self.assertNotIn(self.program.title(), provider.struckOut.values())
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 21
0
 def test_getSeasonAndEpisode_When_not_struck_out_and_delegate_returns_season_and_episode_Then_return_season_and_episode(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     when(self.delegate).getSeasonAndEpisode(any()).thenReturn(('1','2',))
     
     # Test
     season, episode = provider.getSeasonAndEpisode(self.program)
     
     # Verify
     self.assertEqual('1', season)
     self.assertEqual('2', episode)
     self.assertNotIn(self.program.title(), provider.struckOut.values())
     verifyZeroInteractions(self.nextProvider)
Ejemplo n.º 22
0
    def testClearsInvocations(self):
        theMock1 = mock()
        theMock2 = mock()
        theMock1.do_foo()
        theMock2.do_bar()

        self.assertRaises(VerificationError, verifyZeroInteractions, theMock1)
        self.assertRaises(VerificationError, verifyZeroInteractions, theMock2)

        forget_invocations(theMock1, theMock2)

        verifyZeroInteractions(theMock1)
        verifyZeroInteractions(theMock2)
Ejemplo n.º 23
0
    def testClearsInvocations(self):
        theMock1 = mock()
        theMock2 = mock()
        theMock1.do_foo()
        theMock2.do_bar()

        self.assertRaises(VerificationError, verifyZeroInteractions, theMock1)
        self.assertRaises(VerificationError, verifyZeroInteractions, theMock2)

        forget_invocations(theMock1, theMock2)

        verifyZeroInteractions(theMock1)
        verifyZeroInteractions(theMock2)
Ejemplo n.º 24
0
 def test_getPosters_When_struck_out_Then_skip_delegate_and_return_nextProviders_result(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     key = provider.createKey('getPosters', self.program)
     provider.strikeOut(key, self.program)
     when(self.nextProvider).getPosters(any()).thenReturn(['blah.png'])
     
     # Test
     posters = provider.getPosters(self.program)
     
     # Verify
     self.assertEqual('blah.png', posters[0])
     self.assertIn(self.program.title(), provider.struckOut[key].values())
     verifyZeroInteractions(self.delegate)
Ejemplo n.º 25
0
 def test_getPosters_When_struck_out_Then_skip_delegate_and_return_nextProviders_result(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     key = provider.createKey('getPosters', self.program)
     provider.strikeOut(key, self.program)
     when(self.nextProvider).getPosters(any()).thenReturn(['blah.png'])
     
     # Test
     posters = provider.getPosters(self.program)
     
     # Verify
     self.assertEqual('blah.png', posters[0])
     self.assertIn(self.program.title(), provider.struckOut[key].values())
     verifyZeroInteractions(self.delegate)
Ejemplo n.º 26
0
    def test_notification_that_is_not_to_a_paid_state(self):
        payload    = mockito.Mock()
        product    = self.create_from_factory(ValidProductFactory, price=200)
        purchase   = self.create_from_factory(ValidPurchaseFactory, product=product)
        payment    = self.create_from_factory(ValidPaymentFactory, type='dummy', purchase=purchase, amount=100)
        transition = self.create_from_factory(ValidTransitionToPendingFactory, payment=payment)

        mockito.when(self.dummy).notify(purchase, payment, payload, 'notification').thenReturn(transition)

        result = self.service.notify(purchase.id, payment.id, payload)
        self.assertEquals(payment.status, 'pending')
        self.assertEquals(result[0].status, 'pending')
        self.assertEquals(result[0].outstanding_amount, 200)
        mockito.verifyZeroInteractions(self.mailer)
Ejemplo n.º 27
0
 def test_getSeasonAndEpisode_When_struck_out_Then_skip_delegate_and_return_nextProviders_result(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     key = provider.createKey('getSeasonAndEpisode', self.program)
     provider.strikeOut(key, self.program)
     when(self.nextProvider).getSeasonAndEpisode(any()).thenReturn(('1','2'))
     
     # Test
     season, episode = provider.getSeasonAndEpisode(self.program)
     
     # Verify
     self.assertEqual('1', season)
     self.assertEqual('2', episode)
     self.assertIn(self.program.title(), provider.struckOut[key].values())
     verifyZeroInteractions(self.delegate)
Ejemplo n.º 28
0
    def test_enterText_Should_DoNothing_When_UserCancelsOperation(self):
        # Setup
        xbmc.Keyboard.stubConfirmed = False
        control = Mock()
        validator = Mock()
        updater = Mock()

        # Test
        enterText(control=control,
                  validator=validator.validate,
                  updater=updater.update)

        # Verify
        verifyZeroInteractions(validator)
        verifyZeroInteractions(updater)
Ejemplo n.º 29
0
 def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation(self):
     # Setup
     xbmc.Keyboard.stubConfirmed = True
     xbmc.Keyboard.stubText = 'Bubba'
     control = Mock()
     updater = Mock()
     validator = Mock()
     when(validator).validate(any()).thenRaise(Exception('Invalid name'))        
     
     # Test
     enterText(control=control, validator=validator.validate, updater=updater.update)
     
     # Verify
     verifyZeroInteractions(updater)
     verify(control, 0).setLabel(any(str), any(str))
Ejemplo n.º 30
0
 def test_getSeasonAndEpisode_When_struck_out_Then_skip_delegate_and_return_nextProviders_result(self):
     # Setup
     provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
     key = provider.createKey('getSeasonAndEpisode', self.program)
     provider.strikeOut(key, self.program)
     when(self.nextProvider).getSeasonAndEpisode(any()).thenReturn(('1','2'))
     
     # Test
     season, episode = provider.getSeasonAndEpisode(self.program)
     
     # Verify
     self.assertEqual('1', season)
     self.assertEqual('2', episode)
     self.assertIn(self.program.title(), provider.struckOut[key].values())
     verifyZeroInteractions(self.delegate)
Ejemplo n.º 31
0
    def test_notifications_that_cannot_be_processed_throws_its_errors(self):
        payload    = mockito.Mock()
        product    = self.create_from_factory(ValidProductFactory, price=200)
        purchase   = self.create_from_factory(ValidPurchaseFactory, product=product)
        payment    = self.create_from_factory(ValidPaymentFactory, type='dummy', purchase=purchase, amount=100)
        transition = self.create_from_factory(ValidTransitionToPendingFactory, payment=payment)

        mockito.when(self.dummy).notify(purchase, payment, payload, 'notification').thenRaise(InvalidPaymentNotification)
        with self.assertRaises(InvalidPaymentNotification):
            self.service.notify(purchase.id, payment.id, payload)

        mockito.when(self.dummy).notify(purchase, payment, payload, 'notification').thenRaise(PaymentVerificationFailed)
        with self.assertRaises(PaymentVerificationFailed):
            self.service.notify(purchase.id, payment.id, payload)

        mockito.verifyZeroInteractions(self.mailer)
Ejemplo n.º 32
0
    def test_notification_that_pays_the_balance_of_purchase(self):
        payload    = mockito.Mock()
        product    = self.create_from_factory(ValidProductFactory, price=200)
        purchase   = self.create_from_factory(ValidPurchaseFactory, product=product)
        payment    = self.create_from_factory(ValidPaymentFactory, type='dummy', purchase=purchase, amount=200)
        transition = self.create_from_factory(ValidTransitionToPaidFactory, payment=payment)

        mockito.when(self.dummy).notify(purchase, payment, payload, 'notification').thenReturn(transition)
        mockito.when(self.mailer).notify_payment(purchase, payment)

        result = self.service.notify(purchase.id, payment.id, payload)

        self.assertEquals(result[0].status, 'paid')
        self.assertEquals(payment.status, 'paid')
        mockito.verify(self.mailer).notify_payment(purchase, payment)
        mockito.verifyZeroInteractions(self.caravans)
Ejemplo n.º 33
0
    def test_store_When_channel_has_no_icon_Then_do_nothing(self):
        # Setup
        channel = Channel({
            'name': 'Bogus Channel',
            'icon': None,
            'chanid': '9',
            'callsign': 'WXYZ'
        })
        conn = Mock()
        downloader = MythChannelIconResolver(conn)

        # Test
        downloader.store(channel, 'bogusDestDir')

        # Verify
        verifyZeroInteractions(conn)
Ejemplo n.º 34
0
    def test_determine_last_updatedate_for_public_image(self):
        expected_result = "2020-03-12T10:11:56.603Z"
        dummy_parent_image = "ubuntu:18.04"

        when(DockerImageDetails)
        when(RepoDetails)
        when(ParentImage).is_public_image(ANY(str)).thenReturn(True)
        when(ParentImage).determine_last_updatedate(ANY(str)).thenReturn(expected_result)

        result = sut.determine_last_updatedate(dummy_parent_image, "")
        self.assertEqual(expected_result, result)

        verify(ParentImage, times=1).is_public_image(dummy_parent_image)
        verify(ParentImage, times=1).determine_last_updatedate(dummy_parent_image)
        verifyZeroInteractions(DockerImageDetails)
        verifyZeroInteractions(RepoDetails)
Ejemplo n.º 35
0
    def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation(
            self):
        # Setup
        xbmc.Keyboard.stubConfirmed = True
        xbmc.Keyboard.stubText = 'Bubba'
        control = Mock()
        updater = Mock()
        validator = Mock()
        when(validator).validate(any()).thenRaise(Exception('Invalid name'))

        # Test
        enterText(control=control,
                  validator=validator.validate,
                  updater=updater.update)

        # Verify
        verifyZeroInteractions(updater)
        verify(control, 0).setLabel(any(str), any(str))
Ejemplo n.º 36
0
    def test_determine_last_updatedate_for_private_image_with_static_version(self):
        expected_result = "2020-03-12T10:11:56.603Z"
        expected_json = {"lastUpdateTime": expected_result}
        dummy_parent_image = "orgdummy.azurecr.io/prj-infra-dummy:7.7"
        dummy_details = mock(DockerImageDetails)

        when(DockerImageDetails).from_FQDIN(ANY(str)).thenReturn(dummy_details)
        when(dummy_details).az_image_tag_details().thenReturn(expected_json)
        when(RepoDetails)
        when(ParentImage).is_public_image(ANY(str)).thenReturn(False)
        when(ParentImage).determine_last_updatedate(ANY(str)).thenReturn(expected_result)

        result = sut.determine_last_updatedate(dummy_parent_image, "")
        self.assertEqual(expected_result, result)

        verify(ParentImage, times=1).is_public_image(dummy_parent_image)
        verify(ParentImage, times=0).determine_last_updatedate(ANY(str))
        verify(DockerImageDetails, times=1).from_FQDIN(dummy_parent_image)
        verify(dummy_details, times=1).az_image_tag_details()
        verifyZeroInteractions(RepoDetails)
Ejemplo n.º 37
0
    def test_day_order_disappears_after_a_day(self):
        self._set_bar_for_today(open=105.0,
                                high=110.0,
                                low=100.0,
                                close=105.0,
                                volume=100000000.0)

        expected_orders = [
            self.stop_loss_order_1, self.stop_loss_order_2,
            self.stop_loss_order_3
        ]
        actual_orders = self.exec_hanlder.get_open_orders()
        assert_lists_equal(expected_orders, actual_orders)

        self.exec_hanlder.on_market_close(...)
        verifyZeroInteractions(self.portfolio, self.spied_monitor)

        actual_orders = self.exec_hanlder.get_open_orders()
        expected_orders = [self.stop_loss_order_1, self.stop_loss_order_2]
        assert_lists_equal(expected_orders, actual_orders)
Ejemplo n.º 38
0
 def testVerifyZeroInteractionsWorks(self):
     when(Dog).bark('Miau')
     verifyZeroInteractions(Dog)
Ejemplo n.º 39
0
 def testVerifies(self):
     theMock = mock()
     verifyZeroInteractions(theMock)
     theMock.foo()
     self.assertRaises(VerificationError, verifyNoMoreInteractions, theMock)
Ejemplo n.º 40
0
        def testPassIfVerifiedZeroInteractions(self):
            dog = mock()
            when(dog).waggle(1).thenReturn('Sure')
            verifyZeroInteractions(dog)

            verifyStubbedInvocationsAreUsed(dog)
 def assert_login_setup_service_for_user(_):
     verifyZeroInteractions(self.portal)
     mock_redirect.assert_called_once_with('/', self.request)
Ejemplo n.º 42
0
 def testVerifyZeroInteractionsWorks(self):
     dummy = spy(Dummy())
     verifyZeroInteractions(dummy)
Ejemplo n.º 43
0
 def testVerifyZeroInteractionsWorks(self):
     when(Dog).bark('Miau')
     verifyZeroInteractions(Dog)
Ejemplo n.º 44
0
 def testVerifies(self):
   theMock = mock()
   verifyZeroInteractions(theMock)
   theMock.foo()      
   self.assertRaises(VerificationError, verifyNoMoreInteractions, theMock)
 def assert_login_setup_service_for_user(_):
     verifyZeroInteractions(self.portal)
     mock_redirect.assert_called_once_with('/', self.request)
Ejemplo n.º 46
0
 def testVerifyZeroInteractionsWorks(self):
     dummy = spy(Dummy())
     verifyZeroInteractions(dummy)