diff --git a/matchcode/api.py b/matchcode/api.py index 6294fb09..68844b8d 100644 --- a/matchcode/api.py +++ b/matchcode/api.py @@ -15,6 +15,7 @@ from rest_framework.decorators import action from rest_framework.response import Response from rest_framework.serializers import CharField +from rest_framework.serializers import FloatField from rest_framework.serializers import HyperlinkedRelatedField from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ReadOnlyField @@ -92,7 +93,7 @@ class BaseDirectoryIndexMatchSerializer(Serializer): lookup_field='uuid', read_only=True ) - similarity_score = CharField() + similarity_score = FloatField() class CharMultipleWidget(widgets.TextInput): diff --git a/matchcode/tests/test_api.py b/matchcode/tests/test_api.py index 93c29ca3..8decc568 100644 --- a/matchcode/tests/test_api.py +++ b/matchcode/tests/test_api.py @@ -117,7 +117,7 @@ def test_api_approximate_directory_content_index_match_close_match(self): self.assertEqual(expected_matched_fingerprint, result['matched_fingerprint']) expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package1.uuid]) self.assertEqual(expected_package, result['package']) - self.assertEqual('0.9453125', result['similarity_score']) + self.assertEqual(0.9453125, result['similarity_score']) def test_api_approximate_directory_structure_index_match_close_match(self): # This test fingerprint has a hamming distance of 7 from the expected fingerprint @@ -134,7 +134,7 @@ def test_api_approximate_directory_structure_index_match_close_match(self): self.assertEqual(expected_matched_fingerprint, result['matched_fingerprint']) expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package2.uuid]) self.assertEqual(expected_package, result['package']) - self.assertEqual('0.9453125', result['similarity_score']) + self.assertEqual(0.9453125, result['similarity_score']) def test_api_approximate_directory_content_index_match(self): test_fingerprint = '00000007af7d63765c78fa516b5353f5ffa7df45' @@ -149,7 +149,7 @@ def test_api_approximate_directory_content_index_match(self): self.assertEqual(test_fingerprint, result['matched_fingerprint']) expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package1.uuid]) self.assertEqual(expected_package, result['package']) - self.assertEqual('1.0', result['similarity_score']) + self.assertEqual(1.0, result['similarity_score']) def test_api_approximate_directory_structure_index_match(self): test_fingerprint = '00000004d10982208810240820080a6a3e852486' @@ -164,4 +164,4 @@ def test_api_approximate_directory_structure_index_match(self): self.assertEqual(test_fingerprint, result['matched_fingerprint']) expected_package = 'http://testserver' + reverse('api:package-detail', args=[self.test_package2.uuid]) self.assertEqual(expected_package, result['package']) - self.assertEqual('1.0', result['similarity_score']) + self.assertEqual(1.0, result['similarity_score'])