예제 #1
0
class ModerateFontTestCase(TestCase):
    def setUp(self):
        super(ModerateFontTestCase, self).setUp()
        self.user = UserFactory(is_superuser=True, username='******')
        self.font_1 = FontFactory(owner=self.user, status=STATUS_ON_REVIEW)

    def test_moderate_publish_font(self):
        relation = AdminFontRelationFactory(user=self.user,
                                            font=self.font_1,
                                            moderated=False)
        self.assertEqual(self.font_1.status, STATUS_ON_REVIEW)
        relation.moderated = True
        relation.save()
        self.font_1.refresh_from_db()
        self.assertEqual(self.font_1.status, STATUS_PUBLIC)

    def test_moderate_publish_font_not_admin(self):
        self.user_2 = UserFactory(username='******')
        relation = AdminFontRelationFactory(user=self.user_2,
                                            font=self.font_1,
                                            moderated=False)
        self.assertEqual(self.font_1.status, STATUS_ON_REVIEW)
        relation.moderated = True
        relation.save()
        self.font_1.refresh_from_db()
        self.assertEqual(self.font_1.status, STATUS_ON_REVIEW)
예제 #2
0
 def setUp(self):
     super(FontsGetTestCase, self).setUp()
     self.author = AuthorFactory(name='Some Author')
     self.font_1 = FontFactory(owner=self.user, author=self.author)
     self.font_2 = FontFactory(owner=self.user, author=self.author)
     self.user_font_relation_1 = UserFontRelationFactory(user=self.user, font=self.font_1)
     self.url_list = reverse('fonts-relations-list')
     self.url_1 = reverse('fonts-relations-detail', args=(self.font_1.pk,))
     self.url_2 = reverse('fonts-relations-detail', args=(self.font_2.pk,))
예제 #3
0
 def setUp(self):
     super(SymbolsCountTestCase, self).setUp()
     self.author = AuthorFactory()
     self.font_1 = FontFactory(owner=self.user,
                               content='THE',
                               author=self.author)
     self.font_2 = FontFactory(owner=self.user,
                               content='HER',
                               author=self.author)
     self.symbol_1 = SymbolFactory(font=self.font_1)
     self.symbol_2 = SymbolFactory(font=self.font_1)
     self.symbol_3 = SymbolFactory(font=self.font_2)
     self.url = reverse("symbols-count-list")
예제 #4
0
 def setUp(self):
     super(FontDeleteTestCase, self).setUp()
     self.font_1 = FontFactory(owner=self.user, content='THE')
     self.admin_font_relation = AdminFontRelationFactory(user=self.user,
                                                         font=self.font_1)
     self.symbol_1 = SymbolFactory(font=self.font_1)
     self.url = reverse("fonts-detail", args=(self.font_1.pk, ))
예제 #5
0
 def setUp(self):
     super(FontsGetTestCase, self).setUp()
     self.user = UserFactory(is_superuser=True, username='******')
     self.client.force_authenticate(user=self.user)
     self.author = AuthorFactory(name='Mr. Writer')
     self.font_1 = FontFactory(owner=self.user, content='THE')
     self.font_2 = FontFactory(owner=self.user,
                               author=self.author,
                               content='HER')
     self.admin_font_relation = AdminFontRelationFactory(user=self.user,
                                                         font=self.font_1)
     self.admin_font_relation_2 = AdminFontRelationFactory(user=self.user,
                                                           font=self.font_2)
     self.symbol_1 = SymbolFactory(font=self.font_1)
     self.symbol_2 = SymbolFactory(font=self.font_1)
     self.symbol_3 = SymbolFactory(font=self.font_2)
     self.url = reverse("fonts-list")
예제 #6
0
    def setUp(self):
        super(AuthorsTestCase, self).setUp()
        self.user_2 = UserFactory(username='******')

        self.author = AuthorFactory(name='Mr. Writer')
        self.font_1 = FontFactory(author=self.author, owner=self.user)
        self.admin_font_relation = UserFontRelationFactory(user=self.user,
                                                           font=self.font_1,
                                                           like=True)
        self.admin_font_relation = UserFontRelationFactory(user=self.user_2,
                                                           font=self.font_1,
                                                           like=True)
        self.font_2 = FontFactory(author=self.author, owner=self.user)
        self.admin_font_relation = UserFontRelationFactory(user=self.user,
                                                           font=self.font_2,
                                                           like=True)
        self.admin_font_relation = UserFontRelationFactory(user=self.user_2,
                                                           font=self.font_2,
                                                           like=True)
        self.font_3 = FontFactory(author=self.author, owner=self.user)

        self.author_2 = AuthorFactory(name='Mr. Peter')
        self.font_4 = FontFactory(author=self.author_2, owner=self.user)
        self.admin_font_relation = UserFontRelationFactory(user=self.user,
                                                           font=self.font_4,
                                                           like=True)
        self.admin_font_relation = UserFontRelationFactory(user=self.user_2,
                                                           font=self.font_4,
                                                           like=True)

        self.author_3 = AuthorFactory(name='Mr. Killer')
        self.font_5 = FontFactory(author=self.author_3, owner=self.user)
        self.admin_font_relation = UserFontRelationFactory(user=self.user_2,
                                                           font=self.font_5,
                                                           like=True)
        self.font_6 = FontFactory(author=self.author_3, owner=self.user)

        self.url = reverse("authors-list")
