test(core): Ensure that a ticket milestone comes from the same assigned project
ref: #744 #723
This commit is contained in:
29
.github/ISSUE_TEMPLATE/new_model.md
vendored
29
.github/ISSUE_TEMPLATE/new_model.md
vendored
@ -77,16 +77,17 @@ Describe in detail the following:
|
|||||||
### 🧪 Tests
|
### 🧪 Tests
|
||||||
|
|
||||||
- Unit Tests
|
- Unit Tests
|
||||||
|
- [ ] API Render (fields)
|
||||||
- [ ] [Model](https://nofusscomputing.com/projects/centurion_erp/development/models/#tests)
|
- [ ] [Model](https://nofusscomputing.com/projects/centurion_erp/development/models/#tests)
|
||||||
- [ ] Serializer
|
|
||||||
- [ ] ViewSet
|
- [ ] ViewSet
|
||||||
- Function Test
|
- Function Test
|
||||||
- [ ] ViewSet
|
- [ ] History API Render (fields)
|
||||||
|
- [ ] History Entries
|
||||||
- [ ] API Metadata
|
- [ ] API Metadata
|
||||||
- [ ] API Permissions
|
- [ ] API Permissions
|
||||||
- [ ] API Render (fields)
|
- [ ] Model
|
||||||
- [ ] History Entries
|
- [ ] Serializer
|
||||||
- [ ] History API Render (fields)
|
- [ ] ViewSet
|
||||||
|
|
||||||
|
|
||||||
## ✅ Requirements
|
## ✅ Requirements
|
||||||
@ -95,6 +96,24 @@ A Requirement is a must have. In addition will also be tested.
|
|||||||
|
|
||||||
- [ ] Must have a [model_tag](https://nofusscomputing.com/projects/centurion_erp/user/core/markdown/#model-reference)
|
- [ ] Must have a [model_tag](https://nofusscomputing.com/projects/centurion_erp/user/core/markdown/#model-reference)
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
When detailing requirements the following must be taken into account:
|
||||||
|
|
||||||
|
- what the user should be able to do
|
||||||
|
|
||||||
|
- what the user should not be able to do
|
||||||
|
|
||||||
|
- what should occur when a user performs an action
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
- Functional Requirements
|
||||||
|
|
||||||
|
|
||||||
|
- Non-Functional Requirements
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!-- Add additional requirement here and as a check box list -->
|
<!-- Add additional requirement here and as a check box list -->
|
||||||
|
@ -241,6 +241,7 @@ class TicketBaseSerializerTestCases:
|
|||||||
)
|
)
|
||||||
|
|
||||||
request.cls.valid_data.update({
|
request.cls.valid_data.update({
|
||||||
|
'organization': request.cls.organization,
|
||||||
'category': TicketCategory.objects.create(
|
'category': TicketCategory.objects.create(
|
||||||
organization = request.cls.organization,
|
organization = request.cls.organization,
|
||||||
name = 'a category'
|
name = 'a category'
|
||||||
@ -262,10 +263,28 @@ class TicketBaseSerializerTestCases:
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
project_two = Project.objects.create(
|
||||||
|
organization = request.cls.organization,
|
||||||
|
name = 'project_two'
|
||||||
|
)
|
||||||
|
|
||||||
|
request.cls.project_milestone_two = ProjectMilestone.objects.create(
|
||||||
|
organization = request.cls.organization,
|
||||||
|
name = 'project milestone two',
|
||||||
|
project = project_two
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
with django_db_blocker.unblock():
|
with django_db_blocker.unblock():
|
||||||
|
|
||||||
|
request.cls.project_milestone_two.delete()
|
||||||
|
|
||||||
|
project_two.delete()
|
||||||
|
|
||||||
request.cls.entity_user.delete()
|
request.cls.entity_user.delete()
|
||||||
|
|
||||||
parent_ticket.delete()
|
parent_ticket.delete()
|
||||||
@ -335,6 +354,70 @@ class TicketBaseSerializerTestCases:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_serializer_valid_data_milestone_from_different_project_not_valid(self, fake_view, create_serializer):
|
||||||
|
"""Serializer Validation Check
|
||||||
|
|
||||||
|
Ensure that when creating an object with valid data, no validation
|
||||||
|
error occurs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
valid_data = self.valid_data.copy()
|
||||||
|
|
||||||
|
valid_data['milestone'] = self.project_milestone_two.id
|
||||||
|
|
||||||
|
view_set = fake_view(
|
||||||
|
user = self.view_user,
|
||||||
|
_has_import = True,
|
||||||
|
_has_triage = True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
serializer = create_serializer(
|
||||||
|
context = {
|
||||||
|
'request': view_set.request,
|
||||||
|
'view': view_set,
|
||||||
|
},
|
||||||
|
data = valid_data
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not serializer.is_valid(raise_exception = False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_serializer_valid_data_milestone_from_different_project_raises_exception(self, fake_view, create_serializer):
|
||||||
|
"""Serializer Validation Check
|
||||||
|
|
||||||
|
Ensure that when creating an object with valid data, no validation
|
||||||
|
error occurs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
valid_data = self.valid_data.copy()
|
||||||
|
|
||||||
|
valid_data['milestone'] = self.project_milestone_two.id
|
||||||
|
|
||||||
|
view_set = fake_view(
|
||||||
|
user = self.view_user,
|
||||||
|
_has_import = True,
|
||||||
|
_has_triage = True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
with pytest.raises(ValidationError) as err:
|
||||||
|
|
||||||
|
serializer = create_serializer(
|
||||||
|
context = {
|
||||||
|
'request': view_set.request,
|
||||||
|
'view': view_set,
|
||||||
|
},
|
||||||
|
data = valid_data
|
||||||
|
)
|
||||||
|
|
||||||
|
serializer.is_valid(raise_exception = True)
|
||||||
|
|
||||||
|
assert err.value.get_codes()['milestone'][0] == 'milestone_same_project'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_serializer_valid_data_missing_field_raises_exception(self, fake_view, parameterized, param_key_test_data,
|
def test_serializer_valid_data_missing_field_raises_exception(self, fake_view, parameterized, param_key_test_data,
|
||||||
create_serializer,
|
create_serializer,
|
||||||
param_value,
|
param_value,
|
||||||
|
Reference in New Issue
Block a user