def list(self, request): ''' List all custom URLs for target Projects or Users. ''' urls = CustomURL.query().fetch() messages = [] for url in urls: messages.append(url.to_message()) return CustomUrlsMessage(urls=messages)
def test_custom_url_delete_method(self): ''' Add a custom_url and then delete it through the api. ''' slug = 'test-slug' custom_url_key = db_loader.create_custom_url(slug=slug) params = { 'key': encrypt(custom_url_key.urlsafe()), } response = generic_service_method_success_test(self, 'url', 'delete', params=params) self.assertEqual(response['response']['type'], 'Echo', 'CustomUrl delete service method failed.') self.assertEqual(len(CustomURL.query().fetch(1)), 0, 'Failed to delete custom url.')
def put(self, request): ''' Create a new custom URL. If the url is already in use, error.''' url_key = ndb.Key('CustomURL', request.slug) custom_url = url_key.get() if custom_url != None: # Url is already in use. raise remote.ApplicationError('Custom URL already exists.') target = ndb.Key(urlsafe=self.decrypt(request.target)) target_obj = target.get() if not target_obj: # Target object not found. raise remote.ApplicationError('put url requires a valid target') custom_url = CustomURL(key=url_key, slug=request.slug, target=target) custom_url.put() target_obj.customurl = url_key target_obj.put() return custom_url.to_message()