def test_retrieve_job_returns_500_when_invalid_request_data(self): expected = [dict(status = 500)] hostname = 'http://localhost:8080' post_data = {'jobname' : 'Test1'} request = self.factory.post('/pull/retrieve_job',data=post_data,HTTP_X_REQUESTED_WITH='XMLHttpRequest') request.user = Mock(returnValue=User()) request.user.is_authenticated = Mock(returnValue=True) actual = views.retrieve_job(request) self.assertEqual(actual.content,simplejson.dumps(expected)) self.assertEqual(actual.status_code,200)
def test_retrieve_job_returns_500_when_invalid_request_data(self): expected = [dict(status=500)] hostname = 'http://localhost:8080' post_data = {'jobname': 'Test1'} request = self.factory.post('/pull/retrieve_job', data=post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') request.user = Mock(returnValue=User()) request.user.is_authenticated = Mock(returnValue=True) actual = views.retrieve_job(request) self.assertEqual(actual.content, simplejson.dumps(expected)) self.assertEqual(actual.status_code, 200)
def test_retrieve_job_returns_200_when_user_is_authenticated(self): d = dict(jobname = 'Test2', status = 'SUCCESS') hostname = 'http://localhost:8080' post_data = {'hostname' : hostname, 'jobname' : 'Test2', 'displayname' : 'Test2'} d.update(dict(hostname = hostname, status = 200)) request = self.factory.post('/pull/retrieve_job',data=post_data,HTTP_X_REQUESTED_WITH='XMLHttpRequest') request.session = {'http://localhost:8080/Test2' : d} user = User(username='******') user.save() request.user = user request.user.is_authenticated = Mock(returnValue=True) actual = views.retrieve_job(request) self.assertEqual(actual.content,simplejson.dumps([d])) self.assertEqual(actual.status_code,200)
def test_retrieve_job_returns_200_when_user_is_authenticated(self): d = dict(jobname='Test2', status='SUCCESS') hostname = 'http://localhost:8080' post_data = { 'hostname': hostname, 'jobname': 'Test2', 'displayname': 'Test2' } d.update(dict(hostname=hostname, status=200)) request = self.factory.post('/pull/retrieve_job', data=post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') request.session = {'http://localhost:8080/Test2': d} user = User(username='******') user.save() request.user = user request.user.is_authenticated = Mock(returnValue=True) actual = views.retrieve_job(request) self.assertEqual(actual.content, simplejson.dumps([d])) self.assertEqual(actual.status_code, 200)