def test_author_update_deletes_a_author_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        self.client.delete(self.url)

        self.assertFalse(Author.objects.exists())
    def test_author_detail_returns_200_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        response = self.client.get(self.url)

        self.assertEqual(200, response.status_code)
Exemple #3
0
    def test_category_update_returns_204_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        response = self.client.delete(self.url)

        self.assertEqual(204, response.status_code)
    def test_author_update_returns_403_given_non_admin_user(self):
        user = UserFactory(is_staff=False)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        response = self.client.delete(self.url)

        self.assertEqual(403, response.status_code)
Exemple #5
0
    def test_category_create_creates_a_category_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {'name': 'Drama', 'description': 'Titanic stuff'}
        self.client.post(self.url,
                         json.dumps(body),
                         content_type='application/json')

        self.assertTrue(Category.objects.exists())
Exemple #6
0
    def test_category_create_returns_201_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {'name': 'Drama', 'description': 'Titanic stuff'}
        response = self.client.post(self.url,
                                    json.dumps(body),
                                    content_type='application/json')

        self.assertEqual(201, response.status_code)
    def test_author_create_creates_an_author_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {
            'name': 'Steven King'
        }
        self.client.post(self.url, json.dumps(body), content_type='application/json')

        self.assertTrue(Author.objects.exists())
    def test_author_create_returns_403_given_non_admin_user(self):
        user = UserFactory(is_staff=False)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {
            'name': 'Steven King'
        }
        response = self.client.post(self.url, json.dumps(body), content_type='application/json')

        self.assertEqual(403, response.status_code)
    def test_category_update_returns_403_given_non_admin_user(self):
        user = UserFactory(is_staff=False)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {
            'name': 'Drama',
            'description': 'Titanic stuff'
        }
        response = self.client.patch(self.url, json.dumps(body), content_type='application/json')

        self.assertEqual(403, response.status_code)
    def test_author_detail_returns_valid_response_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        expected_response = {
            'id': 999,
            'name': 'Steven King',
        }

        response = self.client.get(self.url)

        self.assertEqual(expected_response, response.json())
    def test_author_update_returns_200_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        body = {
            'name': 'Steven King',
        }
        response = self.client.patch(self.url,
                                     json.dumps(body),
                                     content_type='application/json')

        self.assertEqual(200, response.status_code)
    def test_category_detail_returns_valid_response_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        expected_response = {
            'id': 999,
            'name': 'Drama',
            'description': 'Titanic stuff'
        }

        response = self.client.get(self.url)

        self.assertEqual(expected_response, response.json())
    def test_author_list_returns_valid_response_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        AuthorFactory(id=999, name='Steven King')
        expected_response = {
            'total_count': 1,
            'total_pages': 1,
            'list': [{
                'id': 999,
                'name': 'Steven King',
            }]
        }
        response = self.client.get(self.url)

        self.assertTrue(expected_response, response.json())
    def test_category_list_returns_valid_response_given_valid_input(self):
        user = UserFactory(is_staff=True)
        token = TokenFactory(user=user)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        CategoryFactory(id=999, name='Drama', description='Titanic stuff')
        expected_response = {
            'total_count': 1,
            'total_pages': 1,
            'list': [{
                'id': 999,
                'name': 'Drama',
                'description': 'Titanic stuff'
            }]
        }
        response = self.client.get(self.url)

        self.assertTrue(expected_response, response.json())