예제 #1
0
    def test_insert_with_invalid_author(self):
        book = 'Some book'
        authors = ['']

        response, err = inventory.insert(book=book, authors=authors)

        assert response is False
        assert err == 'Author name cannot be empty!'
        assert book.lower() not in inventory._BOOKS_TO_AUTHOR_MAP
        assert authors[0].lower() not in inventory._AUTHOR_TO_BOOKS_MAP
예제 #2
0
    def test_insert_with_invalid_author(self):
        book = "Some book"
        authors = [""]

        response, err = inventory.insert(book=book, authors=authors)

        assert response is False
        assert err == "Author name cannot be empty!"
        assert book.lower() not in inventory._BOOKS_TO_AUTHOR_MAP
        assert authors[0].lower() not in inventory._AUTHOR_TO_BOOKS_MAP
예제 #3
0
    def test_insert_with_valid_input(self):
        book = "Some book"
        authors = ["Some Author"]

        response, err = inventory.insert(book=book, authors=authors)

        assert response
        assert err is None
        assert inventory._BOOKS_TO_AUTHOR_MAP[book.lower()] == [a.lower() for a in authors]
        assert inventory._AUTHOR_TO_BOOKS_MAP[authors[0].lower()] == [book.lower()]
예제 #4
0
    def test_get_books_for_author_with_empty_list(self):
        book = 'Some book'
        authors = ['Some Author']

        response, err = inventory.insert(book=book, authors=authors)

        assert response

        books = inventory.get_books_for_author(author='Random Author')

        assert len(books) == 0
예제 #5
0
    def test_get_books_for_author_with_empty_list(self):
        book = "Some book"
        authors = ["Some Author"]

        response, err = inventory.insert(book=book, authors=authors)

        assert response

        books = inventory.get_books_for_author(author="Random Author")

        assert len(books) == 0
예제 #6
0
    def test_get_books_for_author_with_books(self):
        book = 'Some book'
        authors = ['Some Author']

        response, err = inventory.insert(book=book, authors=authors)

        assert response

        books = inventory.get_books_for_author(author=authors[0])

        assert len(books) > 0
        assert books[0] == book.lower().strip()
예제 #7
0
    def test_insert_with_valid_input(self):
        book = 'Some book'
        authors = ['Some Author']

        response, err = inventory.insert(book=book, authors=authors)

        assert response
        assert err is None
        assert inventory._BOOKS_TO_AUTHOR_MAP[book.lower()]\
            == [a.lower() for a in authors]
        assert inventory._AUTHOR_TO_BOOKS_MAP[authors[0].lower()]\
            == [book.lower()]
예제 #8
0
    def test_get_books_for_author_with_books(self):
        book = "Some book"
        authors = ["Some Author"]

        response, err = inventory.insert(book=book, authors=authors)

        assert response

        books = inventory.get_books_for_author(author=authors[0])

        assert len(books) > 0
        assert books[0] == book.lower().strip()
예제 #9
0
    def test_compare_without_results(self):
        books = ['Some book', 'Another Book', 'The Book']
        authors = ['Some Author', 'Another Author', 'The Author']

        my_list = ['Some book', 'Another Author', 'Author', 'The Book']

        input_list = ['Another Book', 'The Book', 'Some Book']

        for book, author in zip(books, authors):
            response, err = inventory.insert(book=book, authors=[author])
            assert response

        result = inventory.compare(my_list=my_list, input_list=input_list)

        assert len(result) == 0
예제 #10
0
    def test_compare_without_results(self):
        books = ["Some book", "Another Book", "The Book"]
        authors = ["Some Author", "Another Author", "The Author"]

        my_list = ["Some book", "Another Author", "Author", "The Book"]

        input_list = ["Another Book", "The Book", "Some Book"]

        for book, author in zip(books, authors):
            response, err = inventory.insert(book=book, authors=[author])
            assert response

        result = inventory.compare(my_list=my_list, input_list=input_list)

        assert len(result) == 0
예제 #11
0
파일: manager.py 프로젝트: vedarthk/misc
import sys
import json

import inventory

if __name__ == '__main__':

    try:
        with open('data.json', 'r') as f:
            input_data = json.loads(f.read())
    except IOError as e:
        sys.stdout.write('[error] data.json file is missing,'
                         ' rename the data.json.example to data.json\n')
        sys.exit(1)

    for book, authors in input_data['inventory'].items():
        inventory.insert(book=book, authors=authors)

    sys.stdout.write('Missing books:\n')
    for i, b in enumerate(
            inventory.compare(my_list=input_data['my_list'],
                              input_list=input_data['input_list'])):
        sys.stdout.write('{}. {}\n'.format(i + 1, b))
예제 #12
0
파일: manager.py 프로젝트: vedarthk/misc
import sys
import json

import inventory

if __name__ == '__main__':

    try:
        with open('data.json', 'r') as f:
            input_data = json.loads(f.read())
    except IOError as e:
        sys.stdout.write('[error] data.json file is missing,'
                         ' rename the data.json.example to data.json\n')
        sys.exit(1)

    for book, authors in input_data['inventory'].items():
        inventory.insert(book=book, authors=authors)

    sys.stdout.write('Missing books:\n')
    for i, b in enumerate(inventory.compare(
            my_list=input_data['my_list'],
            input_list=input_data['input_list'])):
        sys.stdout.write('{}. {}\n'.format(i + 1, b))