def test_recover_movies_from_cache(self): mockApiRest = None cache = MongoDBMoviesCache(self.mongo_client) self.setMovieInCache({"Title": "Sunshine", "Year": "2007"}) restCache = RestCache(mockApiRest, cache) restCache.search_movie("Sunshine")
def test_store_movies_in_cache(self): mockApiRest = ApiRest() cache = MongoDBMoviesCache(self.mongo_client) restCache = RestCache(mockApiRest, cache) restCache.search_movie("Sunshine") self.assertMovieInCache("Sunshine")
def test_recovering_movies_from_cache(self): mockApiRest = MagicMock() mockCache = MagicMock() mockCache.search = MagicMock(return_value={'Title':"Sunshine", 'Year':"2007"}) restCache = RestCache(mockApiRest, mockCache) restCache.search_movie("Sunshine") assert mockApiRest.search.call_count == 0
def test_recovering_movies_from_api(self): mockApiRest = mock() mockCache = mock() when(mockCache).search("Sunshine").thenReturn(None) restCache = RestCache(mockApiRest, mockCache) restCache.search_movie("Sunshine") verify(mockApiRest, 1).search("Sunshine")
def test_recovering_movies_from_api(self): mockApiRest = MagicMock() mockCache = MagicMock() mockCache.search = MagicMock(return_value=None) restCache = RestCache(mockApiRest, mockCache) restCache.search_movie("Sunshine") mockApiRest.search.assert_called_once_with("Sunshine")
def test_recovering_movies_from_cache(self): mockApiRest = mock() mockCache = mock() when(mockCache).search("Sunshine").thenReturn({'Title':"Sunshine", 'Year':"2007"}) restCache = RestCache(mockApiRest, mockCache) restCache.search_movie("Sunshine") verify(mockCache, 1).search("Sunshine") verify(mockApiRest, 0).search("Sunshine")
def test_intercepting_url(self): httpretty.register_uri(httpretty.GET, "http://www.omdbapi.com/", body='{"Title": "Demo movie", "Date": "2014"}', content_type="application/json") apiRest = ApiRest() mongo_client = mongomock.MongoClient() cache = MongoDBMoviesCache(mongo_client) capturer = JsonCapturer() restCache = RestCache(apiRest, cache) restCache.show = capturer.capture restCache.search_movie("aliens") self.assertEqual(capturer.doc['Title'], "Demo movie")