""" This module cantains tests for the comic data model """ import unittest from . import TestBase from kontor.library.models import Author, Publisher, Book class TestComicsModel(TestBase): """This TestCase contains tests for comic data model.""" def setUp(self): publisher = Publisher() publisher.name = "Publisher1" publisher.save() author = Author() author.name = "Autor1" author.save() book = Book() book.title = "Title1" book.save() def tearDown(self): for book in Book.objects.all(): book.delete() for author in Author.objects.all(): author.delete() for publisher in Publisher.objects.all(): publisher.delete() def test_comic_model(self): book_list = Book.objects.all() self.assertEqual(book_list.count(), 1) def test_publisher_model(self): self.assertEqual(Publisher.objects.all().count(), 1) def test_artist_model(self): self.assertEqual(Author.objects.all().count(), 1) def test_assign_publisher(self): book = Book.objects.first() publisher = Publisher.objects.first() book.publisher = publisher book.save() self.assertEqual(publisher.name, book.publisher.name) if __name__ == '__main__': unittest.main()