Skip to content

Commit

Permalink
feat: setup client surveys
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed May 11, 2022
1 parent 45635f8 commit 81dfa07
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ jobs:
run: ./.github/scripts/decrypt_secret.sh
env:
SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }}

- name: Purge postgres
run: |
sudo apt-get --purge remove postgresql postgresql-*
- name: Install requirements
run: |
Expand All @@ -102,6 +106,15 @@ jobs:
pip install -r requirements/local.txt && pip install -r requirements/production.txt
npm ci
npm install -g mjml
- name: Install Postgresql/PostGIS 12
run: |
sudo apt-get install postgresql-12 postgresql-12-postgis-3
- name: Setup and start postgres service
run: |
sudo pg_ctlcluster 12 main start
sudo -u ${POSTGRES_USER} psql -p ${POSTGRES_PORT} -c "ALTER USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';"
- name: Set up Django
run: |
Expand Down
14 changes: 13 additions & 1 deletion mycarehub/common/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from django.contrib import admin

from mycarehub.common.models.common_models import FAQ, Address, AuditLog, Contact, Notification
from mycarehub.common.models.common_models import (
FAQ,
Address,
AuditLog,
Contact,
Notification,
UserSurveys,
)

from .models import Facility, FacilityAttachment, Organisation

Expand Down Expand Up @@ -78,3 +85,8 @@ class FAQAdmin(BaseAdmin):
@admin.register(Notification)
class NotificationAdmin(BaseAdmin):
pass


@admin.register(UserSurveys)
class UserSurveysAdmin(BaseAdmin):
pass
45 changes: 45 additions & 0 deletions mycarehub/common/migrations/0020_usersurveys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.2.11 on 2022-05-09 13:37

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import mycarehub.common.models.base_models
import mycarehub.utils.general_utils
import uuid


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('common', '0019_alter_notification_title'),
]

operations = [
migrations.CreateModel(
name='UserSurveys',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('active', models.BooleanField(default=True)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
('created_by', models.UUIDField(blank=True, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
('updated_by', models.UUIDField(blank=True, null=True)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('survey_link', models.TextField()),
('survey_title', models.TextField()),
('survey_description', models.TextField(blank=True, null=True)),
('has_submitted', models.BooleanField(default=False)),
('organisation', models.ForeignKey(default=mycarehub.utils.general_utils.default_organisation, on_delete=django.db.models.deletion.PROTECT, related_name='common_usersurveys_related', to='common.organisation')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ('-updated', '-created'),
'abstract': False,
},
managers=[
('objects', mycarehub.common.models.base_models.AbstractBaseManager()),
],
),
]
18 changes: 18 additions & 0 deletions mycarehub/common/models/common_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,21 @@ class FlavourChoices(models.TextChoices):

def __str__(self) -> str:
return f"{self.notification_type} - {self.title}"


class UserSurveys(AbstractBase):
"""
UserSurveys Model defines the surveys that are provided to the client or
staff based on flavour.
If the user has filled in the survey, has_submitted is set to True
The link should be only be used once for every submission
"""

user = models.ForeignKey(User, on_delete=models.CASCADE)
survey_link = models.TextField()
survey_title = models.TextField()
survey_description = models.TextField(null=True, blank=True)
has_submitted = models.BooleanField(default=False)

def __str__(self) -> str:
return f"{self.survey_title}"
16 changes: 15 additions & 1 deletion mycarehub/common/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
is_image_type,
unique_list,
)
from mycarehub.common.models.common_models import Address, Contact, Notification
from mycarehub.common.models.common_models import Address, Contact, Notification, UserSurveys

fake = Faker()

Expand Down Expand Up @@ -720,3 +720,17 @@ def test_notification_str():
title="Test Notification",
)
assert str(notification) == "TELECONSULT - Test Notification"


def test_user_surveys():
response = baker.make(
UserSurveys,
survey_link="https://mycarehub.org/survey",
survey_title="survey_title",
survey_description="survey_description",
has_submitted=False,
user=baker.make(
get_user_model(), name=fake.name(), organisation=baker.make("common.Organisation")
),
)
assert str(response) == "survey_title"
4 changes: 0 additions & 4 deletions mycarehub/utils/tests/test_storages.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pytest
from django.core.management import call_command
from model_bakery import baker

pytestmark = pytest.mark.django_db


class TestStorages:
def test_static_root_google_cloud_storage(self):
call_command("collectstatic", "--noinput")

def test_media_root_google_cloud_storage(self):
org = baker.make("common.Organisation")
facility = baker.make("common.Facility", name="Test Facility", organisation=org)
Expand Down
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ watchgod~=0.7 # https://github.com/samuelcolvin/watchgod

# Testing
# ------------------------------------------------------------------------------
mypy~=0.910 # https://github.com/python/mypy
mypy~=0.950 # https://github.com/python/mypy
django-stubs~=1.9.0 # https://github.com/typeddjango/django-stubs
pytest~=6.2.4 # https://github.com/pytest-dev/pytest
pytest-sugar~=0.9.4 # https://github.com/Frozenball/pytest-sugar
Expand Down
2 changes: 1 addition & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

gunicorn~=20.1.0 # https://github.com/benoitc/gunicorn
psycopg2-binary~=2.9.1 # https://github.com/psycopg/psycopg2
sentry-sdk~=1.4.3 # https://github.com/getsentry/sentry-python
sentry-sdk~=1.5.12 # https://github.com/getsentry/sentry-python

0 comments on commit 81dfa07

Please sign in to comment.