示例#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")
示例#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")
示例#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
示例#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")
示例#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")
示例#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")
示例#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")