def test_allinone_no_jobmanager(self): from magmaweb.job import JobSubmissionError from pyramid.httpexceptions import HTTPInternalServerError import json post = {'ms_data': 'somexml', 'ms_data_file': ''} request = testing.DummyRequest(post=post) request.user = User('bob', 'Bob Example', '*****@*****.**') job = self.fake_job() jobquery = Mock(JobQuery) job.jobquery.return_value = jobquery views = Views(request) views.job_factory = Mock(JobFactory) views.job_factory.fromScratch = Mock(return_value=job) q = Mock(side_effect=JobSubmissionError()) views.job_factory.submitQuery = q with self.assertRaises(HTTPInternalServerError) as e: views.allinone() expected_json = {'success': False, 'msg': 'Unable to submit query'} self.assertEquals(json.loads(e.exception.body), expected_json) views.job_factory.fromScratch.assert_called_with('bob') jobquery.allinone.assert_called_with(post) views.job_factory.submitQuery.assert_called_with( jobquery.allinone(), job)
def test_allinone_restricted(self): self.config.add_settings(restricted=True) post = {'ms_data': 'somexml', 'ms_data_file': ''} request = testing.DummyRequest(post=post) request.user = User('bob', 'Bob Example', '*****@*****.**') job = self.fake_job() jobquery = Mock(JobQuery) job.jobquery.return_value = jobquery views = Views(request) views.job_factory = Mock(JobFactory) views.job_factory.fromScratch = Mock(return_value=job) views.allinone() job.jobquery.assert_called_with('http://example.com/status/foo.json', True, 1)
def test_uploaddb_post(self): self.config.add_route('results', '/results/{jobid}') from cgi import FieldStorage dbfile = FieldStorage() dbfile.file = StringIO() request = testing.DummyRequest(post={'db_file': dbfile}) request.user = User('bob', 'Bob Example', '*****@*****.**') views = Views(request) views.job_factory = Mock(JobFactory) job = self.fake_job() views.job_factory.fromDb.return_value = job response = views.uploaddb() views.job_factory.fromDb.assert_called_with(dbfile.file, 'bob') self.assertEqual(response.location, 'http://example.com/results/foo')
def test_allinone_with_ms_data_as_text(self): post = {'ms_data': 'somexml', 'ms_data_file': ''} request = testing.DummyRequest(post=post) request.user = User('bob', 'Bob Example', '*****@*****.**') job = self.fake_job() jobquery = Mock(JobQuery) job.jobquery.return_value = jobquery views = Views(request) views.job_factory = Mock(JobFactory) views.job_factory.fromScratch = Mock(return_value=job) response = views.allinone() views.job_factory.fromScratch.assert_called_with('bob') jobquery.allinone.assert_called_with(post) views.job_factory.submitQuery.assert_called_with( jobquery.allinone(), job) self.assertEqual(response, {'success': True, 'jobid': 'foo'}) self.assertEqual(job.ms_filename, 'Uploaded as text') job.jobquery.assert_called_with('http://example.com/status/foo.json', False, 1)
def test_allinone_with_ms_data_as_file(self): from cgi import FieldStorage ms_file = FieldStorage() ms_file.filename = r'c:\bla\bla\F1234.mzxml' post = {'ms_data_file': ms_file} request = testing.DummyRequest(post=post) request.user = User('bob', 'Bob Example', '*****@*****.**') job = self.fake_job() jobquery = Mock(JobQuery) job.jobquery.return_value = jobquery views = Views(request) views.job_factory = Mock(JobFactory) views.job_factory.fromScratch = Mock(return_value=job) response = views.allinone() views.job_factory.fromScratch.assert_called_with('bob') jobquery.allinone.assert_called_with(post) views.job_factory.submitQuery.assert_called_with( jobquery.allinone(), job) self.assertEqual(response, {'success': True, 'jobid': 'foo'}) self.assertEqual(job.ms_filename, r'c:\bla\bla\F1234.mzxml') job.jobquery.assert_called_with('http://example.com/status/foo.json', False, 1)