Ejemplo n.º 1
0
 def test_community_info(self, mock_fetch):
     """Verify that get_community_info returns data from the cache"""
     config = OrgConfig({}, "test")
     config._community_info_cache = {"Kōkua": {"name": "Kōkua"}}
     info = config.get_community_info("Kōkua")
     self.assertEqual(info["name"], "Kōkua")
     mock_fetch.assert_not_called()
Ejemplo n.º 2
0
    def test_community_info_auto_refresh_cache(self, mock_fetch):
        """Verify that the internal cache is automatically refreshed

        The cache should be refreshed automatically if the requested community
        is not in the cache.
        """
        mock_fetch.return_value = {"Kōkua": {"name": "Kōkua"}}

        config = OrgConfig({}, "test")
        config._community_info_cache = {}
        info = config.get_community_info("Kōkua")
        mock_fetch.assert_called()
        self.assertEqual(info["name"], "Kōkua")
Ejemplo n.º 3
0
    def test_community_info_force_refresh(self, mock_fetch):
        """Verify that the force_refresh parameter has an effect"""
        mock_fetch.return_value = {"Kōkua": {"name": "Kōkua"}}
        config = OrgConfig({}, "test")

        # With the cache seeded with the target community, first
        # verify that the cache isn't refreshed automatically
        config._community_info_cache = {"Kōkua": {"name": "Kōkua"}}
        config.get_community_info("Kōkua")
        mock_fetch.assert_not_called()

        # Now, set force_refresh and make sure it is refreshed
        config.get_community_info("Kōkua", force_refresh=True)
        mock_fetch.assert_called()
Ejemplo n.º 4
0
    def test_get_community_info__fetch_if_not_in_cache(self):
        """Verify that the internal cache is automatically refreshed

        The cache should be refreshed automatically if the requested community
        is not in the cache.
        """
        responses.add(
            "GET",
            "https://test/services/data/v45.0/connect/communities",
            json={"communities": [{"name": "Kōkua"}]},
        )

        config = OrgConfig(
            {"instance_url": "https://test", "access_token": "TOKEN"}, "test"
        )
        config._community_info_cache = {}
        info = config.get_community_info("Kōkua")
        self.assertEqual(info["name"], "Kōkua")