"""
Unit tests for class Library.
"""


from library.bookmark import Bookmark
from library.book     import Book
from library.library  import Library


lib = Library()

book1_refs = {
    'Authors': ['OS guy', 'Some guy'],
    'Publisher': 'Forgot publisher',
    'Edition': 9,
    'Chapters': 18,
    'Pages': 900
}
book2_refs = {
    'Authors': 'Me',
    'Edition': 5,
    'Chapters': 7,
    'Pages': 900
}
book3_refs = {
    'Authors': ['Scott Chacon', 'Ben Straub'],
    'Publisher': 'Apress',
    'Edition': 2,
    'Chapters': 10
}

book1 = Book(title='Operating System Concepts',
             refs=book1_refs)
book2 = Book(title='Computer Organization and Design',
             refs=book2_refs)
book3 = Book(title='Pro Git',
             refs=book3_refs)

bookmark1_refs = {
    'Book Title': 'Operating System Concepts',
    'Edition': 9,
    'Chapter': 10,
    'Page': 485
}
bookmark2_refs = {
    'Book Title': 'Operating System Concepts',
    'Edition': 9,
    'Chapter': '11.3.1',
    'Page': 517
}
bookmark3_refs = {
    'Book Title': 'Pro Git',
    'Edition': 2,
    'Chapter': 3,
    'Page': 81
}

bookmark1 = Bookmark(title='File Systems',
                     category='Operating Systems',
                     refs=bookmark1_refs)
bookmark2 = Bookmark(title='Storage Structure',
                     category='Operating Systems',
                     refs=bookmark2_refs)
bookmark3 = Bookmark(title='Git Branching',
                     category='Git',
                     refs=bookmark3_refs)

lib.add_book(book1)
lib.add_book(book2)
lib.add_book(book3)
book1.add_bookmark(bookmark1)
book1.add_bookmark(bookmark2)
book3.add_bookmark(bookmark3)

class TestLibrary:
    def test_book(self):
        # test with ID
        assert(lib.book(book1.id()) == book1)
        assert(lib.book(book1.id()) != book2)
        assert(lib.book(book1.id()) != book3)
        assert(lib.book(book2.id()) != book1)
        assert(lib.book(book2.id()) == book2)
        assert(lib.book(book2.id()) != book3)
        assert(lib.book(book3.id()) != book1)
        assert(lib.book(book3.id()) != book2)
        assert(lib.book(book3.id()) == book3)

        # test with obj
        assert(lib.book(book1) == book1)
        assert(lib.book(book1) != book2)
        assert(lib.book(book1) != book3)
        assert(lib.book(book2) != book1)
        assert(lib.book(book2) == book2)
        assert(lib.book(book2) != book3)
        assert(lib.book(book3) != book1)
        assert(lib.book(book3) != book2)
        assert(lib.book(book3) == book3)

        # test with dict
        assert(lib.book(book1_refs) == book1)
        assert(lib.book(book1_refs) != book2)
        assert(lib.book(book1_refs) != book3)
        assert(lib.book(book2_refs) != book1)
        assert(lib.book(book2_refs) == book2)
        assert(lib.book(book2_refs) != book3)
        assert(lib.book(book3_refs) != book1)
        assert(lib.book(book3_refs) != book2)
        assert(lib.book(book3_refs) == book3)

        # test with str for title
        assert(lib.book(book1.title()) == book1)
        assert(lib.book(book1.title()) != book2)
        assert(lib.book(book1.title()) != book3)
        assert(lib.book(book2.title()) != book1)
        assert(lib.book(book2.title()) == book2)
        assert(lib.book(book2.title()) != book3)
        assert(lib.book(book3.title()) != book1)
        assert(lib.book(book3.title()) != book2)
        assert(lib.book(book3.title()) == book3)

    def test_book_with_bookmark(self):
        assert(lib.book_with_bookmark(bookmark1) == book1)
        assert(lib.book_with_bookmark(bookmark1) != book2)
        assert(lib.book_with_bookmark(bookmark1) != book3)
        assert(lib.book_with_bookmark(bookmark2) == book1)
        assert(lib.book_with_bookmark(bookmark2) != book2)
        assert(lib.book_with_bookmark(bookmark2) != book3)
        assert(lib.book_with_bookmark(bookmark3) != book1)
        assert(lib.book_with_bookmark(bookmark3) != book2)
        assert(lib.book_with_bookmark(bookmark3) == book3)

    def test_bookmarks_of_book(self):
        assert(lib.bookmarks_of_book(book1) == {bookmark1, bookmark2})
        assert(lib.bookmarks_of_book(book1) == {bookmark2, bookmark1})
        assert(lib.bookmarks_of_book(book1) != {bookmark1, bookmark3})
        assert(lib.bookmarks_of_book(book1) != {bookmark2, bookmark3})
        assert(lib.bookmarks_of_book(book2) == set())
        assert(lib.bookmarks_of_book(book2) != {bookmark1, bookmark2})
        assert(lib.bookmarks_of_book(book2) != {bookmark1, bookmark3})
        assert(lib.bookmarks_of_book(book2) != {bookmark2, bookmark3})
        assert(lib.bookmarks_of_book(book3) == {bookmark3})
        assert(lib.bookmarks_of_book(book3) != {bookmark1})
        assert(lib.bookmarks_of_book(book3) != {bookmark2})
        assert(lib.bookmarks_of_book(book3) != {bookmark1, bookmark3})
        assert(lib.bookmarks_of_book(book3) != {bookmark2, bookmark3})

    def test_add_category(self):
        pass

    def test_rm_category(self):
        pass

    def test_parent_category_of(self):
        pass
