api: adjust search for files paths to be partial
This makes it consistent with the partial search available when searching playbook paths. Change-Id: I2e4951a91b7ef39044b0c5f1b47d9cb8ad5858aa
This commit is contained in:
parent
7a192ac1b7
commit
df41b04b7a
@ -164,7 +164,7 @@ class ResultFilter(DateFilter):
|
||||
|
||||
class FileFilter(BaseFilter):
|
||||
playbook = django_filters.NumberFilter(field_name="playbook__id", lookup_expr="exact")
|
||||
path = django_filters.CharFilter(field_name="path", lookup_expr="exact")
|
||||
path = django_filters.CharFilter(field_name="path", lookup_expr="icontains")
|
||||
|
||||
# fmt: off
|
||||
order = django_filters.OrderingFilter(
|
||||
|
@ -164,3 +164,17 @@ class FileTestCase(APITestCase):
|
||||
for field in order_fields:
|
||||
request = self.client.get("/api/v1/files?order=-%s" % field)
|
||||
self.assertEqual(request.data["results"][0]["id"], second_file.id)
|
||||
|
||||
def test_get_file_by_path(self):
|
||||
# Create two files with similar paths
|
||||
first_file = factories.FileFactory(path="/root/file.yaml")
|
||||
factories.FileFactory(path="/root/some/path/file.yaml")
|
||||
|
||||
# Exact search should match one
|
||||
request = self.client.get("/api/v1/files?path=/root/file.yaml")
|
||||
self.assertEqual(1, len(request.data["results"]))
|
||||
self.assertEqual(first_file.path, request.data["results"][0]["path"])
|
||||
|
||||
# Partial match should match both files
|
||||
request = self.client.get("/api/v1/files?path=file.yaml")
|
||||
self.assertEqual(2, len(request.data["results"]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user