diff --git a/matchcode_pipeline/api.py b/matchcode_pipeline/api.py index b07b05a7..6131e5dd 100644 --- a/matchcode_pipeline/api.py +++ b/matchcode_pipeline/api.py @@ -138,6 +138,10 @@ def get_codebase_relations_summary(self, project): queryset = project.codebaserelations.all() return count_group_by(queryset, "map_type") + def validate_input_urls(self, value): + """Add support for providing multiple URLs in a single string.""" + return [url for entry in value for url in entry.split()] + def create(self, validated_data, matching_pipeline_name='matching'): """ Create a new `project` with `upload_file`, using the `matching` pipeline diff --git a/matchcode_pipeline/tests/test_api.py b/matchcode_pipeline/tests/test_api.py index ec976b8a..73dd3a19 100644 --- a/matchcode_pipeline/tests/test_api.py +++ b/matchcode_pipeline/tests/test_api.py @@ -127,9 +127,31 @@ def test_matchcode_pipeline_api_matching_detail(self): def test_matching_pipeline_api_matching_create(self, mock_execute_pipeline_task): # load upload_file contents test_out_loc = self.data_location / 'test-out.json' - content = open(test_out_loc, 'r') + + with open(test_out_loc) as f: + data = { + 'upload_file': f, + } + # Send match request + response = self.csrf_client.post(self.matching_list_url, data) + self.assertEqual(status.HTTP_201_CREATED, response.status_code) + self.assertEqual(1, len(response.data['runs'])) + self.assertEqual('matching', response.data['runs'][0]['pipeline_name']) + mock_execute_pipeline_task.assert_called_once() + + created_matching_project_detail_url = response.data['url'] + matching_project_uuid = response.data['uuid'] + results_url = reverse('matching-results', args=[matching_project_uuid]) + + # Check that the file was uploaded + response = self.csrf_client.get(created_matching_project_detail_url) + self.assertEqual('test-out.json', response.data['input_sources'][0]['filename']) + + @mock.patch('scanpipe.models.Run.execute_task_async') + def test_matching_pipeline_api_matching_create_multiple_input_urls(self, mock_execute_pipeline_task): + # load input_urls data = { - 'upload_file': content, + 'input_urls': 'https://registry.npmjs.org/asdf/-/asdf-1.2.2.tgz\r\nhttps://registry.npmjs.org/asdf/-/asdf-1.2.1.tgz', } # Send match request @@ -145,7 +167,10 @@ def test_matching_pipeline_api_matching_create(self, mock_execute_pipeline_task) # Check that the file was uploaded response = self.csrf_client.get(created_matching_project_detail_url) - self.assertEqual('test-out.json', response.data['input_sources'][0]['filename']) + input_sources = response.data['input_sources'] + self.assertEqual(2, len(input_sources)) + self.assertEqual('asdf-1.2.2.tgz', input_sources[0]['filename']) + self.assertEqual('asdf-1.2.1.tgz', input_sources[1]['filename']) def test_matchcode_pipeline_api_run_detail(self): run1 = self.project1.add_pipeline('matching')