Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add launch_id to response in xml api method #38

Merged
merged 1 commit into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cdws_api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,38 @@ def test_additional_information(self):
self.assertFalse(launch['build']['branch'])
self.assertEqual(120.2, launch['duration'])

def test_additional_information_to_existent_launch(self):
data = \
'{"env": {"BRANCH": "master"}, "options": {"started_by": "user",' \
'"duration": "120.20"}}'
project = Project.objects.create(name='DummyTestProject')
testplan = TestPlan.objects.create(name='DummyTestPlan',
project=project)
launch = Launch.objects.create(test_plan=testplan)
self._post(file_name='junit-test-report.xml',
data={'launch': launch.id, 'data': data},
url='{}/junit/junit.xml'.format(testplan.id))
self._post(file_name='junit-test-report.xml',
data={'launch': launch.id, 'data': data},
url='{}/junit/junit.xml'.format(testplan.id))

launches = self._call_rest('get',
'launches/?testplan={}'.format(testplan.id))
self.assertEqual(1, launches['count'])
launch = launches['results'][0]
self.assertEqual(json.loads(data), launch['parameters'])
self.assertEqual('user', launch['started_by'])
self.assertTrue(launch['build'])
self.assertFalse(launch['build']['version'])
self.assertFalse(launch['build']['hash'])
self.assertFalse(launch['build']['branch'])
self.assertEqual(120.2, launch['duration'])

failed = self._call_rest(
'get',
'testresults/?launch={}&state={}'.format(launch['id'], FAILED))
self.assertEqual(4, failed['count'])

def test_empty_started_by(self):
data = '{"env": {"BRANCH": "master"}}'
project = Project.objects.create(name='DummyTestProject')
Expand Down
14 changes: 7 additions & 7 deletions cdws_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,15 +761,15 @@ def post(self, request, filename, testplan_id=None, xunit_format=None):
params = request.data['data']
file_obj = request.data['file']
try:
xml_parser_func(testplan_id=testplan_id,
format=xunit_format,
file_content=file_obj.read(),
launch_id=launch_id,
params=params)
data = xml_parser_func(testplan_id=testplan_id,
format=xunit_format,
file_content=file_obj.read(),
launch_id=launch_id,
params=params)
except Exception as e:
log.error(e)
return Response(
status=400,
status=status.HTTP_400_BAD_REQUEST,
data={'message': 'Xml file couldn\'t be parsed: {}'.format(e)})

return Response(status=204)
return Response(status=status.HTTP_200_OK, data=data)
4 changes: 2 additions & 2 deletions cdws_api/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def xml_parser_func(format, testplan_id, file_content, launch_id, params):
launch = get_launch(launch_id)
else:
launch = create_launch(testplan_id)
if params is not None:
if params is not None and launch.parameters == '{}':
launch.parameters = params
params_json = json.loads(params)
if 'options' in params_json \
Expand All @@ -181,4 +181,4 @@ def xml_parser_func(format, testplan_id, file_content, launch_id, params):
parser.load_string(file_content)
parser.update_duration(launch)
launch.calculate_counts()
return 'Done'
return {'launch_id': launch.id}