Last active
September 19, 2018 12:50
-
-
Save bevkololi/d98fc2e3eead7e5e64151bad4243bfef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase | |
from rest_framework import status | |
from rest_framework import APIClient | |
class ArticleTestCase(TestCase): | |
def setUp(self): | |
"""Define test variable""" | |
self.client = APIClient() | |
self.article_data = {'title': 'Hello world', 'content':'hello world, this is a group activity that involves tdd'} | |
self.response = self.client.post("api/v1/articles", | |
self.article_data, | |
format="json") | |
def test_user_can_create_article(self) | |
"""Test user can create article""" | |
self.assertEqual(self.response.status_code, status.HTTP_201_CREATED) | |
def test_user_can_edit_article(self): | |
"""Test user can edit the article""" | |
new_data={"title":"hello", "content":"Edited aricle"} | |
self.response = self.client.post("api/v1/articles/", | |
self.article_data, | |
format="json") | |
self.response = self.client.put("api/v1/articles/1", | |
self.new_data, | |
format="json") | |
self.assertEqual(self.response.status_code, status.HTTP_200_OK) | |
Nice work on the two test cases. You chose a unique feature to test on.
I would suggest you implement more assertions based on the response data.
For example
self.assertIn(b'Article created successfully', response.data)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
follow the pep8 standard to ensure the lines are not more than 70 characters.