def get(self, name):
     '''
     @summary: deals with GET request (getting a JSON HAL of the resource)
     @param name: name of the resource
     '''
     tmp = LOCK_MANAGER_INSTANCE.get_resource_as_dict(name)
     resource = Resource(self.reverse_url("resource", name), {"name": name})
     if tmp:
         for lock_dict in tmp['locks']:
             lock = Resource(self.reverse_url("lock", name, lock_dict['uid']), lock_dict)
             resource.add_embedded_resource("locks", lock)
     self.set_header("Content-Type", "application/hal+json")
     self.finish(resource.to_json())
 def get(self, name, uid):
     '''
     @summary: deals with GET request
     @param name: name of the resource
     @param uid: uid of the lock
     '''
     lock = LOCK_MANAGER_INSTANCE.get_lock(name, uid)
     if lock:
         self.set_header('Content-Type', 'application/hal+json')
         hal_lock = Resource(href=self.reverse_url("lock", name, lock.uid),
                             properties=lock.to_dict())
         hal_resource_link = Link(href=self.reverse_url("resource", name))
         hal_lock.add_link(rel="resource", link=hal_resource_link, multiple=False)
         self.write(hal_lock.to_json())
     else:
         self.send_error(status_code=404, message="lock not found")
         return
 def get(self, name, uid):
     '''
     @summary: deals with GET request
     @param name: name of the resource
     @param uid: uid of the lock
     '''
     lock = LOCK_MANAGER_INSTANCE.get_lock(name, uid)
     if lock:
         self.set_header('Content-Type', 'application/hal+json')
         hal_lock = Resource(href=self.reverse_url("lock", name, lock.uid),
                             properties=lock.to_dict())
         hal_resource_link = Link(href=self.reverse_url("resource", name))
         hal_lock.add_link(rel="resource",
                           link=hal_resource_link,
                           multiple=False)
         self.write(hal_lock.to_json())
     else:
         self.send_error(status_code=404, message="lock not found")
         return
 def test_resource3(self):
     a = Resource("/foo", {'key1': 'value1', 'key2': 'value2'})
     b = Resource("/bar", {'key3': 'value3', 'key4': 'value4'})
     a.add_embedded_resource("bars", b)
     tmp = a.to_dict()
     self.assertEqual(tmp["_embedded"]['bars'][0]['key3'], 'value3')
     self.assertEqual(tmp["_embedded"]['bars'][0]['key4'], 'value4')
 def get(self):
     '''
     @summary: deals with GET request (getting a JSON HAL of resources)
     '''
     resources = Resource(self.reverse_url("resources"))
     resources_names = LOCK_MANAGER_INSTANCE.get_resources_names()
     for resource_name in resources_names:
         tmp = LOCK_MANAGER_INSTANCE.get_resource_as_dict(resource_name)
         resource = Resource(self.reverse_url("resource", tmp['name']), {"name": tmp['name']})
         resources.add_embedded_resource("resources", resource)
     self.set_header("Content-Type", "application/hal+json")
     self.finish(resources.to_json())
 def get(self, name):
     '''
     @summary: deals with GET request (getting a JSON HAL of the resource)
     @param name: name of the resource
     '''
     tmp = LOCK_MANAGER_INSTANCE.get_resource_as_dict(name)
     resource = Resource(self.reverse_url("resource", name), {"name": name})
     if tmp:
         for lock_dict in tmp['locks']:
             lock = Resource(
                 self.reverse_url("lock", name, lock_dict['uid']),
                 lock_dict)
             resource.add_embedded_resource("locks", lock)
     self.set_header("Content-Type", "application/hal+json")
     self.finish(resource.to_json())
 def test_resource2(self):
     a = Resource("/foo", {'key1': 'value1', 'key2': 'value2'})
     tmp = a.to_dict()
     self.assertEqual(tmp['key1'], 'value1')
     self.assertEqual(tmp['key2'], 'value2')
 def test_resource1(self):
     a = Resource("/foo")
     tmp = a.to_dict()
     self.assertEqual(tmp['_links']['self']['href'], '/foo')