mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
add test to query results of /jobs call in api
This commit is contained in:
parent
88e93b7fe5
commit
dac16583b7
@ -206,3 +206,60 @@ class TestArgKwarg(BaseRestCherryPyTest):
|
||||
self.assertEqual(resp['return'][0]['args'], [1234])
|
||||
self.assertEqual(resp['return'][0]['kwargs'],
|
||||
{'ext_source': 'redis'})
|
||||
|
||||
|
||||
class TestJobs(BaseRestCherryPyTest):
|
||||
auth_creds = (
|
||||
('username', 'saltdev_auto'),
|
||||
('password', 'saltdev'),
|
||||
('eauth', 'auto'))
|
||||
|
||||
low = (
|
||||
('client', 'local'),
|
||||
('tgt', '*'),
|
||||
('fun', 'test.ping'),
|
||||
)
|
||||
|
||||
def _token(self):
|
||||
'''
|
||||
Return the token
|
||||
'''
|
||||
body = urlencode(self.auth_creds)
|
||||
request, response = self.request(
|
||||
'/login',
|
||||
method='POST',
|
||||
body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
)
|
||||
return response.headers['X-Auth-Token']
|
||||
|
||||
def _add_job(self):
|
||||
'''
|
||||
Helper function to add a job to the job cache
|
||||
'''
|
||||
cmd = dict(self.low, **dict(self.auth_creds))
|
||||
body = urlencode(cmd)
|
||||
|
||||
request, response = self.request('/run', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '200 OK')
|
||||
|
||||
def test_all_jobs(self):
|
||||
'''
|
||||
test query to /jobs returns job data
|
||||
'''
|
||||
self._add_job()
|
||||
|
||||
request, response = self.request('/jobs', method='GET',
|
||||
headers={
|
||||
'Accept': 'application/json',
|
||||
'X-Auth-Token': self._token(),
|
||||
})
|
||||
|
||||
resp = json.loads(response.body[0])
|
||||
self.assertIn('test.ping', str(resp['return']))
|
||||
self.assertEqual(response.status, '200 OK')
|
||||
|
Loading…
Reference in New Issue
Block a user