-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add /openapi (OAS schema) and schema docs (#17)
This will make the REST API self describing
- Loading branch information
1 parent
550d3b6
commit 1b7e0bf
Showing
12 changed files
with
275 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 3.2.9 on 2021-11-09 06:22 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('clients', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='client', | ||
name='enrollment_date', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='clientfacility', | ||
name='assigned', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='identifier', | ||
name='valid_from', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='securityquestionresponse', | ||
name='timestamp', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from rest_framework.serializers import ModelSerializer | ||
|
||
from mycarehub.clients.models import ( | ||
Client, | ||
ClientFacility, | ||
Identifier, | ||
RelatedPerson, | ||
SecurityQuestion, | ||
SecurityQuestionResponse, | ||
) | ||
|
||
|
||
class IdentifierSerializer(ModelSerializer): | ||
class Meta: | ||
model = Identifier | ||
fields = "__all__" | ||
|
||
|
||
class SecurityQuestionSerializer(ModelSerializer): | ||
class Meta: | ||
model = SecurityQuestion | ||
fields = "__all__" | ||
|
||
|
||
class SecurityQuestionResponseSerializer(ModelSerializer): | ||
class Meta: | ||
model = SecurityQuestionResponse | ||
fields = "__all__" | ||
|
||
|
||
class RelatedPersonSerializer(ModelSerializer): | ||
class Meta: | ||
model = RelatedPerson | ||
fields = "__all__" | ||
|
||
|
||
class ClientSerializer(ModelSerializer): | ||
class Meta: | ||
model = Client | ||
fields = "__all__" | ||
|
||
|
||
class ClientFacilitySerializer(ModelSerializer): | ||
class Meta: | ||
model = ClientFacility | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.urls import reverse | ||
from faker import Faker | ||
from model_bakery import baker | ||
from rest_framework.test import APITestCase | ||
|
||
from mycarehub.common.tests.test_api import LoggedInMixin | ||
|
||
from .models import Identifier | ||
|
||
fake = Faker() | ||
|
||
|
||
class IdentifierViewsetTest(LoggedInMixin, APITestCase): | ||
def setUp(self): | ||
self.url_list = reverse("api:identifier-list") | ||
self.comparison_field = "identifier_value" | ||
self.url_detail_base = "api:identifier-detail" | ||
self.instance = baker.make( | ||
Identifier, | ||
identifier_type="NATIONAL_ID", | ||
identifier_value=fake.ssn(), | ||
identifier_use="OFFICIAL", | ||
description=fake.text(), | ||
is_primary_identifier=True, | ||
organisation=self.global_organisation, | ||
) | ||
self.data = { | ||
"identifier_type": "NATIONAL_ID", | ||
"identifier_value": fake.ssn(), | ||
"identifier_use": "OFFICIAL", | ||
"description": fake.text(), | ||
"is_primary_identifier": True, | ||
"organisation": self.global_organisation.pk, | ||
} | ||
self.detail_url = reverse(self.url_detail_base, kwargs={"pk": self.instance.pk}) | ||
super().setUp() | ||
|
||
def test_create(self): | ||
response = self.client.post(self.url_list, self.data) | ||
assert response.status_code == 201, response.json() | ||
assert response.data[self.comparison_field] == self.data[self.comparison_field] | ||
|
||
def test_list(self): | ||
response = self.client.get(self.url_list) | ||
assert response.status_code == 200, response.json() | ||
assert response.data["count"] >= 1, response.json() | ||
|
||
values = [a[self.comparison_field] for a in response.data["results"]] | ||
assert getattr(self.instance, self.comparison_field) in values | ||
|
||
def test_retrieve(self): | ||
response = self.client.get(self.detail_url) | ||
assert response.status_code == 200, response.json() | ||
assert response.data[self.comparison_field] == getattr( | ||
self.instance, self.comparison_field | ||
) | ||
|
||
def test_patch(self): | ||
patch = {self.comparison_field: fake.ssn()} | ||
response = self.client.patch(self.detail_url, patch) | ||
assert response.status_code == 200, response.json() | ||
assert response.data[self.comparison_field] == patch[self.comparison_field] | ||
|
||
def test_put(self): | ||
response = self.client.put(self.detail_url, self.data) | ||
assert response.status_code == 200, response.json() | ||
assert response.data[self.comparison_field] == self.data[self.comparison_field] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from mycarehub.clients.models import ( | ||
Client, | ||
ClientFacility, | ||
Identifier, | ||
RelatedPerson, | ||
SecurityQuestion, | ||
SecurityQuestionResponse, | ||
) | ||
from mycarehub.clients.serializers import ( | ||
ClientFacilitySerializer, | ||
ClientSerializer, | ||
IdentifierSerializer, | ||
RelatedPersonSerializer, | ||
SecurityQuestionResponseSerializer, | ||
SecurityQuestionSerializer, | ||
) | ||
|
||
|
||
class IdentifierViewSet(ModelViewSet): | ||
queryset = Identifier.objects.order_by("pk") | ||
serializer_class = IdentifierSerializer | ||
|
||
|
||
class SecurityQuestionViewSet(ModelViewSet): | ||
queryset = SecurityQuestion.objects.order_by("pk") | ||
serializer_class = SecurityQuestionSerializer | ||
|
||
|
||
class SecurityQuestionResponseViewSet(ModelViewSet): | ||
queryset = SecurityQuestionResponse.objects.order_by("pk") | ||
serializer_class = SecurityQuestionResponseSerializer | ||
|
||
|
||
class RelatedPersonViewSet(ModelViewSet): | ||
queryset = RelatedPerson.objects.order_by("pk") | ||
serializer_class = RelatedPersonSerializer | ||
|
||
|
||
class ClientViewSet(ModelViewSet): | ||
queryset = Client.objects.order_by("pk") | ||
serializer_class = ClientSerializer | ||
|
||
|
||
class ClientFacilityViewSet(ModelViewSet): | ||
queryset = ClientFacility.objects.order_by("pk") | ||
serializer_class = ClientFacilitySerializer |
19 changes: 19 additions & 0 deletions
19
mycarehub/common/migrations/0004_alter_auditlog_timestamp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.2.9 on 2021-11-09 06:22 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0003_auto_20211108_2023'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='auditlog', | ||
name='timestamp', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 3.2.9 on 2021-11-09 06:22 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0002_auto_20211108_2027'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='metric', | ||
name='timestamp', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='termsofservice', | ||
name='valid_from', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='userpin', | ||
name='valid_from', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
migrations.AlterField( | ||
model_name='userpin', | ||
name='valid_to', | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters