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_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)
def put(self, lang): request = json.loads(self.request.body) yield update_custom_texts(lang, request) GLApiCache.invalidate() self.set_status(202) # Updated
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 set_onion_service_info(store, hostname, key): node_fact = NodeFactory(store) node_fact.set_val(u'onionservice', hostname) priv_fact = PrivateFactory(store) priv_fact.set_val(u'tor_onion_key', key) 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 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, context_id): """ Delete the specified context. Request: AdminContextDesc Response: None Errors: InvalidInputFormat, ContextIdNotFound """ yield delete_context(context_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 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 post(self): request = self.validate_message(self.request.content.read(), requests.WizardDesc) # Wizard will raise exceptions if there are any errors with the request yield wizard(request, self.request.language) yield serialize_node(self.request.language) # Invalidation is performed at this stage only after the asserts within # wizard have ensured that the wizard can be executed. GLApiCache.invalidate()
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 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 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 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, 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 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 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)
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 anon_serialize_node(self.request.language) GLApiCache.invalidate() self.set_status(201) # Created self.finish()
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)
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 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 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 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 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 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 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 put(self, receiver_id): """ Update the specified receiver. Parameters: receiver_id Request: AdminReceiverDesc Response: AdminReceiverDesc Errors: InvalidInputFormat, ReceiverIdNotFound, ContextId """ 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 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.StepDesc) response = yield create_step(request, self.request.language) GLApiCache.invalidate('contexts') self.set_status(201) self.finish(response)
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, False) # 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(200)
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 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 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 post(self): """ Create a new field. :return: the serialized field :rtype: AdminFieldDesc :raises InvalidInputFormat: if validation fails. """ request = self.validate_message(self.request.body, requests.AdminFieldDesc) response = yield create_field(request, self.request.language, self.request.request_type) GLApiCache.invalidate() self.set_status(201) self.write(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)