diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-31 10:41:53 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-31 10:41:53 +0100 |
commit | 9917bd1793d0362b84704d0ad4409be4ec9dbdd3 (patch) | |
tree | aa79d250353e148067eb7e4bd72ae32116c7b0d7 | |
parent | 2adf4f28ec512b654a4802e274ad683d6c670fc5 (diff) | |
parent | 10579be5293908b57336ecd769b8e17a610e008a (diff) |
Merge branch 'incident-report-form' of github.com:hammerheadlemon/ctrack into incident-report-form
-rw-r--r-- | ctrack/organisations/tests/factories.py | 10 | ||||
-rw-r--r-- | ctrack/organisations/tests/incident_report.json | 25 | ||||
-rw-r--r-- | ctrack/organisations/tests/test_factories.py | 14 | ||||
-rw-r--r-- | ctrack/users/tests/test_credentials.py | 30 |
4 files changed, 60 insertions, 19 deletions
diff --git a/ctrack/organisations/tests/factories.py b/ctrack/organisations/tests/factories.py index ba2655e..a0b700d 100644 --- a/ctrack/organisations/tests/factories.py +++ b/ctrack/organisations/tests/factories.py @@ -32,16 +32,6 @@ def _random_submode(): return sms[random.randint(0, len(sms) - 1)] -class UserFactory(DjangoModelFactory): - # Better to create this using example in ctrack.users.tests.factories. - # Handles password generation correctly. - class Meta: - model = User - - username = Faker("lexify", text="???????", letters="abcdsgTGQA") - password = Faker("lexify", text="????????", letters="AdOIqkcvBnMP") - - class OrganisationFactory(DjangoModelFactory): class Meta: model = Organisation diff --git a/ctrack/organisations/tests/incident_report.json b/ctrack/organisations/tests/incident_report.json new file mode 100644 index 0000000..2b03d48 --- /dev/null +++ b/ctrack/organisations/tests/incident_report.json @@ -0,0 +1,25 @@ +[ +{ + "model": "organisations.incidentreport", + "pk": 1, + "fields": { + "organisation": 15, + "reporting_person": 15, + "person_involved": "Robin Cousins", + "role": "Team Ice Skater", + "phone_number": "08929 390 30943", + "email": "a@example.com", + "internal_incident_number": "092T", + "date_time_incident_detected": "2020-05-28T00:00:00Z", + "date_time_incident_reported": "2020-05-30T15:21:52.171Z", + "incident_type": "Cyber", + "incident_status": "Detected", + "incident_stage": "Ongoing", + "summary": "We were woken to 10am by the crying of children. A school bus had tipped over on the dual carriageway outside the HQ and several of the occupants had spilled out on to the verge and we somewhat distraight. It appeared that the automatic road stinger had activated outside our main gatehouse (we use this to stop people leaving who have not paid for the photocopying that day).", + "mitigations": "We have been able to remove the wires that attach the ejector module to the power unit, but we don't know how to do anything else. The maintenance engineer is in Tenerife and not answering his phone.", + "others_informed": "The local convent school St Mirium Collete of the Roasted Saint. They sent their societial liaison officer to take pictures of the scene for their Tinder account.", + "next_steps": "Once we get hold of someone how knows how to fix the system, we intend to make sure there is an adequate response, but at the moment, this simply isn't possible. Sorry!", + "dft_handle_status": "QUEUED" + } +} +] diff --git a/ctrack/organisations/tests/test_factories.py b/ctrack/organisations/tests/test_factories.py index 9c0d575..227d7db 100644 --- a/ctrack/organisations/tests/test_factories.py +++ b/ctrack/organisations/tests/test_factories.py @@ -1,12 +1,8 @@ -from ctrack.organisations.tests.factories import OrganisationFactory -from ctrack.organisations.tests.factories import PersonFactory -from ctrack.organisations.tests.factories import RoleFactory -from ctrack.organisations.tests.factories import UserFactory - - -def test_user_factory(): - u = UserFactory.build() - assert u.username +from ctrack.organisations.tests.factories import ( + OrganisationFactory, + PersonFactory, + RoleFactory, +) def test_organisation_factory(): diff --git a/ctrack/users/tests/test_credentials.py b/ctrack/users/tests/test_credentials.py new file mode 100644 index 0000000..7538643 --- /dev/null +++ b/ctrack/users/tests/test_credentials.py @@ -0,0 +1,30 @@ +""" +THIS TEST IS FROM REALPYTHON ARTICLE +https://realpython.com/django-pytest-fixtures/ + +The permissions here are not optimal for this project yet. +TODO - make them so! +""" +import pytest +from django.contrib.auth import get_user_model +from django.contrib.auth.models import Group, Permission + + +@pytest.fixture +def user_A(db) -> Group: + group = Group.objects.create(name="cct_user") + change_user_permissions = Permission.objects.filter( + codename__in=["change_user", "view_user"], + ) + group.permissions.add(*change_user_permissions) + user = get_user_model().objects.create_user("A") + user.groups.add(group) + return user + + +def test_should_create_user(user_A: get_user_model()) -> None: + assert user_A.username == "A" + + +def test_user_is_in_app_user_group(user_A: get_user_model()) -> None: + assert user_A.groups.filter(name="cct_user").exists() |