def createBook(request): form = BookForm() context = {'form': form} if request.method == 'POST': form = BookForm(request.POST) if form.is_valid(): Book.create(request.POST['name'], request.POST['description'], request.POST['count'], request.POST['authors']) return redirect("/books") return render(request, 'book_form.html', context)
def test_create_positive_name_description_empty(self): """ Positive Test of the CustomUser.create method """ book = Book.create(name="testBook", description="") self.assertIsInstance(book, Book) self.assertEqual(book.name, "testBook") self.assertEqual(book.description, "") self.assertEqual(book.count, 10) self.assertListEqual(list(book.authors.all()), [])
def test_create_positive_name_description_count_a(self): """ Positive Test of the CustomUser.create method """ book = Book.create(name="testBook", description="testDescription", count=5, authors=[self.author1, self.author2]) self.assertIsInstance(book, Book) self.assertEqual(book.name, "testBook") self.assertEqual(book.description, "testDescription") self.assertEqual(book.count, 5) self.assertListEqual(list(book.authors.all()), [self.author1, self.author2])
def fill_db_books(): for book in books: Book.create(**book)
def test_create_negative_len_name(self): """ Positive Test of the CustomUser.create method TEST_DATE_END""" book = Book.create(name="1" * 128, description="12") self.assertIsInstance(book, Book) book = Book.create(name="1" * 129, description="12") self.assertIsNone(book)