diff --git a/packagedb/api.py b/packagedb/api.py index 194b4d98..43df7aa3 100644 --- a/packagedb/api.py +++ b/packagedb/api.py @@ -105,6 +105,19 @@ def filter_by_checksums(self, request, *args, **kwargs): "27afff2610b5a94274a2311f8b15e514446b0e76 ] } + + Multiple checksums algorithms can be passed together: + { + "sha1": [ + "b55fd82f80cc1bd0bdabf9c6e3153788d35d7911", + "27afff2610b5a94274a2311f8b15e514446b0e76 + ], + "md5": [ + "e927df60b093456d4e611ae235c1aa5b" + ] + } + + This will return Resources whose sha1 or md5 matches those values. """ data = dict(request.data) unsupported_fields = [] @@ -473,6 +486,19 @@ def filter_by_checksums(self, request, *args, **kwargs): "27afff2610b5a94274a2311f8b15e514446b0e76 ] } + + Multiple checksums algorithms can be passed together: + { + "sha1": [ + "b55fd82f80cc1bd0bdabf9c6e3153788d35d7911", + "27afff2610b5a94274a2311f8b15e514446b0e76 + ], + "md5": [ + "e927df60b093456d4e611ae235c1aa5b" + ] + } + + This will return Packages whose sha1 or md5 matches those values. """ data = dict(request.data) unsupported_fields = [] diff --git a/packagedb/tests/test_api.py b/packagedb/tests/test_api.py index 0df2c252..8311e9e4 100644 --- a/packagedb/tests/test_api.py +++ b/packagedb/tests/test_api.py @@ -206,7 +206,7 @@ def test_api_resource_filter_by_checksums(self): response = self.client.post('/api/resources/filter_by_checksums/', data=data) self.assertEqual(2, response.data['count']) expected = self.get_test_loc('api/resource-filter_by_checksums-expected.json') - self.check_expected_results(response.data['results'], expected, regen=True) + self.check_expected_results(response.data['results'], expected, fields_to_remove=["url", "uuid", "package"], regen=False) class PackageApiTestCase(JsonBasedTesting, TestCase): test_data_dir = os.path.join(os.path.dirname(__file__), 'testfiles') @@ -455,7 +455,7 @@ def test_package_api_filter_by_checksums(self): response = self.client.post('/api/packages/filter_by_checksums/', data=data) self.assertEqual(3, response.data['count']) expected = self.get_test_loc('api/package-filter_by_checksums-expected.json') - self.check_expected_results(response.data['results'], expected, regen=True) + self.check_expected_results(response.data['results'], expected, fields_to_remove=["url", "uuid", "resources"], regen=False) class PackageApiReindexingTestCase(JsonBasedTesting, TestCase): diff --git a/packagedb/tests/testfiles/api/package-filter_by_checksums-expected.json b/packagedb/tests/testfiles/api/package-filter_by_checksums-expected.json index d614cf2d..a01c743b 100644 --- a/packagedb/tests/testfiles/api/package-filter_by_checksums-expected.json +++ b/packagedb/tests/testfiles/api/package-filter_by_checksums-expected.json @@ -1,7 +1,5 @@ [ { - "url":"http://testserver/api/packages/c47b9874-a870-4bfb-9578-e65e79cc4ac9/", - "uuid":"c47b9874-a870-4bfb-9578-e65e79cc4ac9", "filename":"Foo.zip", "package_sets":[], "package_content":null, @@ -45,12 +43,9 @@ "package_uid":"pkg:generic/generic/foo@12.34?test_qual=qual&uuid=fixed-uid-done-for-testing-5642512d1758#test_subpath", "datasource_id":null, "file_references":[], - "dependencies":[], - "resources":"http://testserver/api/packages/c47b9874-a870-4bfb-9578-e65e79cc4ac9/resources/" + "dependencies":[] }, { - "url":"http://testserver/api/packages/63897eec-1475-471c-b46d-aa7066eed476/", - "uuid":"63897eec-1475-471c-b46d-aa7066eed476", "filename":"Bar.zip", "package_sets":[], "package_content":null, @@ -94,12 +89,9 @@ "package_uid":"pkg:npm/example/bar@56.78?uuid=fixed-uid-done-for-testing-5642512d1758", "datasource_id":null, "file_references":[], - "dependencies":[], - "resources":"http://testserver/api/packages/63897eec-1475-471c-b46d-aa7066eed476/resources/" + "dependencies":[] }, { - "url":"http://testserver/api/packages/f327655d-bdd5-4fb7-bf06-e0b4bc596120/", - "uuid":"f327655d-bdd5-4fb7-bf06-e0b4bc596120", "filename":"Baz.zip", "package_sets":[], "package_content":null, @@ -143,7 +135,6 @@ "package_uid":"pkg:jar/sample/baz@90.12?uuid=fixed-uid-done-for-testing-5642512d1758", "datasource_id":null, "file_references":[], - "dependencies":[], - "resources":"http://testserver/api/packages/f327655d-bdd5-4fb7-bf06-e0b4bc596120/resources/" + "dependencies":[] } ] \ No newline at end of file diff --git a/packagedb/tests/testfiles/api/resource-filter_by_checksums-expected.json b/packagedb/tests/testfiles/api/resource-filter_by_checksums-expected.json index a5f83a44..325beb1c 100644 --- a/packagedb/tests/testfiles/api/resource-filter_by_checksums-expected.json +++ b/packagedb/tests/testfiles/api/resource-filter_by_checksums-expected.json @@ -1,6 +1,5 @@ [ { - "package":"http://testserver/api/packages/7c2697c2-30a0-4838-b2f2-07c5ad9f3d72/", "purl":"pkg:type1/name1", "path":"package1/contents1.txt", "type":"file", @@ -34,7 +33,6 @@ "extra_data":"{\"test1\": \"data1\"}" }, { - "package":"http://testserver/api/packages/505f6476-108c-41e2-850f-9720e33c07cb/", "purl":"pkg:type2/name2", "path":"package2/contents2.txt", "type":"file",