Ejemplo n.º 1
0
 def test_articles_ar_paginated(self):
     '''See if  the return of get articles has count, next and previous articles'''
     url = API_Reverse('articles:articles')
     response = self.client.get(url)
     self.assertIn("next", response.data)
     self.assertIn("previous", response.data)
     self.assertIn("count", response.data)
Ejemplo n.º 2
0
    def setUp(self):
        self.url = API_Reverse('articles:articles')

        self.signup_url = API_Reverse('authentication:user-registration')

        self.user = {
            "user": {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**"
            }
        }

        self.article = {
            "article": {
                "title": "test article",
                "description": "This is test description",
                "body": "This is a test body"
            }
        }
Ejemplo n.º 3
0
 def test_user_can_delete(self):
     """This method tests if a user can delete articles"""
     token = self.create_user()
     response = self.client.post(self.url,
                                 self.article,
                                 format='json',
                                 HTTP_AUTHORIZATION=token)
     slug = response.data['slug']
     url = API_Reverse('articles:article-details', {slug: 'slug'})
     r = self.client.delete(url, format='json', HTTP_AUTHORIZATION=token)
     self.assertEqual(r.status_code, status.HTTP_200_OK)
     self.assertIn("Article Deleted Successfully", json.dumps(r.data))
Ejemplo n.º 4
0
    def setUp(self):
        self.url = API_Reverse('articles:articles')
        self.client = APIClient()
        self.unauthorised_client = APIClient()
        self.signup_url = API_Reverse('authentication:user-registration')    
        self.login_url = API_Reverse('authentication:user_login')    
        
        self.user = {
            "user": {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**"
            }
        }

        self.user2 = {
            "user": {
                "username": "******",
                "password": "******",
                "email": "*****@*****.**"
            }
        }

        self.article = {
            "article": {
                "title": "test article",
                "description": "This is test description",
                "body": "This is a test body",
                "tags": ["test", "tags"]
            }
        }

        self.comment = {
            "comment": {
                "body": "This is a test comment body."
            }
        }
Ejemplo n.º 5
0
 def test_user_can_update(self):
     """This method checks if a user can update an existing articles"""
     token = self.create_user()
     response = self.client.post(self.url,
                                 self.article,
                                 format='json',
                                 HTTP_AUTHORIZATION=token)
     slug = response.data['slug']
     url = API_Reverse('articles:article-details', {slug: 'slug'})
     r = self.client.put(url,
                         data={
                             "article": {
                                 "title": "Updated Title",
                                 "body": "Updated body"
                             }
                         },
                         format='json',
                         HTTP_AUTHORIZATION=token)
     self.assertIn("Updated Title", json.dumps(r.data))
     self.assertEqual(r.status_code, status.HTTP_200_OK)
Ejemplo n.º 6
0
 def single_article_details(self):
     slug = self.create_article()
     url = API_Reverse('articles:article-details', {slug: 'slug'})
     return url
Ejemplo n.º 7
0
 def create_comment(self):
     slug = self.create_article()
     post_url = API_Reverse('articles:comments', {slug: 'slug'})
     post_response = self.client.post(post_url, self.comment, format='json')
     id = post_response.data['id']
     return id, slug
Ejemplo n.º 8
0
 def update_comment(self, id, slug, new_comment):
     url = API_Reverse('articles:comment-details', {slug: 'slug', id: 'id'})
     response = self.client.put(url, data={'comment': {'body': new_comment}}, format='json')
     return response