예제 #7
0
class FontsGetTestCase(APITestCase):
    def setUp(self):
        super(FontsGetTestCase, self).setUp()
        self.user = UserFactory(is_superuser=True, username='******')
        self.client.force_authenticate(user=self.user)
        self.author = AuthorFactory(name='Mr. Writer')
        self.font_1 = FontFactory(owner=self.user, content='THE')
        self.font_2 = FontFactory(owner=self.user,
                                  author=self.author,
                                  content='HER')
        self.admin_font_relation = AdminFontRelationFactory(user=self.user,
                                                            font=self.font_1)
        self.admin_font_relation_2 = AdminFontRelationFactory(user=self.user,
                                                              font=self.font_2)
        self.symbol_1 = SymbolFactory(font=self.font_1)
        self.symbol_2 = SymbolFactory(font=self.font_1)
        self.symbol_3 = SymbolFactory(font=self.font_2)
        self.url = reverse("fonts-list")

    def test_get_font_with_image(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response.data[0]['image']['image_original'] = '/media/' + \
                                                      response.data[0]['image']['image_original'].split('/')[-1]
        response.data[1]['image']['image_original'] = '/media/' + \
                                                      response.data[1]['image']['image_original'].split('/')[-1]
        response.data[0]['image']['image_thumbnail'] = '/media/' + \
                                                       response.data[0]['image']['image_thumbnail'].split('/')[-1]
        response.data[1]['image']['image_thumbnail'] = '/media/' + \
                                                       response.data[1]['image']['image_thumbnail'].split('/')[-1]

        self.assertEqual(response.data, [
            FontGetSerializer(self.font_1).data,
            FontGetSerializer(self.font_2).data
        ])
        self.assertEqual(response.data[0]['author_name'], 'Mr. Author')
        self.assertEqual(response.data[1]['author_name'], 'Mr. Writer')

        symbol_1_data = SymbolForFontSerializer(self.symbol_1).data
        symbol_2_data = SymbolForFontSerializer(self.symbol_2).data
        symbol_3_data = SymbolForFontSerializer(self.symbol_3).data
        self.assertIn(symbol_1_data, response.data[0]['symbols'])
        self.assertIn(symbol_2_data, response.data[0]['symbols'])
        self.assertIn(symbol_3_data, response.data[1]['symbols'])

    def test_get_font_search_no_filter(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)

    def test_get_font_search_no_filter_one_no_moderated(self):
        self.user_not_admin = UserFactory(is_superuser=False,
                                          username='******')
        self.client.force_authenticate(user=self.user_not_admin)
        self.font_1.status = STATUS_ON_REVIEW
        self.font_1.save()
        self.admin_font_relation.moderated = False
        self.admin_font_relation.save()
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)

    def test_get_font_search_no_filter_one_no_moderated_if_admin(self):
        self.client.force_authenticate(
            user=UserFactory(is_superuser=True, username='******'))
        self.admin_font_relation.moderated = False
        self.admin_font_relation.save()
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)

    def test_get_font_search_one(self):
        response = self.client.get(self.url, data={'content_contains': 'ER'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)

    def test_get_font_search_two(self):
        response = self.client.get(self.url, data={'content_contains': 'HE'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)

    def test_get_font_search_three(self):
        response = self.client.get(self.url, data={'content_contains': 'T'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)

    def test_get_font_search_empty_content_exact(self):
        response = self.client.get(self.url, data={'content_exact': 'HE'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, [])

    def test_get_font_search_ok_content_exact(self):
        response = self.client.get(self.url, data={'content_exact': 'HER'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
예제 #8
0
 def setUp(self):
     super(ModerateFontTestCase, self).setUp()
     self.user = UserFactory(is_superuser=True, username='******')
     self.font_1 = FontFactory(owner=self.user, status=STATUS_ON_REVIEW)