Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Relax api regex for some models allowng . in names
Default api urls do not allow '.' characters when matching the names, presumably to ensure '.<format>' specifications are definitely matched properly. This patch relaxes this as we are definitely going to want to allow for '.' for things like version names. - change the lookup_value_regex for Component, Milestone and Version models - add hypothesis tests for testing the values that the api is allowed to use for names when creating objects from each list view
- Loading branch information
Showing
6 changed files
with
91 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,84 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from django.urls import reverse | ||
from hypothesis import example, given, strategies as st | ||
from hypothesis.extra.django import TestCase | ||
from rest_framework.test import APIClient, APIRequestFactory | ||
from rest_framework import status | ||
|
||
from ...models import Product | ||
|
||
name_st = st.text( | ||
st.characters( | ||
blacklist_characters="/", | ||
max_codepoint=1000, | ||
blacklist_categories=("Cc", "Cs") | ||
), | ||
min_size=1 | ||
).map(lambda x: x.strip()).filter(lambda s: len(s) > 0) | ||
|
||
|
||
class CommonAPIPropertiesTestCase(TestCase): | ||
"""Common tests for API""" | ||
|
||
def setUp(self): | ||
self.client = APIClient() | ||
self.factory = APIRequestFactory() | ||
self.product = Product.objects.create(prefix="BH", name="Bloodhound") | ||
self.list_uri = reverse( | ||
self.list_view_name, | ||
kwargs={"product_prefix": "BH"} | ||
) | ||
|
||
|
||
class NameTestsMixin: | ||
@given(name=name_st) | ||
@example("next 1.x") | ||
def test_create(self, name): | ||
data = { | ||
"name": name, | ||
"description": "Example Description", | ||
} | ||
|
||
response = self.client.post(self.list_uri, data) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
|
||
class ComponentAPIPropertiesTest(CommonAPIPropertiesTestCase, NameTestsMixin): | ||
"""Hypothesis tests for component API""" | ||
|
||
def setUp(self): | ||
self.list_view_name = "product-components-list" | ||
super().setUp() | ||
|
||
|
||
class MilestoneAPIPropertiesTest(CommonAPIPropertiesTestCase, NameTestsMixin): | ||
"""Hypothesis tests for milestone API""" | ||
|
||
def setUp(self): | ||
self.list_view_name = "product-milestones-list" | ||
super().setUp() | ||
|
||
|
||
class VersionAPIPropertiesTest(CommonAPIPropertiesTestCase, NameTestsMixin): | ||
"""Hypothesis tests for version API""" | ||
|
||
def setUp(self): | ||
self.list_view_name = "product-versions-list" | ||
super().setUp() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters