def put(self, field_id): """ Update a single field's attributes. :param field_id: :return: the serialized field :rtype: FieldDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.FieldDesc) # enforce difference between /admin/field and /admin/fieldtemplate request['is_template'] = False response = yield update_field(field_id, request, self.request.language) # get the updated list of contexts, and update the cache public_contexts_list = yield get_public_context_list(self.request.language) GLApiCache.invalidate('contexts') GLApiCache.set('contexts', self.request.language, public_contexts_list) self.set_status(202) # Updated self.finish(response)
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)
def initialization(self): self.responses = [] # we need to reset settings.session to keep each test independent GLSessions.clear() # we need to reset GLApiCache to keep each test independent GLApiCache.invalidate()
def put(self, lang): request = json.loads(self.request.body) yield update_custom_texts(lang, request) GLApiCache.invalidate() self.set_status(202) # Updated
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!")
def delete(self, context_id): """ Delete the specified context. Request: AdminContextDesc Response: None Errors: InvalidInputFormat, ContextIdNotFound """ yield delete_context(context_id) GLApiCache.invalidate()
def delete(self, questionnaire_id): """ Delete the specified questionnaire. Request: AdminQuestionnaireDesc Response: None Errors: InvalidInputFormat, QuestionnaireIdNotFound """ yield delete_questionnaire(questionnaire_id) GLApiCache.invalidate()
def delete(self, field_id): """ Delete a single field template. :param field_id: :raises FieldIdNotFound: if there is no field with such id. """ yield delete_field(field_id) GLApiCache.invalidate()
def delete(self, step_id): """ Delete the specified step. :param step_id: :raises StepIdNotFound: if there is no step with such id. :raises InvalidInputFormat: if validation fails. """ yield delete_step(step_id) GLApiCache.invalidate()
def delete(self, field_id): """ Delete a single field. :param field_id: :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ yield delete_field(field_id) GLApiCache.invalidate()
def post(self): request = self.validate_message(self.request.body, requests.WizardDesc) # Wizard will raise exceptions if there are any errors with the request yield wizard(request, self.request.language) # cache must be updated in order to set wizard_done = True yield serialize_node(self.request.language) GLApiCache.invalidate() self.set_status(201) # Created
def delete(self, user_id): """ Delete the specified user. Parameters: user_id Request: None Response: None Errors: InvalidInputFormat, UserIdNotFound """ yield delete_user(user_id) GLApiCache.invalidate()
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 post(self): """ """ request = self.validate_message(self.request.body, requests.WizardFirstSetupDesc) yield wizard(request, self.request.language) # cache must be updated in particular to set wizard_done = True public_node_desc = yield serialize_node(self.request.language) GLApiCache.invalidate() self.set_status(201) # Created
def delete(self, context_id): """ Delete the specified context. Request: AdminContextDesc Response: None Errors: InvalidInputFormat, ContextIdNotFound """ yield delete_context(context_id) GLApiCache.invalidate() self.set_status(200) # Ok and return no content self.finish()
def delete(self, questionnaire_id): """ Delete the specified questionnaire. Request: AdminQuestionnaireDesc Response: None Errors: InvalidInputFormat, QuestionnaireIdNotFound """ yield delete_questionnaire(questionnaire_id) GLApiCache.invalidate() self.set_status(200) # Ok and return no content self.finish()
def put(self): """ Parameters: None Request: ReceiverReceiverDesc Response: ReceiverReceiverDesc Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication """ request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc) receiver_status = yield update_receiver_settings(self.current_user.user_id, request, self.request.language) GLApiCache.invalidate() self.write(receiver_status)
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)
def post(self, obj_key, obj_id): uploaded_file = self.get_file_upload() if uploaded_file is None: self.set_status(201) return try: yield add_model_img(model_map[obj_key], obj_id, uploaded_file['body'].read()) finally: uploaded_file['body'].close() GLApiCache.invalidate() self.set_status(201)
def delete(self, field_id): """ Delete a single field. :param field_id: :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ yield delete_field(field_id) # get the updated list of contexts, and update the cache GLApiCache.invalidate('contexts') self.set_status(200)
def post(self, key): uploaded_file = self.get_file_upload() if uploaded_file is None: self.set_status(201) return try: yield add_file(uploaded_file['body'].read(), key) finally: uploaded_file['body'].close() GLApiCache.invalidate() self.set_status(201)
def put(self): """ Update the node infos. Request: AdminNodeDesc Response: AdminNodeDesc Errors: InvalidInputFormat """ request = self.validate_message(self.request.body, requests.AdminNodeDesc) node_description = yield update_node(request, self.request.language) GLApiCache.invalidate() self.set_status(202) # Updated self.write(node_description)
def test_get(self): handler = self.request() yield handler.get(lang=u'en') self.assertNotIn('12345', self.responses[0]) yield admin_l10n.update_custom_texts(u'en', custom_texts) GLApiCache.invalidate('l10n') yield handler.get(lang=u'en') self.assertIn('12345', self.responses[1]) self.assertEqual('54321', self.responses[1]['12345'])
def get(self, field_id): """ Get the field identified by field_id :param field_id: :return: the serialized field :rtype: AdminFieldDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ response = yield get_field(field_id, self.request.language, self.request.request_type) GLApiCache.invalidate() self.write(response)
def delete(self, user_id): """ Delete the specified user. Parameters: user_id Request: None Response: None Errors: InvalidInputFormat, UserIdNotFound """ yield delete_user(user_id) GLApiCache.invalidate() self.set_status(200) # OK and return not content self.finish()
def put(self): """ Update the node infos. Request: AdminNodeDesc Response: AdminNodeDesc Errors: InvalidInputFormat """ request = self.validate_message(self.request.body, requests.AdminNodeDesc) node_description = yield update_node(request, True, self.request.language) GLApiCache.invalidate() self.set_status(202) # Updated self.finish(node_description)
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)
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)
def delete(self, receiver_id): """ Delete the specified receiver. Parameters: receiver_id Request: None Response: None Errors: InvalidInputFormat, ReceiverIdNotFound """ yield delete_receiver(receiver_id) # get the updated list of receivers, and update the cache GLApiCache.invalidate() self.set_status(200) # OK and return not content self.finish()
def post(self): """ Create a new context. Request: AdminContextDesc Response: AdminContextDesc Errors: InvalidInputFormat, ReceiverIdNotFound """ request = self.validate_message(self.request.body, requests.AdminContextDesc) response = yield create_context(request, self.request.language) GLApiCache.invalidate() self.set_status(201) # Created self.finish(response)
def post(self): """ Get the specified receiver. Request: AdminReceiverDesc Response: AdminReceiverDesc Errors: InvalidInputFormat, ContextIdNotFound """ request = self.validate_message(self.request.body, requests.AdminReceiverDesc) response = yield create_receiver(request, self.request.language) GLApiCache.invalidate() self.set_status(201) # Created self.finish(response)
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)
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)
def put(self, user_id): """ Update the specified user. Parameters: user_id Request: AdminUserDesc Response: AdminUserDesc Errors: InvalidInputFormat, UserIdNotFound """ request = self.validate_message(self.request.body, requests.AdminUserDesc) response = yield admin_update_user(user_id, request, self.request.language) GLApiCache.invalidate() self.set_status(201) self.finish(response)
def get(self, field_id): """ Get the field identified by field_id :param field_id: :return: the serialized field :rtype: FieldDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ response = yield get_field(field_id, self.request.language) GLApiCache.invalidate('contexts') self.set_status(200) self.finish(response)
def post(self): """ Create a new field. :return: the serialized field :rtype: FieldDesc :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.FieldDesc) response = yield create_field(request, self.request.language) GLApiCache.invalidate('contexts') self.set_status(201) self.finish(response)
def post(self): """ Create a new step. :return: the serialized step :rtype: StepDesc :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.AdminStepDesc) response = yield create_step(request, self.request.language) GLApiCache.invalidate() self.set_status(201) self.write(response)
def get(self): """ Get the Ahmia.fi descriptor """ node_info = yield GLApiCache.get('node', self.request.language, anon_serialize_node, self.request.language) if node_info['ahmia']: ret = yield GLApiCache.get('ahmia', self.request.language, anon_serialize_ahmia, self.request.language) self.finish(ret) else: # in case of disabled option we return 404 self.set_status(404) self.finish()
def post(self): """ Create a new questionnaire. Request: AdminQuestionnaireDesc Response: AdminQuestionnaireDesc Errors: InvalidInputFormat, ReceiverIdNotFound """ validator = requests.AdminQuestionnaireDesc if self.request.language is not None else requests.AdminQuestionnaireDescRaw request = self.validate_message(self.request.body, validator) response = yield create_questionnaire(request, self.request.language) GLApiCache.invalidate() self.set_status(201) self.write(response)
def put(self, field_id): """ Update a single field template's attributes. :param field_id: :rtype: FieldTemplateDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.AdminFieldDesc) response = yield update_field(field_id, request, self.request.language) GLApiCache.invalidate('contexts') self.set_status(202) # Updated self.finish(response)
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, {})
def put(self, user_id): """ Update the specified user. Parameters: user_id Request: AdminUserDesc Response: AdminUserDesc Errors: InvalidInputFormat, UserIdNotFound """ request = self.validate_message(self.request.body, requests.AdminUserDesc) response = yield admin_update_user(user_id, request, self.request.language) GLApiCache.invalidate() self.set_status(201) self.write(response)
def put(self, step_id): """ Update attributes of the specified step :param step_id: :return: the serialized step :rtype: StepDesc :raises StepIdNotFound: if there is no step with such id. :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.StepDesc) response = yield update_step(step_id, request, self.request.language) GLApiCache.invalidate('contexts') self.set_status(202) # Updated self.finish(response)
def put(self, receiver_id): """ Update the specified receiver. Parameters: receiver_id Request: AdminReceiverDesc Response: AdminReceiverDesc Errors: InvalidInputFormat, ReceiverIdNotFound, ContextIdNotFound """ request = self.validate_message(self.request.body, requests.AdminReceiverDesc) response = yield update_receiver(receiver_id, request, self.request.language) GLApiCache.invalidate() self.set_status(201) self.finish(response)
def put(self, field_id): """ Update attributes of the specified step. :param field_id: :return: the serialized field :rtype: FieldDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.FieldDesc) response = yield update_field(field_id, request, self.request.language) # get the updated list of contexts, and update the cache GLApiCache.invalidate('contexts') self.set_status(202) # Updated self.finish(response)
def put(self, context_id): """ Update the specified context. Parameters: context_id Request: AdminContextDesc Response: AdminContextDesc Errors: InvalidInputFormat, ContextIdNotFound, ReceiverIdNotFound Updates the specified context. """ request = self.validate_message(self.request.body, requests.AdminContextDesc) response = yield update_context(context_id, request, self.request.language) GLApiCache.invalidate() self.set_status(202) # Updated self.finish(response)
def put(self, field_id): """ Update attributes of the specified step. :param field_id: :return: the serialized field :rtype: AdminFieldDesc :raises FieldIdNotFound: if there is no field with such id. :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.AdminFieldDesc) response = yield update_field(field_id, request, self.request.language, self.request.request_type) GLApiCache.invalidate() self.set_status(202) # Updated self.write(response)
def put(self, questionnaire_id): """ Update the specified questionnaire. Parameters: questionnaire_id Request: AdminQuestionnaireDesc Response: AdminQuestionnaireDesc Errors: InvalidInputFormat, QuestionnaireIdNotFound, ReceiverIdNotFound Updates the specified questionnaire. """ request = self.validate_message(self.request.body, requests.AdminQuestionnaireDesc) response = yield update_questionnaire(questionnaire_id, request, self.request.language) GLApiCache.invalidate() self.set_status(202) # Updated self.finish(response)
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 initialization(self): self.responses = [] def mock_write(cls, response=None): # !!! # Here we are making the assumption that every time write() get's # called it contains *all* of the response message. #RequestHandler.finish(cls, response) if response: self.responses.append(response) self._handler.write = mock_write # we make the assumption that we will always use call finish on write. self._handler.finish = mock_write # we need to reset settings.session to keep each test independent GLSessions.clear() # we need to reset GLApiCache to keep each test independent GLApiCache.invalidate()
def put(self): """ Parameters: None Request: ReceiverReceiverDesc Response: ReceiverReceiverDesc Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication, TipIdNotFound """ request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc) receiver_status = yield update_receiver_settings( self.current_user.user_id, request, self.request.language) # get the updated list of receivers, and update the cache public_receivers_list = yield get_public_receiver_list( self.request.language) GLApiCache.invalidate('receivers') GLApiCache.set('receivers', self.request.language, public_receivers_list) self.set_status(200) self.finish(receiver_status)
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)
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)
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)