|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# |
| 3 | +# http://nexb.com and https://github.com/nexB/scancode.io |
| 4 | +# The ScanCode.io software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with ScanCode.io is provided as-is without warranties. |
| 6 | +# ScanCode is a trademark of nexB Inc. |
| 7 | +# |
| 8 | +# You may not use this software except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 10 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 11 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | +# specific language governing permissions and limitations under the License. |
| 14 | +# |
| 15 | +# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 16 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 17 | +# ScanCode.io should be considered or used as legal advice. Consult an Attorney |
| 18 | +# for any legal advice. |
| 19 | +# |
| 20 | +# ScanCode.io is a free software code scanning tool from nexB Inc. and others. |
| 21 | +# Visit https://github.com/nexB/scancode.io for support and download. |
| 22 | + |
| 23 | +from django.test import TestCase |
| 24 | + |
| 25 | +from scanpipe.filters import ResourceFilterSet |
| 26 | +from scanpipe.models import CodebaseResource |
| 27 | +from scanpipe.models import Project |
| 28 | + |
| 29 | + |
| 30 | +class ScanPipeFiltersTest(TestCase): |
| 31 | + def setUp(self): |
| 32 | + self.project1 = Project.objects.create(name="Analysis") |
| 33 | + |
| 34 | + def test_scanpipe_filters_filter_queryset_empty_values(self): |
| 35 | + resource1 = CodebaseResource.objects.create( |
| 36 | + project=self.project1, |
| 37 | + path="r1", |
| 38 | + # CharField blank=True null=False |
| 39 | + programming_language="Python", |
| 40 | + # JSONField default=list |
| 41 | + copyrights=[{"copyright": "Copyright (c)"}], |
| 42 | + ) |
| 43 | + resource2 = CodebaseResource.objects.create( |
| 44 | + project=self.project1, |
| 45 | + path="r2", |
| 46 | + ) |
| 47 | + |
| 48 | + data = {"programming_language": ""} |
| 49 | + filterset = ResourceFilterSet(data=data) |
| 50 | + self.assertEqual([resource1, resource2], list(filterset.qs)) |
| 51 | + |
| 52 | + data = {"programming_language": "Python"} |
| 53 | + filterset = ResourceFilterSet(data=data) |
| 54 | + self.assertEqual([resource1], list(filterset.qs)) |
| 55 | + |
| 56 | + data = {"programming_language": "EMPTY"} |
| 57 | + filterset = ResourceFilterSet(data=data) |
| 58 | + self.assertEqual([resource2], list(filterset.qs)) |
| 59 | + |
| 60 | + data = {"copyrights": ""} |
| 61 | + filterset = ResourceFilterSet(data=data) |
| 62 | + self.assertEqual([resource1, resource2], list(filterset.qs)) |
| 63 | + |
| 64 | + data = {"copyrights": "Copyright"} |
| 65 | + filterset = ResourceFilterSet(data=data) |
| 66 | + self.assertEqual([resource1], list(filterset.qs)) |
| 67 | + |
| 68 | + data = {"copyrights": "EMPTY"} |
| 69 | + filterset = ResourceFilterSet(data=data) |
| 70 | + self.assertEqual([resource2], list(filterset.qs)) |
0 commit comments