Here are the examples of the python api mockito.any taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
61 Examples
5
Example 1
Project: astral Source File: test_streams.py
def test_create_stream(self):
mockito.when(StreamsAPI).create(source_uuid=mockito.any(),
name=mockito.any(), slug=mockito.any(),
description=mockito.any()).thenReturn(None)
data = {'name': faker.lorem.sentence()}
eq_(Stream.get_by(name=data['name']), None)
self.http_client.fetch(HTTPRequest(
self.get_url('/streams'), 'POST', body=json.dumps(data),
follow_redirects=False), self.stop)
response = self.wait()
eq_(response.code, 302)
ok_(Stream.get_by(name=data['name']))
3
Example 2
Project: tasksync Source File: test_sync.py
def test_known_from_downstream_stale(self):
d = self.downstream[0]
u = self.upstream[0]
d.associate_with(u)
d.mark_dirty()
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([u])
self._do_sync_all()
verify(self.downstream_repo).save(d, any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 3
Project: mythbox Source File: test_fanart.py
def test_getPosters_When_posters_not_in_cache_and_returned_by_next_in_chain_Then_cache_locally_and_return_posters(self):
# Setup
when(self.nextProvider).getPosters(any(Program)).thenReturn(['logo.gif'])
key = self.provider.createKey('getPosters', self.program)
self.assertNotIn(key, self.provider.imagePathsByKey)
# Test
posters = self.provider.getPosters(self.program)
# Verify
log.debug('Posters = %s' % posters)
self.assertEqual('logo.gif', posters[0])
self.assertIn(key, self.provider.imagePathsByKey)
3
Example 4
Project: mythbox Source File: test_toolkit.py
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))
3
Example 5
Project: mythbox Source File: test_fanart.py
def test_getSeasonAndEpisode_When_not_struck_out_and_delegate_returns_empty_tuple_Then_strike_out_and_return_nextProviders_result(self):
# Setup
provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
key = provider.createKey('getSeasonAndEpisode', self.program)
when(self.delegate).getSeasonAndEpisode(any()).thenReturn((None,None,))
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())
3
Example 6
Project: tasksync Source File: test_sync.py
def test_no_tasks(self):
when(self.downstream_repo).all().thenReturn([])
when(self.upstream_repo).all().thenReturn([])
self._do_sync_all()
verify(self.downstream_repo, 0).save(any(), any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 7
Project: mythbox Source File: test_settings.py
def test_When_existing_setting_changed_to_different_value_Then_event_published_to_bus(self):
# Setup
when(self.platform).getScriptDataDir().thenReturn(self.sandbox)
s = MythSettings(self.platform, self.translator, bus=self.bus)
# Test
s.get('mysql_host')
s.put('mysql_host', 'foo')
# Verify
verify(self.bus, 1).publish(any(dict))
3
Example 8
Project: pixelated-user-agent Source File: test_mail_sender.py
@defer.inlineCallbacks
def test_problem_with_email_raises_exception(self):
input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.fail(Exception('pretend something went wrong')))
try:
yield self.sender.sendmail(input_mail)
self.fail('Exception expected!')
except MailSenderException, e:
for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
self.assertTrue(recipient in e.email_error_map)
3
Example 9
Project: pixelated-user-agent Source File: test_user_settings_resource.py
def setUp(self):
self.services = mock()
self.mail_service = mock()
self.mail_service.account_email = MAIL_ADDRESS
self.keymanager = mock()
self.services_factory = mock()
self.services_factory.mode = UserAgentMode(is_single_user=True)
self.services.mail_service = self.mail_service
self.services.keymanager = self.keymanager
self.services_factory._services_by_user = {'someuserid': self.keymanager}
self.resource = UserSettingsResource(self.services_factory)
when(self.services_factory).services(any()).thenReturn(self.services)
self.web = DummySite(self.resource)
3
Example 10
Project: mythbox Source File: test_upcoming.py
def test_formattedAirDate_When_previous_program_today_and_current_program_tomorrow_Then_return_tomorrow(self):
when(self.current).starttimeAsTime().thenReturn(self.tomorrow)
when(self.previous).starttimeAsTime().thenReturn(self.today)
when(self.translator).get(any(int)).thenReturn('Tomorrow')
airDate = self.urw.formattedAirDate(self.previous, self.current)
log.debug('Air date: %s' % airDate)
self.assertEqual('Tomorrow', airDate)
3
Example 11
Project: tasksync Source File: test_sync.py
def test_known_deleted_from_upstream_with_orphan_removal(self):
d = self.downstream[0]
d.associate_with(self.upstream[0])
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([])
self.execution['downstream']['delete_orphans'] = True
self._do_sync_all()
verify(self.downstream_repo).delete(d, any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 12
Project: mythbox Source File: test_fanart.py
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)
3
Example 13
Project: pixelated-user-agent Source File: test_drafts.py
@defer.inlineCallbacks
def test_post_sends_mail_even_when_draft_does_not_exist(self):
# act as if sending the mail by SMTP succeeded
sendmail_deferred = defer.Deferred()
when(self.app_test_client.mail_sender).sendmail(any()).thenReturn(sendmail_deferred)
first_draft = MailBuilder().with_subject('First draft').build_json()
res = self.post_mail(first_draft)
sendmail_deferred.callback(True)
yield res
sent_mails = yield self.app_test_client.get_mails_by_tag('sent')
drafts = yield self.app_test_client.get_mails_by_tag('drafts')
self.assertEquals(1, len(sent_mails))
self.assertEquals('First draft', sent_mails[0].subject)
self.assertEquals(0, len(drafts))
3
Example 14
Project: mythbox Source File: test_fanart.py
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)
3
Example 15
Project: astral Source File: test_tickets.py
def test_remote_source(self):
node = Node.me()
node.supernode = True
remote_node = NodeFactory()
mockito.when(TicketsAPI).create(mockito.any(),
destination_uuid=mockito.any()).thenReturn(
{'source': remote_node.uuid,
'source_port': 42,
'hops': 1})
stream = StreamFactory()
tickets_before = Ticket.query.count()
self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()),
'POST', body=''), self.stop)
response = self.wait()
eq_(response.code, 200)
eq_(Ticket.query.count(), tickets_before + 1)
3
Example 16
Project: mythbox Source File: test_fanart.py
def test_getSeasonAndEpisode_When_not_in_cache_Then_ask_next_provider(self):
# Given
when(self.nextProvider).getSeasonAndEpisode(any(Program)).thenReturn(('5','12'))
key = self.provider.createEpisodeKey('getSeasonAndEpisode', self.program)
self.assertNotIn(key, self.provider.imagePathsByKey)
# When
season, episode = self.provider.getSeasonAndEpisode(self.program)
# Then
self.assertEqual('5', season)
self.assertEqual('12', episode)
self.assertEqual(('5','12'), self.provider.imagePathsByKey.get(key))
3
Example 17
Project: tasksync Source File: test_sync.py
def test_unknown_from_downstream_filter_drop(self):
d = self.downstream[0]
u = self.upstream[0]
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([])
# Filter only happens after create.
when(self.upstream_factory).create_from(other=d).thenReturn(u)
self.execution['upstream']['filter'] = lambda d, u: False
self._do_sync_all()
verify(self.downstream_repo, 0).save(any(), any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 18
Project: mythbox Source File: test_player.py
def test_RecordingWithNoCommBreaksDoesNothing(self):
# Setup
when(self.player).isPlaying().thenReturn(True)
when(self.program).getCommercials().thenReturn([])
when(self.player).getTime().thenReturn(500)
# Test
skipper = TrackingCommercialSkipper(self.player, self.program, self.translator)
skipper.onPlayBackStarted()
time.sleep(1)
when(self.player).isPlaying().thenReturn(False)
skipper.onPlayBackStopped()
# Verify
verify(self.player, times(0)).seekTime(any())
3
Example 19
Project: mythbox Source File: test_player.py
def test_PlayerNeverEntersAnyCommBreaks(self):
# Setup
when(self.player).isPlaying().thenReturn(True)
when(self.program).getCommercials().thenReturn([CommercialBreak(100, 200), CommercialBreak(600, 700)])
when(self.player).getTime().thenReturn(500)
# Test
skipper = TrackingCommercialSkipper(self.player, self.program, self.translator)
skipper.onPlayBackStarted()
time.sleep(2)
when(self.player).isPlaying().thenReturn(False)
skipper.onPlayBackStopped()
# Verify
verify(self.player, times(0)).seekTime(any())
3
Example 20
Project: mythbox Source File: test_upcoming.py
def test_formattedAirDate_When_previous_program_is_none_and_current_program_airs_tomorrow_Then_return_tomorrow(self):
when(self.current).starttimeAsTime().thenReturn(self.tomorrow)
when(self.translator).get(any(int)).thenReturn('Tomorrow')
airDate = self.urw.formattedAirDate(previous=None, current=self.current)
log.debug('Air date: %s' % airDate)
self.assertEqual('Tomorrow', airDate)
3
Example 21
Project: tasksync Source File: test_sync.py
def test_unknown_from_upstream(self):
d = self.downstream[0]
u = self.upstream[0]
when(self.downstream_repo).all().thenReturn([])
when(self.upstream_repo).all().thenReturn([u])
when(self.downstream_factory).create_from(other=u).thenReturn(d)
self._do_sync_all()
verify(self.downstream_repo).save(d, any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 22
Project: tasksync Source File: test_sync.py
def test_unknown_from_upstream_filter_drop(self):
d = self.downstream[0]
u = self.upstream[0]
when(self.downstream_repo).all().thenReturn([])
when(self.upstream_repo).all().thenReturn([u])
# Filter only happens after create.
when(self.downstream_factory).create_from(other=u).thenReturn(d)
self.execution['downstream']['filter'] = lambda u, d: False
self._do_sync_all()
verify(self.downstream_repo, 0).save(any(), any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 23
Project: astral Source File: test_tickets.py
def test_fallback_to_another_remote_node(self):
node = Node.me()
node.supernode = True
remote_node = NodeFactory()
mockito.when(TicketsAPI).create(mockito.any(),
destination_uuid=mockito.any()).thenReturn(
{'source': remote_node.uuid,
'source_port': 42,
'hops': 1})
stream = StreamFactory()
tickets_before = Ticket.query.count()
self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()),
'POST', body=''), self.stop)
response = self.wait()
eq_(response.code, 200)
eq_(Ticket.query.count(), tickets_before + 1)
3
Example 24
Project: tasksync Source File: test_sync.py
def test_known_deleted_from_upstream_no_orphan_removal(self):
d = self.downstream[0]
d.associate_with(self.upstream[0])
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([])
self._do_sync_all()
verify(self.downstream_repo, 0).delete(d)
verify(self.upstream_repo, 0).save(
any(), batch=any(), userdata=any(), cb=any())
3
Example 25
Project: mythbox Source File: test_domain.py
def test_isRecording_True(self):
when(self.conn).isTunerRecording(any()).thenReturn(True)
result = self.tuner.isRecording()
log.debug('isRecording_True = %s'%result)
self.assertTrue(result)
verify(self.conn).isTunerRecording(any())
3
Example 26
Project: mythbox Source File: test_fanart.py
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)
3
Example 27
Project: mythbox Source File: test_fanart.py
def test_getPosters_When_next_link_in_chain_returns_posters_Then_cache_locally_on_filesystem(self):
# Setup
when(self.nextProvider).getPosters(any(Program)).thenReturn(['http://www.google.com/intl/en_ALL/images/logo.gif'])
when(self.httpCache).get(any(str)).thenReturn('logo.gif')
# Test
posters = self.provider.getPosters(self.program)
# Verify
log.debug('Posters= %s' % posters)
self.assertEqual('logo.gif', posters[0])
3
Example 28
Project: astral Source File: test_ticket.py
def test_get(self):
node = Node.me()
ticket = TicketFactory(destination=node)
mockito.when(TicketsAPI).create(mockito.any(),
destination_uuid=mockito.any()).thenReturn(
{'source': ticket.destination.uuid,
'source_port': ticket.source_port,
'hops': ticket.hops})
response = self.fetch(ticket.absolute_url())
eq_(response.code, 200)
result = json.loads(response.body)
ok_('ticket' in result)
eq_(result['ticket']['stream'], ticket.stream.slug)
3
Example 29
Project: mythbox Source File: test_fanart.py
def test_clear_When_struckout_not_empty_Then_empties_struckout_and_forwards_to_delegate(self):
# Setup
provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
provider.struckOut[self.program.title()] = self.program.title()
# Test
provider.clear()
# Verify
self.assertFalse(len(provider.struckOut))
verify(self.delegate, times=1).clear(any())
3
Example 30
Project: mythbox Source File: test_upcoming.py
def test_formattedAirDate_When_previous_program_is_none_and_current_program_airs_today_Then_return_today(self):
when(self.current).starttimeAsTime().thenReturn(self.today)
when(self.translator).get(any(int)).thenReturn('Today')
airDate = self.urw.formattedAirDate(previous=None, current=self.current)
log.debug('Air date: %s' % airDate)
self.assertEqual('Today', airDate)
3
Example 31
Project: mythbox Source File: test_fanart.py
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)
3
Example 32
Project: pixelated-user-agent Source File: test_mail_sender.py
@defer.inlineCallbacks
def test_iterates_over_recipients(self):
input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
yield self.sender.sendmail(input_mail)
for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient))
3
Example 33
Project: mythbox Source File: test_fanart.py
def test_pickling(self):
when(self.nextProvider).getPosters(any(Program)).thenReturn(['logo.gif'])
for p in self.programs(20000):
self.provider.getPosters(p)
self.provider.close()
filesize = os.path.getsize(self.provider.pfilename)
log.debug('Pickle file size = %d' % filesize)
self.assertGreater(filesize, 0)
3
Example 34
Project: astral Source File: test_tickets.py
def test_none_available(self):
mockito.when(TicketsAPI).create(mockito.any(),
destination_uuid=mockito.any()).thenReturn(None)
stream = StreamFactory()
tickets_before = Ticket.query.count()
self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()),
'POST', body=''), self.stop)
response = self.wait()
eq_(response.code, 412)
eq_(Ticket.query.count(), tickets_before)
3
Example 35
Project: mythbox Source File: test_fanart.py
def test_getPosters_When_next_link_in_chain_doesnt_find_posters_Then_dont_cache_anything(self):
# Setup
when(self.nextProvider).getPosters(any(Program)).thenReturn([])
key = self.provider.createKey('getPosters', self.program)
self.assertNotIn(key, self.provider.imagePathsByKey)
# Test
posters = self.provider.getPosters(self.program)
# Verify
self.assertListEqual([], posters)
self.assertNotIn(key, self.provider.imagePathsByKey)
3
Example 36
Project: tasksync Source File: test_sync.py
def test_unknown_from_downstream(self):
d = self.downstream[0]
u = self.upstream[0]
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([])
when(self.upstream_factory).create_from(other=d).thenReturn(u)
self._do_sync_all()
verify(self.downstream_repo, 0).save(any(), any(), any(), any())
verify(self.upstream_repo).save(u, any(), any(), any())
3
Example 37
Project: mythbox Source File: test_feeds.py
def test_getLatestEntries_None(self):
# Setup
settings = Mock()
when(settings).get(any()).thenReturn('blah')
feedHose = FeedHose(settings=settings, bus=Mock())
# Test
entries = feedHose.getLatestEntries()
# Verify
self.assertTrue(len(entries) == 0)
3
Example 38
Project: pixelated-user-agent Source File: test_mail_sender.py
@defer.inlineCallbacks
def test_send_leaves_mail_in_tact(self):
input_mail_dict = mail_dict()
input_mail = InputMail.from_dict(input_mail_dict, from_address='pixelated@org')
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
yield self.sender.sendmail(input_mail)
self.assertEqual(input_mail.to, input_mail_dict["header"]["to"])
self.assertEqual(input_mail.cc, input_mail_dict["header"]["cc"])
self.assertEqual(input_mail.bcc, input_mail_dict["header"]["bcc"])
self.assertEqual(input_mail.subject, input_mail_dict["header"]["subject"])
3
Example 39
def setUp(self):
self.tracker = Mock()
self.translator = Mock()
when(self.translator).get(any()).thenReturn('some %s string')
self.player = Mock()
self.player.tracker = self.tracker
self.program = Mock()
when(self.program).title().thenReturn('movie.mpg')
3
Example 40
Project: tasksync Source File: test_sync.py
def test_known_from_downstream_not_stale(self):
d = self.downstream[0]
u = self.upstream[0]
d.associate_with(u)
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([u])
self._do_sync_all()
verify(self.downstream_repo, 0).save(any(), any(), any(), any())
verify(self.upstream_repo).save(u, any(), any(), any())
3
Example 41
Project: tasksync Source File: test_sync.py
def test_known_from_upstream(self):
d = self.downstream[0]
u = self.upstream[0]
d.associate_with(u)
d.mark_dirty()
when(self.downstream_repo).all().thenReturn([d])
when(self.upstream_repo).all().thenReturn([u])
self._do_sync_all()
verify(self.downstream_repo).save(d, any(), any(), any())
verify(self.upstream_repo, 0).save(any(), any(), any(), any())
3
Example 42
Project: pixelated-user-agent Source File: test_mail_sender.py
@defer.inlineCallbacks
def test_iterates_over_recipients_and_send_whitout_bcc_field(self):
input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
bccs = input_mail.bcc
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
yield self.sender.sendmail(input_mail)
for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
verify(OutgoingMail).send_message(MailToSmtpFormatCapture(recipient, bccs), TwistedSmtpUserCapture(recipient))
3
Example 43
Project: tornado-bootstrap Source File: entity_spec.py
def should_load_instances(self):
query = mock()
filtered_query = mock()
when(self.session).query(entity).thenReturn(query)
when(query).filter(any()).thenReturn(filtered_query)
when(filtered_query).first().thenReturn(self.msg)
assert self.repository.load(1) == self.msg
3
Example 44
Project: mythbox Source File: test_fanart.py
def test_getPosters_When_not_struck_out_and_delegate_returns_empty_list_Then_strike_out_and_return_nextProviders_result(self):
# Setup
provider = OneStrikeAndYoureOutFanartProvider(self.platform, self.delegate, self.nextProvider)
key = provider.createKey('getPosters', self.program)
when(self.delegate).getPosters(any()).thenReturn([])
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())
0
Example 45
Project: pyherc Source File: test_leveldecorator.py
def test_walls_can_be_ornamented(self):
"""
Ornaments should be placed only on walls
"""
wall_tile(self.level, (2, 2), self.wall)
wall_tile(self.level, (3, 2), self.wall)
wall_tile(self.level, (3, 2), self.wall)
rng = mock()
when(rng).randint(any(), any()).thenReturn(0)
when(rng).choice(any()).thenReturn(self.ornamentation)
self.config = WallOrnamentDecoratorConfig(
['any level'],
wall_tile = self.wall,
ornamentation = [self.ornamentation],
rng = rng,
rate = 100)
self.decorator = WallOrnamentDecorator(self.config)
self.decorator.decorate_level(self.level)
assert_that(ornamentation(self.level, (2, 2)),
is_(equal_to([self.ornamentation])))
0
Example 46
Project: pyherc Source File: test_leveldecorator.py
def test_ornamentation_rate_can_be_controlled(self):
"""
There should be way to control how frequently walls are ornamented
"""
wall_tile(self.level, (2, 2), self.wall)
wall_tile(self.level, (3, 2), self.wall)
wall_tile(self.level, (4, 2), self.wall)
rng = mock()
when(rng).randint(any(), any()).thenReturn(0).thenReturn(100).thenReturn(0)
when(rng).choice(any()).thenReturn(self.ornamentation)
self.config = WallOrnamentDecoratorConfig(
['any level'],
wall_tile = self.wall,
ornamentation = [self.ornamentation],
rng = rng,
rate = 50)
self.decorator = WallOrnamentDecorator(self.config)
self.decorator.decorate_level(self.level)
candle_count = 0
for location, tile in get_tiles(self.level):
if self.ornamentation in tile['\ufdd0:ornamentation']:
candle_count = candle_count + 1
assert_that(candle_count, is_(equal_to(2)))
0
Example 47
Project: pyherc Source File: test_leveldecorator.py
def test_only_northern_wall_is_decorated(self):
"""
Ornamentations should be placed only on northern walls
"""
wall_tile(self.level, (2, 2), self.wall)
wall_tile(self.level, (3, 2), self.wall)
wall_tile(self.level, (4, 2), self.wall)
floor_tile(self.level, (2, 3), self.floor)
floor_tile(self.level, (3, 3), self.floor)
floor_tile(self.level, (4, 3), self.floor)
wall_tile(self.level, (2, 4), self.wall)
wall_tile(self.level, (3, 4), self.wall)
wall_tile(self.level, (4, 4), self.wall)
floor_tile(self.level, (2, 5), self.empty_floor)
floor_tile(self.level, (4, 5), self.empty_floor)
floor_tile(self.level, (4, 5), self.empty_floor)
rng = mock()
when(rng).randint(any(), any()).thenReturn(0)
when(rng).choice(any()).thenReturn(self.ornamentation)
self.config = WallOrnamentDecoratorConfig(
['any level'],
wall_tile = self.wall,
ornamentation = [self.ornamentation],
rng = rng,
rate = 100)
self.decorator = WallOrnamentDecorator(self.config)
self.decorator.decorate_level(self.level)
assert_that(ornamentation(self.level, (2, 2)),
is_(equal_to([self.ornamentation])))
assert_that(ornamentation(self.level, (2, 4)),
is_(equal_to([])))
0
Example 48
Project: astral Source File: test_tickets.py
def test_other_known_tickets(self):
node = Node.me()
node.supernode = True
stream = StreamFactory()
existing_ticket = TicketFactory(stream=stream, source=stream.source,
hops=1)
mockito.when(TicketsAPI).create(mockito.any(),
destination_uuid=mockito.any()).thenReturn(
{'source': existing_ticket.destination.uuid,
'source_port': 42,
'hops': 1})
tickets_before = Ticket.query.count()
self.http_client.fetch(HTTPRequest(
self.get_url(stream.tickets_url()), 'POST', body=''),
self.stop)
response = self.wait()
eq_(response.code, 200)
eq_(Ticket.query.count(), tickets_before + 1)
ticket = Ticket.query.filter_by(destination=Node.me()).first()
eq_(ticket.source, existing_ticket.destination)
0
Example 49
Project: pixelated-user-agent Source File: test_drafts.py
@defer.inlineCallbacks
def test_post_sends_mail_and_deletes_previous_draft_if_it_exists(self):
# act as if sending the mail by SMTP succeeded
sendmail_deferred = defer.Deferred()
when(self.app_test_client.mail_sender).sendmail(any()).thenReturn(sendmail_deferred)
# creates one draft
first_draft = MailBuilder().with_subject('First draft').build_json()
first_draft_ident = (yield self.app_test_client.put_mail(first_draft)[0])['ident']
# sends an updated version of the draft
second_draft = MailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build_json()
deferred_res = self.post_mail(second_draft)
sendmail_deferred.callback(None) # SMTP succeeded
yield deferred_res
sent_mails = yield self.app_test_client.get_mails_by_tag('sent')
drafts = yield self.app_test_client.get_mails_by_tag('drafts')
# make sure there is one email in the sent mailbox and it is the second draft
self.assertEquals(1, len(sent_mails))
self.assertEquals('Second draft', sent_mails[0].subject)
# make sure that there are no drafts in the draft mailbox
self.assertEquals(0, len(drafts))
0
Example 50
Project: tornado-bootstrap Source File: entity_spec.py
def should_create_new_instances(self):
when(self.handler).param('field1').thenReturn("Field1 data")
when(self.handler).param('field2').thenReturn("Field2 data")
self.handler.post()
verify(self.repository).save(any(entity))