Exemplo n.º 1
0
 def test_adding_game_by_ID(self):
     """Test that the TheGamesDB API for game lookups hasn't changed"""
     game = Item("game", "18817", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         game.find(False)
     game.set_state("have")
     assert(Item.select().where(Item.item_ID == "18817").first())
Exemplo n.º 2
0
 def test_adding_movie_by_ID(self):
     """Test that the IMDB API for ID queries hasn't changed"""
     movie = Item("movie", "tt0068646", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt0068646").first().state == "have")
Exemplo n.º 3
0
 def test_adding_book_by_ID(self):
     """Test that the Google Books API for volume lookups hasn't changed"""
     book = Item("book", "btpIkZ6X6egC", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == "btpIkZ6X6egC").first())
Exemplo n.º 4
0
 def test_have_game(self):
     """Test that the TheGamesDB API for game searches hasn't changed"""
     game = Item("game", "FIFA 14")
     with mock.patch("__builtin__.raw_input", return_value="16"):
         game.find(False)
     game.set_state("have")
     assert(Item.select().where(Item.item_ID == "18817").first())
Exemplo n.º 5
0
 def test_have_book(self):
     """Test that the Google Books API for searches hasn't changed"""
     # search this way because results are otherwise unstable
     book = Item("book", "editions:pksPd7dfAAMC")
     with mock.patch("__builtin__.raw_input", return_value="2"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == "btpIkZ6X6egC").first())
Exemplo n.º 6
0
 def test_removing_item_with_unicode_title(self):
     """Test removing an item with unicode in the title from the database"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps[u"WALL·E"]),
                   status=200, content_type="application/json")
     movie = Item("movie", u"WALL·E")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == u"tt0910970").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("movie", "tt0910970", False)
     assert(not Item.select().where(Item.item_ID == u"tt0910970").first())
Exemplo n.º 7
0
 def test_removing_movie(self):
     """Test that a movie is properly removed from the database"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["The Godfather"]),
                   status=200, content_type="application/json")
     movie = Item("movie", "The Godfather")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == u"tt0068646").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("movie", "tt0068646", False)
     assert(not Item.select().where(Item.item_ID == u"tt0068646").first())
Exemplo n.º 8
0
 def test_removing_tv_show(self):
     """Test that a TV show is properly removed from the database"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["The Sopranos"]),
                   status=200, content_type="application/json")
     show = Item("TV show", "The Sopranos")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         show.find(False)
     show.set_state("have")
     assert(Item.select().where(Item.item_ID == u"tt0141842").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("TV show", "tt0141842", False)
     assert(not Item.select().where(Item.item_ID == u"tt0141842").first())
Exemplo n.º 9
0
 def test_removing_book(self):
     """Test that a book is properly removed from the database"""
     responses.add(responses.GET, "https://www.googleapis.com/books/v1/volumes",
                   body=json.dumps(resps["A Game of Thrones"]),
                   status=200, content_type="application/json")
     book = Item("book", "A Game of Thrones")
     with mock.patch("__builtin__.raw_input", return_value="3"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == u"btpIkZ6X6egC").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("book", "btpIkZ6X6egC", False)
     assert(not Item.select().where(Item.item_ID == u"btpIkZ6X6egC").first())
Exemplo n.º 10
0
 def test_removing_game(self):
     """Test that a game is properly removed from the database"""
     responses.add(responses.GET, "http://thegamesdb.net/api/GetGamesList.php",
                   body=base64.b64decode(resps["FIFA 14"]["data"]),
                   status=200, content_type="text/xml")
     game = Item("game", "FIFA 14")
     with mock.patch("__builtin__.raw_input", return_value="16"):
         game.find(False)
     game.set_state("have")
     assert(Item.select().where(Item.item_ID == "18817").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("game", "18817", False)
     assert(not Item.select().where(Item.item_ID == "18817").first())
Exemplo n.º 11
0
 def test_removing_item_of_wrong_type(self):
     """Test specifying the wrong type when removing doesn't remove the item"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["The Godfather"]),
                   status=200, content_type="application/json")
     movie = Item("movie", "The Godfather")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == u"tt0068646").first())
     with mock.patch("__builtin__.raw_input", return_value="y"):
         remove_item("book", "tt0068646", False)
     assert(Item.select().where(Item.item_ID == u"tt0068646").first())
