Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
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")
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
    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")