def test_next_job_basic(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"cli": "ls -l", 'env': ''}, status=200) job_id = res.json['job_id'] res = app.get("/jobs/next", {}, status=307) eq(res.headers['location'], 'http://localhost/jobs/1')
def test_get_all_jobs(): t = TestObj(json=[{'job_id': 1}]) mock = MagicMock(return_value = t) with patch('simplebatch.client.requests.get', mock): r = simplebatch.client.get_all_jobs() print "R:", r eq(len(r), 1) mock.assert_called_with('http://localhost:8000/jobs/')
def test_kill_job(): t = TestObj(json={'job_id': 1}) mock = MagicMock(return_value = t) with patch('simplebatch.client.requests.post', mock): r = simplebatch.client.kill_job(1) print "R:", r eq(r['job_id'], 1) mock.assert_called_with('http://localhost:8000/jobs/1/kill', data=json.dumps({}), headers={'content-type': 'application/json'})
def test_get_next_job(): t = TestObj(json={'job_id': 1}) mock = MagicMock(return_value = t) with patch('simplebatch.client.requests.get', mock): r = simplebatch.client.get_next_job() print "R:", r eq(r['job_id'], 1) mock.assert_called_with('http://localhost:8000/jobs/next')
def test_get_job(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"cli": "ls -l", 'env': ''}, status=200) job_id = res.json['job_id'] res = app.get("/jobs/1", status=200) eq(res.json['job_id'], 1) eq(res.json['status'], "pending")
def test_all_jobs(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"cli": "ls -l", 'env': ''}, status=200) job_id1 = res.json['job_id'] res = app.post_json("/jobs/", {"cli": "df -h", 'env': ''}, status=200) job_id2 = res.json['job_id'] res = app.get("/jobs/", status=200) eq(len(res.json), 2)
def test_run_job(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"cli": "ls -l", 'env': ''}, status=200) job_id = res.json['job_id'] res = app.post_json("/jobs/1/run", {}, status=307) res = app.get("/jobs/1", status=200) eq(res.json['job_id'], 1) eq(res.json['status'], "running") assert re.match("^[1-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]$", res.json['start_time']), res.json['start_time']
def test_submit_job(): j = Job() t = TestObj(json={'job_id': 1}) mock = MagicMock(return_value = t) with patch('simplebatch.client.requests.post', mock): r = simplebatch.client.submit_job(j) print "R:", r eq(r['job_id'], 1) job_dict = j.toDict() del job_dict['status'] del job_dict['job_id'] del job_dict['start_time'] del job_dict['end_time'] mock.assert_called_with('http://localhost:8000/jobs/', data=json.dumps(job_dict), headers={'content-type': 'application/json'})
def test_new_job(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"command": "ls", 'args': ['-l'], 'env': {}}, status=200) eq(res.json['job_id'], 1) eq(res.json['status'], "pending") res = app.post_json("/jobs/", {"command": "df", "args": [], 'env': {}}, status=200) eq(res.json['job_id'], 2) eq(res.json['status'], "pending")
def test_complete_job(self): app = TestApp(server.dispatcher) res = app.post_json("/jobs/", {"cli": "ls -l", 'env': ''}, status=200) job_id = res.json['job_id'] res = app.post_json("/jobs/1/run", {}, status=307) res = app.post_json("/jobs/1/complete", {"return_code": 42}, status=307) res = app.get("/jobs/1", status=200) eq(res.json['job_id'], 1) eq(res.json['status'], "complete") eq(res.json['return_code'], 42) assert re.match("^[1-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]$", res.json['end_time']), res.json['end_time'] assert res.json['end_time'] >= res.json['start_time']
def test_method3(self, req, job_id, post_data): assert type(post_data) is dict eq(post_data['return_code'], 42) eq(job_id, 1234) return "C"
def test(method, args, results): meth = wsgi_util.json_post(method) eq(json.loads(meth(*args).body), results)
def test(method, args, kwargs, results): meth = wsgi_util.json_return(method) eq(json.loads(meth(*args, **kwargs).body), results)