Esempio n. 1
0
 def test_add_new_chapter_one_parameter_none(self):
     chapter = Chapter()
     chapter.chapter_name = None
     chapter_test = self.chapter_repository.add_new_chapter(chapter, 1)
     self.assertEqual(chapter_test, None)
     result = self.chapter_repository.get_one_by_id(chapter.id)
     self.assertEqual(result, None)
Esempio n. 2
0
 def get_one_by_id(self, id):
     if id == None or id < 0:
         return None
     self.cursor.execute("SELECT * from projekt.chapter where id=%d ;" % id)
     records_chapter = self.cursor.fetchone()
     if records_chapter == None:
         return None
     now_chapter = Chapter()
     now_chapter.id = records_chapter[0]
     now_chapter.chapter_name = records_chapter[1]
     now_chapter.edited_date = records_chapter[2]
     return now_chapter
Esempio n. 3
0
 def get_all(self):
     self.cursor.execute("SELECT * from projekt.chapter ;")
     records_chapter = self.cursor.fetchall()
     if records_chapter != None:
         chapter_list = []
         for chapter in records_chapter:
             now_chapter = Chapter()
             now_chapter.id = chapter[0]
             now_chapter.chapter_name = chapter[1]
             now_chapter.edited_date = chapter[2]
             chapter_list.append(now_chapter)
         return chapter_list
     else:
         return None
Esempio n. 4
0
    def test_book_delete_valid(self):
        book = Book()
        book.id = 6
        book.user_id = 6
        book.name_of_the_book = 'Mr. Fantastic'
        book.author = 'Reed Richards'
        chapter_1 = Chapter()
        chapter_1.chapter_name = 'First chapter'
        chapter_2 = Chapter()
        chapter_2.chapter_name = 'Second chapter'
        book.chapters.append(chapter_1)
        book.chapters.append(chapter_2)
        self.book_repository.add_new_book(book)

        self.book_repository.book_delete(6)
        books = self.book_repository.get_one_by_id(6)
        self.assertEqual(books, None)
Esempio n. 5
0
 def test_add_new_book_valid(self):
     book = Book()
     book.id = 4
     book.user_id = 4
     book.name_of_the_book = 'Python for beginners'
     book.author = 'Jaroslav Sochan'
     chapter_1 = Chapter()
     chapter_1.chapter_name = 'First chapter'
     chapter_2 = Chapter()
     chapter_2.chapter_name = 'Second chapter'
     book.chapters.append(chapter_1)
     book.chapters.append(chapter_2)
     result_book = self.book_repository.add_new_book(book)
     result = self.book_repository.get_one_by_id(result_book.id)
     self.assertNotEqual(result, None)
     self.assertEqual(result.id, book.id)
     self.assertEqual(result.user_id, book.user_id)
     self.assertEqual(result.name_of_the_book, book.name_of_the_book)
     self.assertEqual(len(result.chapters), len(book.chapters))
Esempio n. 6
0
 def test_add_new_book_one_chapter_parameter_none(self):
     book = Book()
     book.id = 5
     book.user_id = 5
     book.name_of_the_book = 'Python for adults'
     book.author = 'ing. Jaroslav Sochan'
     chapter_1 = Chapter()
     chapter_1.chapter_name = 'First chapter'
     chapter_2 = Chapter()
     chapter_2.chapter_name = None
     book.chapters.append(chapter_1)
     book.chapters.append(chapter_2)
     book_test = self.book_repository.add_new_book(book)
     self.assertNotEqual(book_test, None)
     result = self.book_repository.get_one_by_id(book_test.id)
     self.assertNotEqual(result, None)
     self.assertEqual(result.id, book.id)
     self.assertEqual(result.user_id, book.user_id)
     self.assertEqual(result.name_of_the_book, book.name_of_the_book)
     self.assertEqual(len(result.chapters), 1)
Esempio n. 7
0
 def test_chapter_delete_valid(self):
     chapter = Chapter()
     chapter.chapter_name = 'Second chapter'
     self.chapter_repository.add_new_chapter(chapter, 1)
     self.chapter_repository.chapter_delete(3)
Esempio n. 8
0
 def test_add_new_chapter_valid(self):
     chapter = Chapter()
     chapter.chapter_name = 'First chapter'
     self.chapter_repository.add_new_chapter(chapter, 1)
     result = self.chapter_repository.get_one_by_id(2)
     self.assertEqual(result.chapter_name, 'First chapter')
Esempio n. 9
0
else:
    print('Here are your books')
for i in books:
    print(i.name_of_the_book + ' by author: ' + i.author + ' at a position: ' +
          str(i.id))

for i in range(4):
    print('Do you want to add another book to you? ')
    press = input('Please type yes or no: ')
    if press == 'yes':
        book = Book()
        book.name_of_the_book = input('Type name your new book here: ')
        book.author = input('Type the author here: ')
        chapter_count = input('Type number of chapters of this book: ')
        for i in range(1, int(chapter_count) + 1):
            chapter = Chapter()
            chapter.chapter_name = input('Type chapter number' + str(i) +
                                         ' here:')
            book.chapters.append(chapter)
        book.user_id = loged_user.id
        book_repository.add_new_book(book)
        break
    if press == 'no':
        break
    else:
        print('You press wrong command and you have only ' + ' ' +
              str(int(3 - i)) + ' ' + ' attempts')

for i in range(1, 4):
    print('Do you want to delete some of your books?')
    press = input('Please type yes or no: ')