Skip to content

Instantly share code, notes, and snippets.

@Teatoller
Last active December 19, 2018 11:30
Show Gist options
  • Save Teatoller/256ef2b1cdf37a9e4d90d24200cbfbc4 to your computer and use it in GitHub Desktop.
Save Teatoller/256ef2b1cdf37a9e4d90d24200cbfbc4 to your computer and use it in GitHub Desktop.
Tests to validate field inputs such as
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
@waracci
Copy link

waracci commented Dec 19, 2018

In your setUp method, get rid of the pass and also ensure your posts variable is a class variable.

self.posts = {}

@sharkdevs
Copy link

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.

@johnwayodi
Copy link

johnwayodi commented Dec 19, 2018

from authorsHaven.models import Post

The Post model seems not to have been used, consider removing that import statement

@Paulvitalis200
Copy link

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