diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 357a299..0397c58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: | @@ -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: | diff --git a/mycarehub/common/admin.py b/mycarehub/common/admin.py index 5b696fb..9ae9815 100644 --- a/mycarehub/common/admin.py +++ b/mycarehub/common/admin.py @@ -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 @@ -78,3 +85,8 @@ class FAQAdmin(BaseAdmin): @admin.register(Notification) class NotificationAdmin(BaseAdmin): pass + + +@admin.register(UserSurveys) +class UserSurveysAdmin(BaseAdmin): + pass diff --git a/mycarehub/common/migrations/0020_usersurveys.py b/mycarehub/common/migrations/0020_usersurveys.py new file mode 100644 index 0000000..45cbcef --- /dev/null +++ b/mycarehub/common/migrations/0020_usersurveys.py @@ -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()), + ], + ), + ] diff --git a/mycarehub/common/models/common_models.py b/mycarehub/common/models/common_models.py index 63317ff..4d870cc 100644 --- a/mycarehub/common/models/common_models.py +++ b/mycarehub/common/models/common_models.py @@ -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}" diff --git a/mycarehub/common/tests/test_models.py b/mycarehub/common/tests/test_models.py index 5a3c86d..bc3ef1b 100644 --- a/mycarehub/common/tests/test_models.py +++ b/mycarehub/common/tests/test_models.py @@ -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() @@ -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" diff --git a/mycarehub/utils/tests/test_storages.py b/mycarehub/utils/tests/test_storages.py index d3dd991..f2bc2e7 100644 --- a/mycarehub/utils/tests/test_storages.py +++ b/mycarehub/utils/tests/test_storages.py @@ -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) diff --git a/requirements/local.txt b/requirements/local.txt index 4e3eb18..f2e1c77 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -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 diff --git a/requirements/production.txt b/requirements/production.txt index cabddbd..184f2ec 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -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