def test_beers(self): mfg = ManufacturerFactory() beers = Beer.objects.bulk_create( BeerFactory.build(manufacturer=mfg) for dummy in range(10)) taps = Tap.objects.bulk_create( Tap( beer=beer, tap_number=index + 1, venue=self.venue, ) for index, beer in enumerate(beers)) response = self.client.get(f"{self.url}beers/") self.assertEqual(len(taps), len(beers)) self.assertEqual(Beer.objects.count(), len(beers)) self.assertEqual(response.status_code, 200, response.data) self.assertEqual(len(response.data["results"]), len(beers))
def setUpTestData(cls): super().setUpTestData() cls.venue = VenueFactory() cls.normal_user = UserFactory() cls.styles = Style.objects.bulk_create(StyleFactory.build_batch(50)) cls.manufacturer = ManufacturerFactory() cls.beers = Beer.objects.bulk_create( BeerFactory.build(style=style, manufacturer=cls.manufacturer) for style in cls.styles) cls.taps = Tap.objects.bulk_create( TapFactory.build( beer=beer, venue=cls.venue, tap_number=index, ) for index, beer in enumerate(cls.beers)) VenueTapManager.objects.create( user=cls.normal_user, venue=cls.venue, )
def setUp(self): manufacturer = ManufacturerFactory() venue = VenueFactory() style = StyleFactory() self.beers = Beer.objects.bulk_create( BeerFactory.build( manufacturer=manufacturer, style=style, ) for _ in range(20)) self.prices = BeerPrice.objects.bulk_create( BeerPrice( # pint serving_size_id=1, price=index * 2.1, beer=beer, venue=venue, ) for index, beer in enumerate(self.beers)) self.taps = Tap.objects.bulk_create( # only for half of them TapFactory.build(beer=beer, venue=venue) for beer in self.beers[:10])
def test_multi_beer_more_to_come(self, mock_retry, mock_api): mfg = ManufacturerFactory() beers = Beer.objects.bulk_create( BeerFactory.build(manufacturer=mfg, style=None) for dummy in range(20)) Tap.objects.bulk_create( TapFactory.build(venue=self.venue, beer=beer) for beer in beers) with self.settings_context_manager(): tweet_about_beers([i.id for i in beers]) # pylint: disable=no-value-for-parameter beers = beers[:10] mock_retry.assert_not_called() mock_api.assert_called_once_with( consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, access_token_key=self.api_key, access_token_secret=self.api_secret, ) mock_api.return_value.PostUpdates.assert_called_once() mock_api.return_value.PostUpdate.assert_not_called() call_args = mock_api.return_value.PostUpdates.call_args self.assertEqual(call_args[1], {"continuation": "…", "threaded": True}) self.assertEqual(len(call_args[0]), 1) tweet = call_args[0][0] self.assertIn( MULTI_BEER_OUTER.format(len(beers), "(10 still to come!)").strip(), tweet, ) lines = tweet.splitlines() self.assertEqual(len(lines), 1 + len(beers)) for beer, line in zip(beers, lines[1:]): self.assertIn( MULTI_BEER_INNER.format( beer.name, "@" + beer.manufacturer.twitter_handle, "unknown", self.venue.name, ), line, )
def test_multi_beer(self, mock_retry, mock_api): mfg = ManufacturerFactory() beers = Beer.objects.bulk_create( BeerFactory.build(manufacturer=mfg, style=None) for dummy in range(10) ) Tap.objects.bulk_create( TapFactory.build(venue=self.venue, beer=beer) for beer in beers ) with self.settings_context_manager(): tweet_about_beers([i.id for i in beers]) mock_retry.assert_not_called() mock_api.assert_called_once_with( consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, access_token_key=self.api_key, access_token_secret=self.api_secret, ) mock_api.return_value.PostUpdates.assert_called_once() mock_api.return_value.PostUpdate.assert_not_called() call_args = mock_api.return_value.PostUpdates.call_args self.assertEqual(call_args[1], {'continuation': '…', 'threaded': True}) self.assertEqual(len(call_args[0]), 1) tweet = call_args[0][0] self.assertIn( MULTI_BEER_OUTER.format(len(beers), '').strip(), tweet, ) lines = tweet.splitlines() self.assertEqual(len(lines), 1 + len(beers)) for beer, line in zip(beers, lines[1:]): self.assertIn(MULTI_BEER_INNER.format( beer.name, '@' + beer.manufacturer.twitter_handle, 'unknown', self.venue.name, ), line)