def req_url(tid=None): from ..config import config as c from dxpy.web.urls import req_url if tid is None: return req_url(c['names'], c['ip'], c['port'], None, c['version'], c['base']) else: return req_url(c['name'], c['ip'], c['port'], tid, c['version'], c['base'])
def test_req_url_empty_base_1(self): result = urls.req_url('task', '127.0.0.1', 23300, 10, 0.1, '/') expect = 'http://127.0.0.1:23300/api/v0.1/task/10'
def test_req_url_non_suffix(self): result = urls.req_url('tasks', '127.0.0.1', 23300, None, 0.1, '/') expect = 'http://127.0.0.1:23300/api/v0.1/tasks/'
def test_req_url_non_empty_base_2(self): result = urls.req_url('task', '127.0.0.1', 23300, 10, 0.1, 'parent') expect = 'http://127.0.0.1:23300/api/v0.1/parent/task/10' self.assertEqual(result, expect)
def delete(tid): r = requests.delete(req_url(tid)) if r.status_code == 404: raise TaskNotFoundError(tid)
def update(task_json): task_json_dct = json.loads(task_json) r = requests.put(req_url(task_json_dct['id']), data={'task': task_json}) if r.status_code == 404: raise TaskNotFoundError(task_json_dct['id'])
def read_all(): return rx.Observable.from_(json.loads(requests.get(req_url()).text))
def read(tid): r = requests.get(req_url(tid)) if r.status_code == 200: return r.text else: raise TaskNotFoundError(tid)
def create(task_json): r = requests.post(req_url(), {'task': task_json}) return r.json()['id']