def test_get_resource_content_utility_function_not_cached(self): """ Tests the :func:`pts.core.utils.http.get_resource_content` utility function when the resource is not cached in the given cache instance. """ mock_cache = mock.create_autospec(HttpCache) mock_cache.is_expired.return_value = True expected_content = b"Some content" mock_cache.get_content.return_value = expected_content url = 'http://some.url.com' content = get_resource_content(url, mock_cache) self.assertEqual(content, expected_content) # The function updated the cache mock_cache.update.assert_called_once_with(url)
def test_get_resource_content_utlity_function_cached(self): """ Tests the :func:`pts.core.utils.http.get_resource_content` utility function when the resource is cached in the given cache instance. """ mock_cache = mock.create_autospec(HttpCache) mock_cache.is_expired.return_value = False expected_content = b"Some content" mock_cache.get_content.return_value = expected_content url = 'http://some.url.com' content = get_resource_content(url, mock_cache) # The expected content is retrieved self.assertEqual(content, expected_content) # The function did not update the cache self.assertFalse(mock_cache.update.called)
def generate_accepted_news_content(self, package, version): """ Generates the content for a news item created when a package version is first created. :type package: :class:`SourcePackageName <pts.core.models.SourcePackageName>` :type version: :class:`string` """ package_version = package.source_package_versions.get(version=version) entry = package_version.repository_entries.all()[0] # Add dsc file content = get_resource_content(entry.dsc_file_url) if content: content = content.decode('utf-8') else: content = '' # Add changelog entries since last update... changelog_content = package_version.get_changelog_entry() if changelog_content: content = content + '\nChanges:\n' + changelog_content return content