Skip to content
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
4 changes: 4 additions & 0 deletions matchcode_pipeline/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions matchcode_pipeline/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down