Example #1
0
    def test_handler_cache_hit(self):
        GLApiCache.invalidate()

        handler = self.request(path='/public')
        resp = yield handler.get()

        self.assertEqual(len(GLApiCache.memory_cache_dict), 1)

        cached_resp = GLApiCache.get("/public", "en")

        second_resp = yield handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)

        # Check that a different language doesn't blow away a different resource
        handler_fr = self.request(path='/public',
                                  headers={'gl-language': 'fr'})
        resp_fr = yield handler_fr.get()
        cached_resp_fr = GLApiCache.get("/public", "fr")

        self.assertEqual(resp_fr, cached_resp_fr)

        s = reduce(lambda x, y: x + len(y),
                   GLApiCache.memory_cache_dict.values(), 0)

        self.assertEqual(s, 2)
        self.assertNotEqual(resp_fr, cached_resp)
Example #2
0
 def test_set(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(pdp_it == "come una catapulta!")
     yield GLApiCache.set("passante_di_professione", "it", "ma io ho visto tutto!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "already", "cached")
     self.assertEqual(pdp_it, "ma io ho visto tutto!")
Example #3
0
 def test_get(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     pdp_en = yield GLApiCache.get("passante_di_professione", "en", self.mario, "like", "a", "catapult!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue("it" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertTrue("en" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertEqual(pdp_it, "come una catapulta!")
     self.assertEqual(pdp_en, "like a catapult!")
Example #4
0
    def get(self):
        """
        Get the Ahmia.fi descriptor
        """
        node_info = yield GLApiCache.get("node", self.request.language, serialize_node, self.request.language)

        if node_info["ahmia"]:
            ret = yield GLApiCache.get("ahmia", self.request.language, serialize_ahmia, self.request.language)

            self.finish(ret)
        else:  # in case of disabled option we return 404
            self.set_status(404)
            self.finish()
Example #5
0
    def get(self):
        """
        Get the ahmia.fi descriptor
        """
        node_info = yield GLApiCache.get('node', self.request.language,
                                         serialize_node, self.request.language)

        if node_info['ahmia']:
            ret = yield GLApiCache.get('ahmia', self.request.language,
                                       serialize_ahmia, self.request.language)

            self.write(ret)
        else:  # in case of disabled option we return 404
            self.set_status(404)
Example #6
0
    def get(self):
        """
        Get the Ahmia.fi descriptor
        """
        node_info = yield GLApiCache.get('node', self.request.language,
                                         serialize_node, self.request.language)

        if node_info['ahmia']:
            ret = yield GLApiCache.get('ahmia', self.request.language,
                                       serialize_ahmia, self.request.language)

            self.finish(ret)
        else:  # in case of disabled option we return 404
            self.set_status(404)
            self.finish()
 def test_set(self):
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "come", "una", "catapulta!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(pdp_it == "come una catapulta!")
     yield GLApiCache.set("passante_di_professione", "it",
                          "ma io ho visto tutto!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "already", "cached")
     self.assertEqual(pdp_it, "ma io ho visto tutto!")
 def test_get(self):
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "come", "una", "catapulta!")
     pdp_en = yield GLApiCache.get("passante_di_professione", "en",
                                   self.mario, "like", "a", "catapult!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(
         "it" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertTrue(
         "en" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertEqual(pdp_it, "come una catapulta!")
     self.assertEqual(pdp_en, "like a catapult!")
Example #9
0
 def test_invalidate(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
Example #10
0
 def get(self):
     """
     Get all the receivers.
     """
     ret = yield GLApiCache.get('receivers', self.request.language,
                                get_public_receiver_list, self.request.language)
     self.finish(ret)
Example #11
0
    def get(self, lang):
        self.set_header('Content-Type', 'application/json')

        l10n = yield GLApiCache.get('l10n', self.request.language,
                                    get_l10n, self.request.language)

        self.write(l10n)
Example #12
0
 def get(self):
     """
     Get all the public resources.
     """
     ret = yield GLApiCache.get('public', self.request.language,
                                get_public_resources, self.request.language)
     self.write(ret)
Example #13
0
 def get(self):
     """
     Get all the contexts.
     """
     ret = yield GLApiCache.get('contexts', self.request.language,
                                get_public_context_list, self.request.language)
     self.finish(ret)
Example #14
0
 def get(self):
     """
     Get all the public resources.
     """
     ret = yield GLApiCache.get('public', self.request.language,
                                get_public_resources, self.request.language)
     self.write(ret)
Example #15
0
 def get(self):
     """
     Get all the receivers.
     """
     ret = yield GLApiCache.get('receivers', self.request.language,
                                get_public_receiver_list,
                                self.request.language)
     self.finish(ret)
Example #16
0
 def get(self):
     """
     Get all the contexts.
     """
     ret = yield GLApiCache.get('contexts', self.request.language,
                                get_public_context_list,
                                self.request.language)
     self.finish(ret)
Example #17
0
 def test_get_set_items(self):
     self.assertEqual(GLApiCache.memory_cache_dict, {})
     self.assertIsNone(GLApiCache.get("passante_di_professione", "it"))
     self.assertIsNone(GLApiCache.get("passante_di_professione", "en"))
     GLApiCache.set("passante_di_professione", "it", 'ititit')
     GLApiCache.set("passante_di_professione", "en", 'enenen')
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(
         "it" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertTrue(
         "en" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertEqual(GLApiCache.get("passante_di_professione", "it"),
                      'ititit')
     self.assertEqual(GLApiCache.get("passante_di_professione", "en"),
                      'enenen')
     GLApiCache.invalidate()
     self.assertEqual(GLApiCache.memory_cache_dict, {})
Example #18
0
    def get(self):
        """
        Get the node infos.
        """
        ret = yield GLApiCache.get("node", self.request.language, serialize_node, self.request.language)

        ret["custom_homepage"] = os.path.isfile(os.path.join(GLSettings.static_path, "custom_homepage.html"))

        self.finish(ret)
 def test_invalidate(self):
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "come", "una", "catapulta!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
Example #20
0
    def get(self):
        """
        Get the node infos.
        """
        ret = yield GLApiCache.get('node', self.request.language,
                                   serialize_node, self.request.language)

        ret['custom_homepage'] = os.path.isfile(
            os.path.join(GLSettings.static_path, "custom_homepage.html"))

        self.finish(ret)
Example #21
0
    def get(self):
        """
        Return a list of all the fields templates available.

        :return: the list of field templates registered on the node.
        :rtype: list
        """
        response = yield GLApiCache.get('fieldtemplates', self.request.language,
                                        get_fieldtemplate_list, self.request.language, self.request.request_type)

        self.write(response)
Example #22
0
    def get(self):
        """
        Return all the questionnaires.

        Parameters: None
        Response: adminQuestionnaireList
        Errors: None
        """
        response = yield GLApiCache.get('questionnaires', self.request.language,
                                        get_questionnaire_list, self.request.language)

        self.write(response)
Example #23
0
    def get(self):
        """
        Get the ahmia.fi descriptor
        """
        if not GLSettings.memory_copy.ahmia:
            yield
            self.set_status(404)
            return

        ret = yield GLApiCache.get('ahmia', self.request.language,
                                   serialize_ahmia, self.request.language)

        self.write(ret)
Example #24
0
    def get(self):
        """
        Get the robots.txt
        """
        node_info = yield GLApiCache.get('node', self.request.language,
                                         serialize_node, self.request.language)

        self.set_header('Content-Type', 'text/plain')

        if node_info['allow_indexing']:
            self.write("User-agent: *\nAllow: /")
        else:
            self.write("User-agent: *\nDisallow: /")
Example #25
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        p = '/fake/sync/res'
        handler = self.request(handler_cls=FakeSyncHandler, path=p)
        resp = handler.get()

        cached_resp = GLApiCache.get(p, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)
Example #26
0
    def get(self):
        """
        Return a list of all the fields templates available.

        :return: the list of field templates registered on the node.
        :rtype: list
        """
        response = yield GLApiCache.get('fieldtemplates',
                                        self.request.language,
                                        get_fieldtemplate_list,
                                        self.request.language,
                                        self.request.request_type)

        self.write(response)
Example #27
0
    def get(self):
        """
        Return all the questionnaires.

        Parameters: None
        Response: adminQuestionnaireList
        Errors: None
        """
        response = yield GLApiCache.get('questionnaires',
                                        self.request.language,
                                        get_questionnaire_list,
                                        self.request.language)

        self.write(response)
Example #28
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        fake_path = '/xxx'
        fake_uri = 'https://www.globaleaks.org' + fake_path
        handler = self.request(handler_cls=FakeSyncHandler, uri=fake_uri)
        resp = handler.get()

        cached_resp = GLApiCache.get(fake_path, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)