Exemplo n.º 12
0
 def test_want_movie(self):
     """Test adding a movie to the wanted-list"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["The Godfather"]),
                   status=200, content_type="application/json")
     movie = Item("movie", "The Godfather")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("want")
     assert(Item.select().where(Item.item_ID == "tt0068646").first().state == "want")
Exemplo n.º 13
0
 def test_adding_game_by_ID(self):
     """Test adding a game to the library using a TheGamesDB ID"""
     responses.add(responses.GET, "http://thegamesdb.net/api/GetGame.php",
                   body=base64.b64decode(resps["18817"]["data"]),
                   status=200, content_type="text/xml")
     game = Item("game", "18817", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         game.find(False)
     game.set_state("have")
     assert(Item.select().where(Item.item_ID == "18817").first())
Exemplo n.º 14
0
 def test_adding_TV_show_by_ID(self):
     """Test adding a TV Show to the library using an IMDB ID"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["tt0141842"]),
                   status=200, content_type="application/json")
     show = Item("TV show", "tt0141842", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         show.find(False)
     show.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt0141842").first().state == "have")
Exemplo n.º 15
0
 def test_adding_movie_by_ID(self):
     """Test adding a movie to the library using an IMDB ID"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["tt0068646"]),
                   status=200, content_type="application/json")
     movie = Item("movie", "tt0068646", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt0068646").first().state == "have")
Exemplo n.º 16
0
 def test_have_movie_with_unicode_in_title(self):
     """Test adding a movie that has unicode in it's title"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps[u"WALL·E"]),
                   status=200, content_type="application/json")
     movie = Item("movie", u"WALL·E")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         movie.find(False)
     movie.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt0910970").first())
Exemplo n.º 17
0
 def test_adding_book_by_ID(self):
     """Test adding a book to the library using a Google Books volume ID"""
     responses.add(responses.GET, "https://www.googleapis.com/books/v1/volumes/btpIkZ6X6egC",
                   body=json.dumps(resps["btpIkZ6X6egC"]),
                   status=200, content_type="application/json")
     book = Item("book", "btpIkZ6X6egC", True)
     with mock.patch("__builtin__.raw_input", return_value="y"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == "btpIkZ6X6egC").first())
Exemplo n.º 18
0
 def test_listing_books_with_unicode_in_title(self):
     """Test listing books with unicode in the title"""
     responses.add(responses.GET, "https://www.googleapis.com/books/v1/volumes",
                   body=json.dumps(resps[u"Toda mulher é uma Deusa"]),
                   status=200, content_type="application/json")
     book = Item("book", u"Toda mulher é uma Deusa")
     with mock.patch("__builtin__.raw_input", return_value="1"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == "NgvTH74c8B0C").first())
     print_list("book", None, None)
Exemplo n.º 19
0
 def test_listing_books(self):
     """Test listing books"""
     responses.add(responses.GET, "https://www.googleapis.com/books/v1/volumes",
                   body=json.dumps(resps["A Game of Thrones"]),
                   status=200, content_type="application/json")
     book = Item("book", "A Item of Thrones")
     with mock.patch("__builtin__.raw_input", return_value="3"):
         book.find(False)
     book.set_state("have")
     assert(Item.select().where(Item.item_ID == "btpIkZ6X6egC").first())
     print_list("book", None, None)
Exemplo n.º 20
0
 def test_listing_games(self):
     """Test listing games"""
     responses.add(responses.GET, "http://thegamesdb.net/api/GetGamesList.php",
                   body=base64.b64decode(resps["FIFA 14"]["data"]),
                   status=200, content_type="text/xml")
     game = Item("game", "FIFA 14")
     with mock.patch("__builtin__.raw_input", return_value="16"):
         game.find(False)
     game.set_state("have")
     assert(Item.select().where(Item.item_ID == "18817").first())
     print_list("game", None, None)
Exemplo n.º 21
0
 def test_listing_tv_with_unicode_in_title(self):
     """Test listing TV shows with unicode in the title"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps[u"Isler Güçler"]),
                   status=200, content_type="application/json")
     show = Item("TV show", u"Isler Güçler")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         show.find(False)
     show.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt2311418").first())
     print_list("TV show", None, None)
Exemplo n.º 22
0
 def test_listing_tv(self):
     """Test listing TV shows"""
     responses.add(responses.GET, "http://omdbapi.com/",
                   body=json.dumps(resps["The Sopranos"]),
                   status=200, content_type="application/json")
     show = Item("TV show", "The Sopranos")
     with mock.patch("__builtin__.raw_input", return_value="y"):
         show.find(False)
     show.set_state("have")
     assert(Item.select().where(Item.item_ID == "tt0141842").first())
     print_list("TV show", None, None)
Exemplo n.º 23
0
 def test_removing_non_existent_item(self):
     """Test removing an item that doesn't exist from the database"""
     assert(not Item.select().where(Item.item_ID == u"tt0071562").first())
     remove_item("movie", "tt0071562", False)
Exemplo n.º 24
0
    def setUp(self):
        db = SqliteDatabase(":memory:")

        Item._meta.database = db
        Item.create_table()
Exemplo n.º 25
0
    def test_have_existing_movie(self):
        """Test adding a movie that's already in the library"""
        responses.add(responses.GET, "http://omdbapi.com/",
                      body=json.dumps(resps["The Godfather"]),
                      status=200, content_type="application/json")
        movie = Item("movie", "The Godfather")
        with mock.patch("__builtin__.raw_input", return_value="y"):
            movie.find(False)
        movie.set_state("have")
        assert(Item.select().where(Item.item_ID == "tt0068646").count() == 1)

        movie = Item("movie", "The Godfather")
        with mock.patch("__builtin__.raw_input", return_value="y"):
            movie.find(False)
        movie.set_state("have")
        assert(Item.select().where(Item.item_ID == "tt0068646").count() == 1)