Beispiel #1
0
 def test_add_book_method_books_already_in_books_by_authors(self):
     self.library = Library("Alex")
     self.library.add_book("King", "It")
     self.library.add_book("King", "It")
     self.library.add_book("Jones", "It")
     self.assertEqual(self.library.books_by_authors["King"], ["It"])
     self.assertEqual(self.library.books_by_authors["Jones"], ["It"])
Beispiel #2
0
 def test_method_rent_book_happy_case(self):
     self.library = Library("Alex")
     self.library.add_reader("Miro")
     self.library.add_book("King", "It")
     # book_index = self.library.books_by_authors["King"].index("It")
     self.library.rent_book("Miro", "King", "It")
     self.assertEqual(self.library.readers, {"Miro": [{"King": "It"}]})
     self.assertEqual(self.library.books_by_authors, {"King": []})
Beispiel #3
0
 def test_change_username_method_with_user_id_not_included_in_library_records_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(13, 'George')
     self.assertEqual(result, 'There is no user with id = 13!')
Beispiel #4
0
 def test_add_user_already_registered_in_the_library_should_return_message(
         self):
     user = User(12, 'Valentina')
     library = Library()
     library.add_user(user)
     result = library.add_user(user)
     self.assertEqual(
         result, 'User with id = 12 already registered in the library!')
Beispiel #5
0
 def test_remove_user_method_with_user_not_registered_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.remove_user(p)
     self.assertEqual(result, 'We could not find such user to remove!')
Beispiel #6
0
 def test_remove_user_method_with_valid_data_should_update_library_records_properly(
         self):
     user = User(12, 'Valentina')
     library = Library()
     library.add_user(user)
     library.add_user(User(13, 'Peter'))
     library.remove_user(user)
     self.assertEqual(library.user_records[0].__str__(), '13, Peter, []')
Beispiel #7
0
 def test_change_username_method_with_valid_data_should_return_message_and_update_library_records(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(12, 'Violeta')
     self.assertEqual(
         result, 'Username successfully changed to: Violeta for userid: 12')
     self.assertEqual(library.user_records[0].__str__(), '12, Violeta, []')
Beispiel #8
0
 def test_change_username_method_with_user_id_included_in_library_records_but_provided_new_username_is_the_same_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(12, 'Valentina')
     self.assertEqual(
         result,
         'Please check again the provided username - it should be different than the username used so far!'
     )
Beispiel #9
0
 def test_method_add_reader_username_already_registered(self):
     self.library = Library("Alex")
     self.library.add_reader("Miro")
     self.assertEqual(self.library.add_reader("Miro"),
                      "Miro is already registered in the Alex library.")
Beispiel #10
0
 def test_method_add_reader_happy_case(self):
     self.library = Library("Alex")
     self.library.add_reader("Miro")
     self.assertEqual(self.library.readers, {"Miro": []})
Beispiel #11
0
 def setUp(self):
     self.lib = Library("Test")
Beispiel #12
0
 def test_method_rent_book_author_not_in_books_by_author(self):
     self.library = Library("Alex")
     self.library.add_reader("Miro")
     self.assertEqual(self.library.rent_book("Miro", "King", "It"),
                      "Alex Library does not have any King's books.")
Beispiel #13
0
 def setUp(self):
     self.user = User(12, 'Valentina')
     self.library = Library()
Beispiel #14
0
 def test_method_rent_book_reader_not_in_readers(self):
     self.library = Library("Alex")
     self.assertEqual(self.library.rent_book("Miro", "King", "It"),
                      "Miro is not registered in the Alex Library.")
Beispiel #15
0
    def test__init__name_empty_string(self):
        with self.assertRaises(ValueError) as err:
            self.library = Library("")

        msg = "Name cannot be empty string!"
        self.assertEqual(str(err.exception), msg)
Beispiel #16
0
 def test__init__(self):
     self.library = Library("Alex")
     self.assertEqual(self.library.name, "Alex")
     self.assertEqual(self.library.books_by_authors, {})
     self.assertEqual(self.library.readers, {})
Beispiel #17
0
 def test_method_add_book_happy_case(self):
     self.library = Library("Alex")
     self.library.add_book("King", "It")
     self.assertEqual(self.library.books_by_authors["King"], ["It"])
Beispiel #18
0
 def test_method_rent_book_book_title_not_in_books_by_author(self):
     self.library = Library("Alex")
     self.library.add_reader("Miro")
     self.library.add_book("King", "It")
     self.assertEqual(self.library.rent_book("Miro", "King", "Shining"),
                      """Alex Library does not have King's "Shining".""")
Beispiel #19
0
 def test_method_add_book_author_already_in_books_by_author(self):
     self.library = Library("Alex")
     self.library.add_book("King", "It")
     self.library.add_book("King", "Shining")
     self.assertEqual(self.library.books_by_authors["King"],
                      ["It", "Shining"])
from project.library import Library
from project.user import User

user = User(12, 'Peter')
library = Library()
library.add_user(user)
print(library.add_user(user))
library.remove_user(user)
print(library.remove_user(user))
library.add_user(user)
print(library.change_username(2, 'Igor'))
print(library.change_username(12, 'Peter'))
print(library.change_username(12, 'George'))

[
    print(
        f'{user_record.user_id}, {user_record.username}, {user_record.books}')
    for user_record in library.user_records
]
library.books_available.update({
    'J.K.Rowling': [
        'The Chamber of Secrets', 'The Prisoner of Azkaban',
        'The Goblet of Fire', 'The Order of the Phoenix',
        'The Half-Blood Prince', 'The Deathly Hallows'
    ]
})

user.get_book('J.K.Rowling', 'The Deathly Hallows', 17, library)
print(library.books_available)
print(library.rented_books)
print(user.books)
Beispiel #21
0
 def setUp(self) -> None:
     self.library = Library('AI')