From ec290b905456b52d67eee108bf1b1c22d5d8605e Mon Sep 17 00:00:00 2001 From: mikeymanoguerra Date: Mon, 25 Jan 2021 17:33:38 -0500 Subject: [PATCH] clear migrations, remove unused appointment model, add more tests --- core/management/commands/users_and_groups.py | 9 ---- core/migrations/0001_initial.py | 50 ++++++++++++------- core/migrations/0002_participant_sep_id.py | 18 ------- core/migrations/0003_sites.py | 24 --------- core/migrations/0004_sep_data.py | 26 ---------- core/migrations/0005_auto_20200929_1248.py | 35 ------------- .../0006_participant_maiden_name.py | 18 ------- core/migrations/0007_auto_20201014_1626.py | 23 --------- core/migrations/0008_auto_20201020_1008.py | 21 -------- core/migrations/0009_auto_20201020_1017.py | 17 ------- core/migrations/0010_auto_20201204_2107.py | 24 --------- core/migrations/0011_program_has_queue.py | 18 ------- core/migrations/0012_auto_20201216_0954.py | 18 ------- core/migrations/0013_auto_20210124_2349.py | 18 ------- core/migrations/0013_sepdata_exchanged_for.py | 18 ------- core/models/__init__.py | 1 - core/models/appointment.py | 11 ---- core/tests/services.py | 36 ++++++++++--- 18 files changed, 61 insertions(+), 324 deletions(-) delete mode 100644 core/migrations/0002_participant_sep_id.py delete mode 100644 core/migrations/0003_sites.py delete mode 100644 core/migrations/0004_sep_data.py delete mode 100644 core/migrations/0005_auto_20200929_1248.py delete mode 100644 core/migrations/0006_participant_maiden_name.py delete mode 100644 core/migrations/0007_auto_20201014_1626.py delete mode 100644 core/migrations/0008_auto_20201020_1008.py delete mode 100644 core/migrations/0009_auto_20201020_1017.py delete mode 100644 core/migrations/0010_auto_20201204_2107.py delete mode 100644 core/migrations/0011_program_has_queue.py delete mode 100644 core/migrations/0012_auto_20201216_0954.py delete mode 100644 core/migrations/0013_auto_20210124_2349.py delete mode 100644 core/migrations/0013_sepdata_exchanged_for.py delete mode 100644 core/models/appointment.py diff --git a/core/management/commands/users_and_groups.py b/core/management/commands/users_and_groups.py index 5da782da..9b47bd40 100644 --- a/core/management/commands/users_and_groups.py +++ b/core/management/commands/users_and_groups.py @@ -26,9 +26,6 @@ "add_medication", "change_medication", "view_medication", - "add_appointment", - "change_appointment", - "view_appointment", "add_casemanagement", "change_casemanagement", "view_casemanagement", @@ -65,9 +62,6 @@ "view_service", "add_visit", "change_visit", - "add_appointment", - "change_appointment", - "view_appointment", "add_frontdeskevent", "change_frontdeskevent", "view_frontdeskevent", @@ -87,9 +81,6 @@ "view_service", "change_visit", "view_visit", - "add_appointment", - "change_appointment", - "view_appointment", "add_frontdeskevent", "change_frontdeskevent", "view_frontdeskevent", diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py index e22d6098..79d4258f 100644 --- a/core/migrations/0001_initial.py +++ b/core/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.13 on 2020-08-16 23:37 +# Generated by Django 2.2.13 on 2021-01-25 22:06 from django.db import migrations, models import django.db.models.deletion @@ -45,7 +45,9 @@ class Migration(migrations.Migration): ('date_of_birth', models.DateField()), ('start_date', models.DateField()), ('is_insured', models.BooleanField(default=False)), - ('insurer', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Insurer')), + ('maiden_name', models.CharField(blank=True, max_length=100, null=True, verbose_name="Mother's Maiden Name")), + ('sep_id', models.IntegerField(null=True, unique=True)), + ('insurer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Insurer')), ], ), migrations.CreateModel( @@ -55,6 +57,7 @@ class Migration(migrations.Migration): ('name', models.CharField(max_length=100)), ('is_closed', models.BooleanField(default=False)), ('is_frozen', models.BooleanField(default=False)), + ('has_queue', models.BooleanField(default=True)), ], ), migrations.CreateModel( @@ -63,8 +66,20 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=100)), ('available', models.BooleanField(default=False)), + ('slug', models.CharField(max_length=100, unique=True, verbose_name='Concise Descriptive Identifier')), ('program', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='services', to='core.Program')), - ('slug', models.CharField(max_length=100, unique=True)), + ], + ), + migrations.CreateModel( + name='Site', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('site_name', models.CharField(max_length=100)), + ('site_type', models.CharField(max_length=100)), + ('description', models.CharField(max_length=100)), + ('address', models.CharField(max_length=1000, null=True)), + ('zip_code', models.CharField(max_length=10, null=True)), + ('created_at', models.DateTimeField(default=django.utils.timezone.now)), ], ), migrations.CreateModel( @@ -102,6 +117,18 @@ class Migration(migrations.Migration): ('visit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Visit')), ], ), + migrations.CreateModel( + name='SepData', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(default=django.utils.timezone.now)), + ('needles_in', models.IntegerField()), + ('needles_out', models.IntegerField()), + ('exchanged_for', models.IntegerField(default=None, null=True)), + ('site', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Site')), + ('visit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Visit')), + ], + ), migrations.CreateModel( name='Question', fields=[ @@ -143,7 +170,7 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='HCVNotes', + name='HCVNote', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('note_timestamp', models.DateTimeField()), @@ -174,7 +201,7 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name='BehavioralHealthNotes', + name='BehavioralHealthNote', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('note_timestamp', models.DateTimeField()), @@ -182,17 +209,4 @@ class Migration(migrations.Migration): ('visit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Visit')), ], ), - migrations.CreateModel( - name='Appointment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('appointment_timestamp', models.DateTimeField()), - ('crs_timestamp', models.DateTimeField()), - ('crs_seen', models.BooleanField(default=False)), - ('cm_timestamp', models.DateTimeField()), - ('cm_seen', models.BooleanField(default=False)), - ('hcv_status', models.BooleanField(default=False)), - ('participant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Participant')), - ], - ), ] diff --git a/core/migrations/0002_participant_sep_id.py b/core/migrations/0002_participant_sep_id.py deleted file mode 100644 index 81250095..00000000 --- a/core/migrations/0002_participant_sep_id.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2020-08-30 16:15 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='participant', - name='sep_id', - field=models.IntegerField(null=True, unique=True), - ), - ] diff --git a/core/migrations/0003_sites.py b/core/migrations/0003_sites.py deleted file mode 100644 index 23accb98..00000000 --- a/core/migrations/0003_sites.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 2.2.13 on 2020-09-21 02:47 - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0002_participant_sep_id'), - ] - - operations = [ - migrations.CreateModel( - name='Sites', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('site_name', models.CharField(max_length=100)), - ('site_address', models.CharField(max_length=1000)), - ('site_zip', models.CharField(max_length=10)), - ('created_date', models.DateTimeField(default=django.utils.timezone.now)), - ], - ), - ] diff --git a/core/migrations/0004_sep_data.py b/core/migrations/0004_sep_data.py deleted file mode 100644 index bfd8fd02..00000000 --- a/core/migrations/0004_sep_data.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 2.2.13 on 2020-09-23 13:34 - -from django.db import migrations, models -import django.db.models.deletion -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0003_sites'), - ] - - operations = [ - migrations.CreateModel( - name='Sep_Data', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created_at', models.DateTimeField(default=django.utils.timezone.now)), - ('needles_in', models.IntegerField()), - ('needles_out', models.IntegerField()), - ('site', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Sites')), - ('visit', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Visit')), - ], - ), - ] diff --git a/core/migrations/0005_auto_20200929_1248.py b/core/migrations/0005_auto_20200929_1248.py deleted file mode 100644 index 29579536..00000000 --- a/core/migrations/0005_auto_20200929_1248.py +++ /dev/null @@ -1,35 +0,0 @@ -# Generated by Django 2.2.13 on 2020-09-29 16:48 - -from django.db import migrations, models -import django.db.models.deletion -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0004_sep_data'), - ] - - operations = [ - migrations.CreateModel( - name='Site', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('site_name', models.CharField(max_length=100)), - ('site_type', models.CharField(max_length=100)), - ('description', models.CharField(max_length=100)), - ('address', models.CharField(max_length=1000)), - ('zip_code', models.CharField(max_length=10)), - ('created_at', models.DateTimeField(default=django.utils.timezone.now)), - ], - ), - migrations.AlterField( - model_name='sep_data', - name='site', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Site'), - ), - migrations.DeleteModel( - name='Sites', - ), - ] diff --git a/core/migrations/0006_participant_maiden_name.py b/core/migrations/0006_participant_maiden_name.py deleted file mode 100644 index 6ddb246d..00000000 --- a/core/migrations/0006_participant_maiden_name.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2020-10-03 14:40 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0005_auto_20200929_1248'), - ] - - operations = [ - migrations.AddField( - model_name='participant', - name='maiden_name', - field=models.CharField(max_length=100, null=True, verbose_name="Mother's Maiden Name"), - ), - ] diff --git a/core/migrations/0007_auto_20201014_1626.py b/core/migrations/0007_auto_20201014_1626.py deleted file mode 100644 index c3b2e0f6..00000000 --- a/core/migrations/0007_auto_20201014_1626.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.2.13 on 2020-10-14 20:26 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0006_participant_maiden_name'), - ] - - operations = [ - migrations.AlterField( - model_name='site', - name='address', - field=models.CharField(max_length=1000, null=True), - ), - migrations.AlterField( - model_name='site', - name='zip_code', - field=models.CharField(max_length=10, null=True), - ), - ] diff --git a/core/migrations/0008_auto_20201020_1008.py b/core/migrations/0008_auto_20201020_1008.py deleted file mode 100644 index 1e18e8e7..00000000 --- a/core/migrations/0008_auto_20201020_1008.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.2.13 on 2020-10-20 14:08 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0007_auto_20201014_1626'), - ] - - operations = [ - migrations.RenameModel( - old_name='BehavioralHealthNotes', - new_name='BehavioralHealthNote', - ), - migrations.RenameModel( - old_name='HCVNotes', - new_name='HCVNote', - ), - ] diff --git a/core/migrations/0009_auto_20201020_1017.py b/core/migrations/0009_auto_20201020_1017.py deleted file mode 100644 index eadf4f49..00000000 --- a/core/migrations/0009_auto_20201020_1017.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.2.13 on 2020-10-20 14:17 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0008_auto_20201020_1008'), - ] - - operations = [ - migrations.RenameModel( - old_name='Sep_Data', - new_name='SepData', - ), - ] diff --git a/core/migrations/0010_auto_20201204_2107.py b/core/migrations/0010_auto_20201204_2107.py deleted file mode 100644 index 95fca123..00000000 --- a/core/migrations/0010_auto_20201204_2107.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 2.2.13 on 2020-12-05 02:07 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0009_auto_20201020_1017'), - ] - - operations = [ - migrations.AlterField( - model_name='participant', - name='insurer', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Insurer'), - ), - migrations.AlterField( - model_name='participant', - name='maiden_name', - field=models.CharField(blank=True, max_length=100, null=True, verbose_name="Mother's Maiden Name"), - ), - ] diff --git a/core/migrations/0011_program_has_queue.py b/core/migrations/0011_program_has_queue.py deleted file mode 100644 index 9b9a0a3f..00000000 --- a/core/migrations/0011_program_has_queue.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2020-12-06 00:33 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0010_auto_20201204_2107'), - ] - - operations = [ - migrations.AddField( - model_name='program', - name='has_queue', - field=models.BooleanField(default=False), - ), - ] diff --git a/core/migrations/0012_auto_20201216_0954.py b/core/migrations/0012_auto_20201216_0954.py deleted file mode 100644 index 949c6e73..00000000 --- a/core/migrations/0012_auto_20201216_0954.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2020-12-16 14:54 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0011_program_has_queue'), - ] - - operations = [ - migrations.AlterField( - model_name='program', - name='has_queue', - field=models.BooleanField(default=True), - ), - ] diff --git a/core/migrations/0013_auto_20210124_2349.py b/core/migrations/0013_auto_20210124_2349.py deleted file mode 100644 index 32a9a645..00000000 --- a/core/migrations/0013_auto_20210124_2349.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2021-01-25 04:49 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0012_auto_20201216_0954'), - ] - - operations = [ - migrations.AlterField( - model_name='service', - name='slug', - field=models.CharField(max_length=100, unique=True, verbose_name='Concise Descriptive Identifier'), - ), - ] diff --git a/core/migrations/0013_sepdata_exchanged_for.py b/core/migrations/0013_sepdata_exchanged_for.py deleted file mode 100644 index 14857307..00000000 --- a/core/migrations/0013_sepdata_exchanged_for.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 2.2.13 on 2021-01-22 20:45 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0012_auto_20201216_0954'), - ] - - operations = [ - migrations.AddField( - model_name='sepdata', - name='exchanged_for', - field=models.IntegerField(default=None, null=True), - ), - ] diff --git a/core/models/__init__.py b/core/models/__init__.py index b9ad8810..97fb08de 100644 --- a/core/models/__init__.py +++ b/core/models/__init__.py @@ -5,7 +5,6 @@ from .visit import * from .hcv_note import * from .medication import * -from .appointment import * from .case_management import * from .front_desk_event import * from .urine_drug_screen import * diff --git a/core/models/appointment.py b/core/models/appointment.py deleted file mode 100644 index bc11870a..00000000 --- a/core/models/appointment.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.db import models -from core.models import Participant - -class Appointment(models.Model): - participant = models.ForeignKey(Participant, on_delete=models.CASCADE) - appointment_timestamp = models.DateTimeField() - crs_timestamp = models.DateTimeField() - crs_seen = models.BooleanField(default=False) - cm_timestamp = models.DateTimeField() - cm_seen = models.BooleanField(default=False) - hcv_status = models.BooleanField(default=False) diff --git a/core/tests/services.py b/core/tests/services.py index 7f2d154d..5b3c5d82 100644 --- a/core/tests/services.py +++ b/core/tests/services.py @@ -1,11 +1,11 @@ +import json +import random from django.forms.models import model_to_dict from core.tests.base import BaseTestCase from django.core.exceptions import ValidationError from django.core.management import call_command from core.models import Service, Program from rest_framework import status -import random -import json def get_random_service(): @@ -43,7 +43,7 @@ def test_update_availability(self): json.dumps(random_service), content_type="application/json", follow=True, - **headers + **headers, ) updated_availabilty = Service.objects.get(pk=random_service["id"]).available @@ -65,7 +65,7 @@ def test_disallow_service_name_change(self): json.dumps(random_service), content_type="application/json", follow=True, - **headers + **headers, ) unchanged_name = Service.objects.get(pk=random_service["id"]).name # returns a 200 status, but field is unchanged @@ -80,6 +80,7 @@ def test_service_has_slug_field(self): route = "/api/services/{}/".format(random_service["id"]) res = self.client.get(route, follow=True, **headers) content = json.loads(res.content) + self.assertTrue("slug" in content) self.assertTrue(content["slug"], random_service["slug"]) @@ -90,7 +91,7 @@ def test_disallow_slug_change(self): headers = self.auth_headers_for_user("admin") random_service = get_random_service() service_slug = random_service["slug"] - random_service["name"] = "a fake slug" + random_service["slug"] = "a fake slug" route = "/api/services/{}/".format(random_service["id"]) self.client.put( @@ -98,9 +99,9 @@ def test_disallow_slug_change(self): json.dumps(random_service), content_type="application/json", follow=True, - **headers + **headers, ) - unchanged_slug = Service.objects.get(pk=random_service["id"]).name + unchanged_slug = Service.objects.get(pk=random_service["id"]).slug # returns a 200 status, but field is unchanged self.assertEqual(service_slug, unchanged_slug) @@ -130,4 +131,25 @@ def test_slug_normalization(self): slug = " $%^$# 543 Sligh Bannaga *&^%*& " program = Program.objects.all().first() service = Service.objects.create(name="some name", slug=slug, program=program) + self.assertRegex(service.slug, r"[a-z0-9\-]") + + def test_slug_query(self): + headers = self.auth_headers_for_user("admin") + random_service = get_random_service() + service_slug = random_service["slug"] + + route = f"/api/services/?slug={service_slug}" + res = self.client.get(route, follow=True, **headers) + content = json.loads(res.content) + + self.assertEqual(len(content), 1) + self.assertEqual(content[0]['id'], random_service['id']) + + def test_slug_query_404(self): + headers = self.auth_headers_for_user("admin") + + route = f"/api/services/?slug=a-fake-ol-slug" + res = self.client.get(route, follow=True, **headers) + + self.assertEqual(res.status_code, status.HTTP_404_NOT_FOUND)