Skip to content

Commit

Permalink
Add unit test for clean_purl
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Nov 12, 2024
1 parent c271768 commit 9b63e21
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scanpipe/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class Meta:
"purl": forms.TextInput(
attrs={
"class": "input",
"placeholder": "pkg:npm/lodash@4.0.1",
"placeholder": "pkg:npm/lodash@4.7.21",
}
),
}
Expand Down
6 changes: 4 additions & 2 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,10 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, UpdateMixin, models.Model):
max_length=2048,
blank=True,
help_text=_(
"Package URL for the project, used for pushing project scan result to "
"FederatedCode. This should be the PURL of the input."
"Package URL (PURL) for the project, required for pushing the project's "
"scan result to FederatedCode. For example, if the input is an input URL "
"like https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz, the "
"corresponding PURL would be pkg:npm/[email protected]."
),
)

Expand Down
2 changes: 1 addition & 1 deletion scanpipe/templates/scanpipe/project_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="control">
{{ form.purl }}
</div>
<p class="help">{{ form.purl.help_text }}</p>
<p class="help">{{ form.purl.help_text|urlize }}</p>
</div>
<div class="field">
<label class="label" for="{{ form.notes.id_for_label }}">
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/tests/pipes/test_federatedcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_scanpipe_pipes_federatedcode_add_scan_result(self):
self.assertIn("npm/foobar/v1.2.3/scancodeio.json", repo.untracked_files)
shutil.rmtree(repo.working_dir)

def test_scancpipe_pipes_federatedcode_delete_local_clone(self):
def test_scanpipe_pipes_federatedcode_delete_local_clone(self):
local_dir = tempfile.mkdtemp()
repo = git.Repo.init(local_dir)
federatedcode.delete_local_clone(repo)
Expand Down
18 changes: 18 additions & 0 deletions scanpipe/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ def test_scanpipe_forms_project_settings_form_policies(self):
self.assertEqual(policies_as_yaml.strip(), project.settings["policies"])
self.assertEqual(license_policies_index, project.get_policy_index())

def test_scanpipe_forms_project_settings_form_purl(self):
data_invalid_purl = {
"name": "proj name",
"purl": "pkg/npm/[email protected]",
}
data_valid_purl = {
"name": "proj name",
"purl": "pkg:npm/[email protected]",
}

form1 = ProjectSettingsForm(data=data_invalid_purl)
self.assertFalse(form1.is_valid())

form2 = ProjectSettingsForm(data=data_valid_purl)
self.assertTrue(form2.is_valid())
obj = form2.save()
self.assertEqual("pkg:npm/[email protected]", obj.purl)

def test_scanpipe_forms_edit_input_source_tag_form(self):
data = {}
form = EditInputSourceTagForm(data=data)
Expand Down

0 comments on commit 9b63e21

Please sign in to comment.