Пример #1
0
    def test_text(self):

        quote = QuoteFactory(text='test')

        response = self.client.post('/api/', self.payload).json()

        self.assertEqual(response['text'], quote.get_text())
Пример #2
0
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)
Пример #3
0
    def test_last_hit(self):
        quote = QuoteFactory()

        self.client.post('/api/', self.payload)

        quote.refresh_from_db()

        self.assertIsNotNone(quote.last_hit)
Пример #4
0
    def test_hit_count(self):
        quote = QuoteFactory()

        self.client.post('/api/', self.payload)

        quote.refresh_from_db()

        self.assertEqual(quote.hit_count, 1)
Пример #5
0
    def test_last_hit(self):
        quote = QuoteFactory()

        self.client.post('/api/', self.payload)

        quote.refresh_from_db()

        self.assertIsNotNone(quote.last_hit)
Пример #6
0
    def test_hit_count(self):
        quote = QuoteFactory()

        self.client.post('/api/', self.payload)

        quote.refresh_from_db()

        self.assertEqual(quote.hit_count, 1)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
    def test_context(self):

        quote = QuoteFactory(context='test')

        response = self.client.post('/api/', self.payload).json()

        self.assertEqual(response['attachments'][0]['text'], quote.context)
Пример #11
0
    def test_one_record(self):
        """
        One record in database, should return record
        """

        q = QuoteFactory()

        self.assertEqual(quote.service.next(), q)
Пример #12
0
    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)
Пример #13
0
    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'], ' ')
Пример #14
0
    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'], ' ')