Beispiel #1
0
    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')
Beispiel #2
0
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/')
Beispiel #3
0
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'})
Beispiel #4
0
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')
Beispiel #5
0
    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")
Beispiel #6
0
    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)
Beispiel #7
0
    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']
Beispiel #8
0
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'})
Beispiel #9
0
    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")
Beispiel #10
0
    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']
Beispiel #11
0
 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"
Beispiel #12
0
 def test(method, args, results):
     meth = wsgi_util.json_post(method)
     eq(json.loads(meth(*args).body), results)
Beispiel #13
0
 def test(method, args, kwargs, results):
     meth = wsgi_util.json_return(method)
     eq(json.loads(meth(*args, **kwargs).body), results)