Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created April 26, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/6ac3b4e59b15dee199e2db137f3112b9 to your computer and use it in GitHub Desktop.
Save ivancorrales/6ac3b4e59b15dee199e2db137f3112b9 to your computer and use it in GitHub Desktop.
from database.book import BookDB,Book
class TestBookDatabase:
def setup(self):
self.bookDatabaseClient = BookDB()
def test_default_database_length(self):
assert self.bookDatabaseClient.books.__len__() is 2
def test_all(self):
assert self.bookDatabaseClient.all().__len__() is 2
self.bookDatabaseClient.books.clear()
assert self.bookDatabaseClient.all().__len__() is 0
def test_insert(self):
assert self.bookDatabaseClient.books.__len__() is 2
book = Book('La Colmena','Camilo José Cela')
self.bookDatabaseClient.insert(book)
assert self.bookDatabaseClient.books.__len__() is 3
assert book.id == 3
def test_one(self):
book = self.bookDatabaseClient.one(1)
assert book is not None
assert book.id is 1
assert book.author == 'Miguel de Cervantes'
assert book.title == 'Don Quijote de la Mancha'
new_book = Book('La Colmena', 'Camilo José Cela')
self.bookDatabaseClient.insert(new_book)
book = self.bookDatabaseClient.one(new_book.id)
assert new_book.id is book.id
assert new_book.title == book.title
assert new_book.author == book.author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment