Skip to content

Commit

Permalink
fix: modifify facility_system model
Browse files Browse the repository at this point in the history
  • Loading branch information
saladgg committed Sep 15, 2021
1 parent 659e71b commit 371e046
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 73 deletions.
4 changes: 2 additions & 2 deletions fahari/common/migrations/0021_auto_20210911_1724.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='system',
name='pattern',
field=models.CharField(choices=[('poc', 'Point of Care'), ('rde', 'Retrospective Data Entry'), ('hybrid', 'Hybrid'), ('none', 'None')], default='none', max_length=10),
field=models.CharField(choices=[('poc', 'Point of Care'), ('rde', 'Retrospective Data Entry'), ('hybrid', 'Hybrid'), ('none', 'None')], default='none', max_length=100),
),
migrations.CreateModel(
name='UserFacilityAllotment',
Expand All @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
('created_by', models.UUIDField(blank=True, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
('updated_by', models.UUIDField(blank=True, null=True)),
('allotment_type', models.CharField(choices=[('facility', 'By Facility'), ('region', 'By Region'), ('both', 'By Both Facility and Region')], max_length=10)),
('allotment_type', models.CharField(choices=[('facility', 'By Facility'), ('region', 'By Region'), ('both', 'By Both Facility and Region')], max_length=100)),
('region_type', models.CharField(blank=True, choices=[('county', 'County'), ('constituency', 'Constituency'), ('sub_county', 'Sub County'), ('ward', 'Ward')], max_length=20, null=True)),
('counties', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, choices=[('Nairobi', 'Nairobi'), ('Kajiado', 'Kajiado')], max_length=150, null=True), blank=True, help_text='All the facilities in the selected counties will be allocated to the selected user.', null=True, size=None)),
('constituencies', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, choices=[('Dagoretti North', 'Dagoretti North'), ('Dagoretti South', 'Dagoretti South'), ('Embakasi Central', 'Embakasi Central'), ('Embakasi East', 'Embakasi East'), ('Embakasi North', 'Embakasi North'), ('Embakasi South', 'Embakasi South'), ('Embakasi West', 'Embakasi West'), ('Kajiado Central', 'Kajiado Central'), ('Kajiado East', 'Kajiado East'), ('Kajiado North', 'Kajiado North'), ('Kajiado West', 'Kajiado West'), ('Kamukunji', 'Kamukunji'), ('Kasarani', 'Kasarani'), ('Kibra', 'Kibra'), ('Langata', 'Langata'), ('Magadi', 'Magadi'), ('Makadara', 'Makadara'), ('Mathare', 'Mathare'), ('Roysambu', 'Roysambu'), ('Ruaraka', 'Ruaraka'), ('Starehe', 'Starehe'), ('Westlands', 'Westlands')], max_length=150, null=True), blank=True, help_text='All the facilities in the selected constituencies will be allocated to the selected user.', null=True, size=None)),
Expand Down
23 changes: 23 additions & 0 deletions fahari/common/migrations/0023_auto_20210914_1639.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.7 on 2021-09-14 13:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0022_auto_20210914_1403'),
]

operations = [
migrations.AlterField(
model_name='system',
name='pattern',
field=models.CharField(choices=[('poc', 'Point of Care'), ('rde', 'Retrospective Data Entry'), ('hybrid', 'Hybrid'), ('none', 'None')], default='none', max_length=100),
),
migrations.AlterField(
model_name='userfacilityallotment',
name='allotment_type',
field=models.CharField(choices=[('facility', 'By Facility'), ('region', 'By Region'), ('both', 'By Both Facility and Region')], max_length=100),
),
]
4 changes: 2 additions & 2 deletions fahari/common/models/common_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class SystemPatters(models.TextChoices):

name = models.CharField(max_length=128, null=False, blank=False, unique=True)
pattern = models.CharField(
max_length=10, choices=SystemPatters.choices, default=SystemPatters.NONE.value
max_length=100, choices=SystemPatters.choices, default=SystemPatters.NONE.value
)
description = models.TextField()

Expand Down Expand Up @@ -317,7 +317,7 @@ class RegionType(models.TextChoices):
WARD = "ward"

user = models.OneToOneField(User, on_delete=models.PROTECT)
allotment_type = models.CharField(max_length=10, choices=AllotmentType.choices)
allotment_type = models.CharField(max_length=100, choices=AllotmentType.choices)
region_type = models.CharField(
max_length=20, choices=RegionType.choices, null=True, blank=True
)
Expand Down
22 changes: 20 additions & 2 deletions fahari/common/tests/test_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import random

import pytest
from django.contrib.auth import get_user_model
from django.utils import timezone
from faker.proxy import Faker
from model_bakery import baker

from fahari.common.constants import WHITELIST_COUNTIES
Expand All @@ -12,13 +14,16 @@
get_appointments_mtd,
get_open_ticket_count,
)
from fahari.common.models import Facility
from fahari.ops.models import DailyUpdate, FacilitySystemTicket
from fahari.common.models import Facility, Organisation
from fahari.common.models.common_models import System
from fahari.ops.models import DailyUpdate, FacilitySystem, FacilitySystemTicket

User = get_user_model()

pytestmark = pytest.mark.django_db

fake = Faker()


def test_get_active_facility_count(user):
baker.make(
Expand All @@ -33,8 +38,21 @@ def test_get_active_facility_count(user):


def test_get_open_ticket_count(user):
org = baker.make(Organisation)
facility = baker.make(Facility, organisation=org, name="Test")
system = baker.make(System, organisation=org, name="System")
vrs = "0.0.1"
facility_system = baker.make(
FacilitySystem,
facility=facility,
system=system,
version=vrs,
organisation=org,
trainees=json.dumps([fake.name(), fake.name()]),
)
baker.make(
FacilitySystemTicket,
facility_system=facility_system,
resolved=None,
active=True,
organisation=user.organisation,
Expand Down
5 changes: 4 additions & 1 deletion fahari/ops/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class FacilitySystemFilter(CommonFieldsFilterset):
class Meta:

model = FacilitySystem
fields = "__all__"
exclude = (
"attachment",
"trainees",
)


class FacilitySystemTicketFilter(CommonFieldsFilterset):
Expand Down
29 changes: 29 additions & 0 deletions fahari/ops/migrations/0026_auto_20210914_1059.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.7 on 2021-09-14 07:59

from django.db import migrations, models
import fahari.common.models


class Migration(migrations.Migration):

dependencies = [
('ops', '0025_securityincidence'),
]

operations = [
migrations.AddField(
model_name='facilitysystem',
name='attachment',
field=models.FileField(blank=True, null=True, upload_to=fahari.common.models.get_directory, verbose_name='Attach File or Photo'),
),
migrations.AddField(
model_name='facilitysystem',
name='release_notes',
field=models.TextField(default='-'),
),
migrations.AddField(
model_name='facilitysystem',
name='trainees',
field=models.TextField(default='-'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.2.7 on 2021-09-14 13:03

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ops', '0026_auto_20210914_1059'),
('ops', '0026_auto_20210914_1403'),
]

operations = [
]
19 changes: 19 additions & 0 deletions fahari/ops/migrations/0028_alter_facilitysystem_trainees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.7 on 2021-09-14 13:04

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ops', '0027_merge_0026_auto_20210914_1059_0026_auto_20210914_1403'),
]

operations = [
migrations.AlterField(
model_name='facilitysystem',
name='trainees',
field=django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), help_text='Use commas to separate trainees names', size=None),
),
]
8 changes: 8 additions & 0 deletions fahari/ops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class FacilitySystem(AbstractBase):
facility = models.ForeignKey(Facility, on_delete=models.PROTECT)
system = models.ForeignKey(System, on_delete=models.PROTECT)
version = models.CharField(max_length=64)
release_notes = models.TextField(default="-")
trainees = ArrayField(
models.TextField(),
help_text="Use commas to separate trainees names",
)
attachment = models.FileField(
upload_to=get_directory, verbose_name="Attach File or Photo", null=True, blank=True
)

def get_absolute_url(self):
update_url = reverse_lazy("ops:version_update", kwargs={"pk": self.pk})
Expand Down
1 change: 1 addition & 0 deletions fahari/ops/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FacilitySystemSerializer(BaseSerializer):

facility_name = serializers.ReadOnlyField()
system_name = serializers.ReadOnlyField()
updated = serializers.DateTimeField(format="%d/%m/%Y", required=False)

class Meta(BaseSerializer.Meta):
model = FacilitySystem
Expand Down
28 changes: 25 additions & 3 deletions fahari/ops/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_create(self):
"system": self.system.pk,
"version": fake.name()[:63],
"organisation": self.global_organisation.pk,
"trainees": json.dumps([fake.name(), fake.name()]),
}
response = self.client.post(self.url_list, data)
assert response.status_code == 201, response.json()
Expand All @@ -59,6 +60,7 @@ def test_retrieve(self):
instance = baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
response = self.client.get(self.url_list)
assert response.status_code == 200, response.json()
Expand All @@ -71,6 +73,7 @@ def test_patch_system(self):
instance = baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
edit = {"version": fake.name()[:63]}
url = reverse("api:facilitysystem-detail", kwargs={"pk": instance.pk})
Expand All @@ -83,12 +86,14 @@ def test_put_system(self):
instance = baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
data = {
"facility": self.facility.pk,
"system": self.system.pk,
"version": fake.name()[:63],
"organisation": self.global_organisation.pk,
"trainees": f"{fake.name()},{fake.name()}",
}
url = reverse("api:facilitysystem-detail", kwargs={"pk": instance.pk})
response = self.client.put(url, data)
Expand All @@ -111,7 +116,11 @@ def setUp(self):
super().setUp()

def test_facilitysystem_form_init(self):
baker.make(FacilitySystem, organisation=self.global_organisation)
baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
form = FacilitySystemTicketForm()
queryset = form.fields["facility_system"].queryset
assert FacilitySystem.objects.count() > 0
Expand All @@ -123,6 +132,9 @@ def test_create(self):
"system": self.system.pk,
"version": fake.name()[:63],
"organisation": self.global_organisation.pk,
"release_notes": fake.text(),
"trainees": json.dumps([fake.name(), fake.name()]),
"attachment": fake.file_name(),
}
response = self.client.post(reverse("ops:version_create"), data=data)
self.assertEqual(
Expand All @@ -134,13 +146,17 @@ def test_update(self):
instance = baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
data = {
"pk": instance.pk,
"facility": self.facility.pk,
"organisation": self.global_organisation.pk,
"system": self.system.pk,
"version": fake.name()[:63],
"organisation": self.global_organisation.pk,
"release_notes": fake.text(),
"trainees": f"{fake.name()},{fake.name()}",
"attachment": fake.file_name(),
}
response = self.client.post(
reverse("ops:version_update", kwargs={"pk": instance.pk}), data=data
Expand All @@ -154,6 +170,7 @@ def test_delete(self):
instance = baker.make(
FacilitySystem,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
response = self.client.post(
reverse("ops:version_delete", kwargs={"pk": instance.pk}),
Expand All @@ -174,6 +191,7 @@ def setUp(self):
facility=self.facility,
system=self.system,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
super().setUp()

Expand Down Expand Up @@ -254,16 +272,20 @@ def setUp(self):
facility=self.facility,
system=self.system,
organisation=self.global_organisation,
trainees=json.dumps([fake.name(), fake.name()]),
)
super().setUp()

def test_create(self):
data = {
"facility_system": self.facility_system.pk,
"organisation": self.global_organisation.pk,
"details": fake.text(),
"raised": timezone.now().isoformat(),
"raised_by": fake.name(),
"organisation": self.global_organisation.pk,
"resolved": timezone.now().isoformat(),
"resolved_by": fake.name(),
"resolved_note": fake.text(),
}
response = self.client.post(reverse("ops:ticket_create"), data=data)
self.assertEqual(
Expand Down
Loading

0 comments on commit 371e046

Please sign in to comment.