Last active
December 19, 2018 11:30
-
-
Save Teatoller/256ef2b1cdf37a9e4d90d24200cbfbc4 to your computer and use it in GitHub Desktop.
Tests to validate field inputs such as
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.test import APIClient | |
from authorsHaven.models import Post | |
class PostTest(TestCase): | |
""" This is to test that the Post created has author, title, text in field, create and publish dates """ | |
def setUp(self): | |
# Setup run before every test method. | |
pass | |
posts= { | |
'author.self'='Andrew Hicks', | |
'title.self':'The Dry Lands', | |
'text.self'='', | |
'created_date.self' = '14/12/2018', | |
'published_date.self'= '18/12/2018', | |
} | |
def test_author_field(self): | |
self.assertEqual(author, 'Andrew Hicks') | |
def test_tile_field(self): | |
self.assertEqual(title, 'The Dry Lands') | |
def test_text_field(self): | |
self.assertNotEqual(text, '') | |
def test_created_date_field(self): | |
self.assertEqual(created_date, '14/12/2018') | |
def test_published_date_field(self): | |
self.assertEqual(published_date, '18/12/2018') | |
def tearDown(self): | |
# Clean up run after every test method. | |
pass |
add a blank line between the libraries' imports and local application imports to help easily demarcate the different imports.
Ensure that the pep8 standards are followed as you are writing the code.
from authorsHaven.models import Post
The Post model seems not to have been used, consider removing that import statement
Good work. However, check your setUp
and tearDown
methods and ensure they adhere to PEP 8 standards by de-indenting the contents within it by a single tab or four spaces.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your
setUp
method, get rid of thepass
and also ensure yourposts
variable is a class variable.