Example #1
0
    def test_get_resource_stale_calls_task(self, mock_cache, mock_task):
        resource = Resource(self.resource_url)
        resource.created = resource.created - (60*60*24*365*10)

        mock_cache.get_or_prime = mock_cache
        mock_cache.return_value = (resource, False)
        mock_task.apply_async = mock_task

        self.assertTrue(resource.is_stale)
        resource = self.provider.get_resource(self.resource_url)
        self.assertFalse(resource.is_stale)
        self.assertTrue(mock_task.called)
Example #2
0
    def test_get_resource_cached_is_stale(self, mock_cache):
        # Update django settings
        setattr(settings, 'MONOCLE_CACHE_INTERNAL_PROVIDERS', True)

        resource = Resource(self.resource_url)
        resource.created = resource.created - (60*60*24*365*10)

        mock_cache.get_or_prime = mock_cache
        mock_cache.return_value = (resource, False)
        self.provider._build_resource = Mock(return_value=resource)

        self.assertTrue(resource.is_stale)
        resource = self.provider.get_resource(self.resource_url)
        self.assertFalse(resource.is_stale)
        self.assertTrue(self.provider._build_resource.called)