@ -15,56 +15,59 @@ from app.tests.common import DoesNotExist
|
|||||||
|
|
||||||
class APIFieldsTestCases:
|
class APIFieldsTestCases:
|
||||||
|
|
||||||
api_fields_common = {
|
@property
|
||||||
'id': {
|
def parameterized_test_data(self) -> dict:
|
||||||
'expected': int
|
|
||||||
},
|
|
||||||
'display_name': {
|
|
||||||
'expected': str
|
|
||||||
},
|
|
||||||
'_urls': {
|
|
||||||
'expected': dict
|
|
||||||
},
|
|
||||||
'_urls._self': {
|
|
||||||
'expected': str
|
|
||||||
},
|
|
||||||
'_urls.notes': {
|
|
||||||
'expected': str
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
api_fields_model = {
|
api_fields_common = {
|
||||||
'model_notes': {
|
'id': {
|
||||||
'expected': str
|
'expected': int
|
||||||
},
|
},
|
||||||
'created': {
|
'display_name': {
|
||||||
'expected': str
|
'expected': str
|
||||||
},
|
},
|
||||||
'modified': {
|
'_urls': {
|
||||||
'expected': str
|
'expected': dict
|
||||||
},
|
},
|
||||||
}
|
'_urls._self': {
|
||||||
|
'expected': str
|
||||||
|
},
|
||||||
|
'_urls.notes': {
|
||||||
|
'expected': str
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
api_fields_tenancy = {
|
api_fields_model = {
|
||||||
'organization': {
|
'model_notes': {
|
||||||
'expected': dict
|
'expected': str
|
||||||
},
|
},
|
||||||
'organization.id': {
|
'created': {
|
||||||
'expected': int
|
'expected': str
|
||||||
},
|
},
|
||||||
'organization.display_name': {
|
'modified': {
|
||||||
'expected': str
|
'expected': str
|
||||||
},
|
},
|
||||||
'organization.url': {
|
}
|
||||||
'expected': Hyperlink
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
parameterized_test_data = {
|
api_fields_tenancy = {
|
||||||
**api_fields_common,
|
'organization': {
|
||||||
**api_fields_tenancy,
|
'expected': dict
|
||||||
**api_fields_model,
|
},
|
||||||
}
|
'organization.id': {
|
||||||
|
'expected': int
|
||||||
|
},
|
||||||
|
'organization.display_name': {
|
||||||
|
'expected': str
|
||||||
|
},
|
||||||
|
'organization.url': {
|
||||||
|
'expected': Hyperlink
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
**api_fields_common.copy(),
|
||||||
|
**api_fields_tenancy.copy(),
|
||||||
|
**api_fields_model.copy(),
|
||||||
|
}
|
||||||
|
|
||||||
url_view_kwargs = {}
|
url_view_kwargs = {}
|
||||||
|
|
||||||
@ -229,3 +232,5 @@ class APIFieldsInheritedCases(
|
|||||||
):
|
):
|
||||||
|
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
|
parameterized_test_data = {}
|
@ -94,6 +94,10 @@ def pytest_generate_tests(metafunc):
|
|||||||
|
|
||||||
base_values = getattr(base, 'parameterized_' + parameterized_key, None)
|
base_values = getattr(base, 'parameterized_' + parameterized_key, None)
|
||||||
|
|
||||||
|
if isinstance(base_values, property):
|
||||||
|
|
||||||
|
base_values = getattr(base(), 'parameterized_' + parameterized_key, None)
|
||||||
|
|
||||||
if not isinstance(base_values, dict):
|
if not isinstance(base_values, dict):
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
@ -85,6 +85,53 @@ Test Cases are to test one object and one object **only**. If the object to be t
|
|||||||
!!! tip
|
!!! tip
|
||||||
If you inherit from an `InheritedCases` Class and there is a `class_setup` fixture, don't forget to import this into your test suite. This ensures it's available for use when running tests
|
If you inherit from an `InheritedCases` Class and there is a `class_setup` fixture, don't forget to import this into your test suite. This ensures it's available for use when running tests
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
If you find that a base classes variables are being mutated by other test classes, setup the variable within the base class as a property that contains the defaults as a variable within the function and returns the data as if the property was defined as a variable
|
||||||
|
<!-- markdownlint-disable -->
|
||||||
|
|
||||||
|
Don't do this as `my_variable` will be mutated by other test classes that inherit the base class.
|
||||||
|
|
||||||
|
``` py
|
||||||
|
|
||||||
|
class MyTestClassBase:
|
||||||
|
|
||||||
|
my_variable = 'a'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MyTestClass(
|
||||||
|
MyTestClassBase
|
||||||
|
):
|
||||||
|
|
||||||
|
my_variable = 'b'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Instead, do this. now `MyTestClass` wont override variable `my_variable` which means when another test class inherits from `MyTestClassBase`, variable `my_variable` will always return the desired default value.
|
||||||
|
|
||||||
|
``` py
|
||||||
|
|
||||||
|
class MyTestClassBase:
|
||||||
|
|
||||||
|
@property
|
||||||
|
def my_variable(self):
|
||||||
|
|
||||||
|
default = 'a'
|
||||||
|
|
||||||
|
return default.copy()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MyTestClass(
|
||||||
|
MyTestClassBase
|
||||||
|
):
|
||||||
|
|
||||||
|
my_variable = 'b'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- markdownlint-restore -->
|
||||||
|
|
||||||
|
|
||||||
### Fixtures
|
### Fixtures
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user