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)
Beispiel #2
0
    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()), [])
Beispiel #3
0
    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])
Beispiel #4
0
def fill_db_books():
    for book in books:
        Book.create(**book)
Beispiel #5
0
 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)