def test_text(self): quote = QuoteFactory(text='test') response = self.client.post('/api/', self.payload).json() self.assertEqual(response['text'], quote.get_text())
class QuoteServiceHitTestCase(TestCase): def setUp(self): self.quote = QuoteFactory() self.assertEqual(self.quote.hit_count, 0) self.assertIsNone(self.quote.last_hit) self.assertEqual(self.quote.author.hit_count, 0) self.assertIsNone(self.quote.author.last_hit) def test(self): quote_service.hit(quote=self.quote) self.quote.refresh_from_db() self.quote.author.refresh_from_db() self.assertEqual(self.quote.hit_count, 1) self.assertIsNotNone(self.quote.last_hit) self.assertEqual(self.quote.author.hit_count, 1) self.assertIsNotNone(self.quote.author.last_hit) def test_hit_twice(self): quote_service.hit(quote=self.quote) quote_service.hit(quote=self.quote) self.quote.refresh_from_db() self.quote.author.refresh_from_db() self.assertEqual(self.quote.hit_count, 2) self.assertEqual(self.quote.author.hit_count, 2)
def test_last_hit(self): quote = QuoteFactory() self.client.post('/api/', self.payload) quote.refresh_from_db() self.assertIsNotNone(quote.last_hit)
def test_hit_count(self): quote = QuoteFactory() self.client.post('/api/', self.payload) quote.refresh_from_db() self.assertEqual(quote.hit_count, 1)
def test_two_records_sequence(self): """ Two records in database, first records has a hit value, other does not. So it should return second record """ QuoteFactory(last_hit=timezone.now()) q = QuoteFactory() self.assertEqual(quote.service.next(), q)
def test_two_records(self): """ Two records in database, should return first records two times, since the next function is not responsible for updating the last_hit field so sequence is unchanged """ q = QuoteFactory() QuoteFactory() self.assertEqual(quote.service.next(), q) self.assertEqual(quote.service.next(), q)
def setUp(self): self.quote = QuoteFactory() self.assertEqual(self.quote.hit_count, 0) self.assertIsNone(self.quote.last_hit) self.assertEqual(self.quote.author.hit_count, 0) self.assertIsNone(self.quote.author.last_hit)
def test_context(self): quote = QuoteFactory(context='test') response = self.client.post('/api/', self.payload).json() self.assertEqual(response['attachments'][0]['text'], quote.context)
def test_one_record(self): """ One record in database, should return record """ q = QuoteFactory() self.assertEqual(quote.service.next(), q)
def test_tile_and_image(self): """ Test if two attachments are available. Attachment content is already tested in other tests. """ quote = QuoteFactory(image='image.jpg') TileFactory(quote=quote, template=TemplateFactory(), image='tile.jpg') response = self.client.post('/api/', self.payload).json() self.assertEqual(len(response['attachments']), 2)
def test_image(self): quote = QuoteFactory(image='test.jpg') response = self.client.post('/api/', self.payload).json() self.assertEqual(response['attachments'][0]['image_url'], 'http://testserver/{}'.format(quote.image)) self.assertEqual(response['attachments'][0]['thumb_url'], 'http://testserver/{}'.format(quote.image)) # If quote has no context a space is sent as text. Slack will not show image otherwise self.assertEqual(response['attachments'][0]['text'], ' ')
def test_tile(self): tile = TileFactory(quote_id=QuoteFactory().pk, template_id=TemplateFactory().pk, image='test.jpg') response = self.client.post('/api/', self.payload).json() self.assertEqual(response['attachments'][0]['image_url'], 'http://testserver/{}'.format(tile.image)) self.assertEqual(response['attachments'][0]['thumb_url'], 'http://testserver/{}'.format(tile.image)) # Is always a space self.assertEqual(response['attachments'][0]['text'], ' ')