Skip to content

Commit

Permalink
Merge pull request #175 from praekeltfoundation/randomisation-stratif…
Browse files Browse the repository at this point in the history
…ication

Update django and drf, fix warnings
  • Loading branch information
erikh360 authored Apr 15, 2024
2 parents 60d2358 + 831449a commit c073f6b
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
13 changes: 8 additions & 5 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
env = environ.Env(DEBUG=(bool, False))

ROOT_DIR = root()
environ.Env.read_env(join(ROOT_DIR, ".env"))

ALLOWED_HOSTS = []

Expand Down Expand Up @@ -100,8 +99,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand All @@ -115,7 +112,14 @@

STATIC_ROOT = join(ROOT_DIR, "staticfiles")
STATIC_URL = "/static/"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
COMPRESS_ENABLED = True

MEDIA_ROOT = join(ROOT_DIR, "media")
Expand Down Expand Up @@ -147,7 +151,6 @@
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
"DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema",
}

AWS_ACCESS_KEY_ID = env.str("AWS_ACCESS_KEY_ID", "")
Expand Down
13 changes: 8 additions & 5 deletions rp_recruit/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_recruit_view_post_500(self, fake_get_whatsapp_contact_id):
url, {"msisdn": "+27821111111", "name": "test user"}
)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertFormError(response, "form", None, [WA_CHECK_FORM_ERROR])
self.assertFormError(response.context["form"], None, [WA_CHECK_FORM_ERROR])

@patch("rp_recruit.views.get_whatsapp_contact_id", autospec=True, return_value=None)
def test_recruit_view_post_400(self, mock_get_whatsapp_contact_id):
Expand All @@ -69,8 +69,7 @@ def test_recruit_view_post_400(self, mock_get_whatsapp_contact_id):
url, {"msisdn": "+27821111111", "name": "test user"}
)
self.assertFormError(
response,
"form",
response.context["form"],
"msisdn",
[f"{msisdn} is not a valid WhatsApp contact number"],
)
Expand All @@ -95,7 +94,9 @@ def test_recruit_view_post_400_rp_contact_exists(
)

self.assertFormError(
response, "form", "msisdn", [f"{msisdn} is not a valid contact number"]
response.context["form"],
"msisdn",
[f"{msisdn} is not a valid contact number"],
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
assertCallMadeWith(mock_get_contacts.call_args, urn=f"whatsapp:{wa_id}")
Expand Down Expand Up @@ -134,7 +135,9 @@ def test_recruit_view_post_500_rp_create_failure(

mock_capture_exception.assert_called_once()

self.assertFormError(response, "form", None, [RAPIDPRO_CREATE_OR_START_FAILURE])
self.assertFormError(
response.context["form"], None, [RAPIDPRO_CREATE_OR_START_FAILURE]
)
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)

assertCallMadeWith(mock_get_contacts.call_args, urn=f"whatsapp:{wa_id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-04-11 14:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("rp_transferto", "0004_add_topup_model"),
]

operations = [
migrations.AlterField(
model_name="msisdninformation",
name="data",
field=models.JSONField(),
),
migrations.AlterField(
model_name="topupattempt",
name="response",
field=models.JSONField(null=True),
),
]
2 changes: 1 addition & 1 deletion rp_transferto/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

import pkg_resources
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models import JSONField
from django.utils import timezone

from sidekick.models import Organization
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = */migrations/*.py,*/manage.py,ve/*
exclude = */migrations/*.py,*/manage.py,ve/*,env/*
ignore = D100, D101, D102, D103, D104, D105, W503, E501, F405
line_length = 88

Expand All @@ -15,5 +15,5 @@ line_length = 88
# Vertical hanging indent, for black
multi_line_output = 3
include_trailing_comma = True
skip = ve/
skip = ve/,env/
known_third_party = boto3,celery,dj_database_url,django,environ,freezegun,hashids,json2html,kombu,moto,phonenumber_field,pkg_resources,prometheus_client,pytest,raven,recommonmark,requests,responses,rest_framework,sentry_sdk,setuptools,six,temba_client
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
include_package_data=True,
install_requires=[
"celery==5.2.3",
"coreapi==2.3.3",
"Django==3.2.25",
"Django==4.2.11",
"django-environ==0.4.5",
"django-extensions==3.1.5",
"django-phonenumber-field==3.0.1",
"django-prometheus==2.2.0",
"djangorestframework==3.13.1",
"djangorestframework==3.15.1",
"json2html==1.3.0",
"phonenumbers==8.10.23",
"psycopg2-binary==2.8.6",
Expand Down
9 changes: 0 additions & 9 deletions sidekick/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def mock_queue_lookup(self, name="rp_sidekick", messages=1256, rate=1.25):
"name": name,
},
status=200,
match_querystring=True,
)

@responses.activate
Expand Down Expand Up @@ -136,7 +135,6 @@ def add_whatsapp_messages_200_response(self):
"meta": {"api_status": "stable", "version": "2.19.4"},
},
status=201,
match_querystring=True,
)

@responses.activate
Expand Down Expand Up @@ -278,7 +276,6 @@ def test_wa_check_contact_valid(self):
]
},
status=201,
match_querystring=True,
)

# get result
Expand Down Expand Up @@ -313,7 +310,6 @@ def test_wa_check_contact_invalid(self):
"{}/v1/contacts".format(FAKE_ENGAGE_URL),
json={"contacts": [{"input": telephone_number, "status": "invalid"}]},
status=201,
match_querystring=True,
)

# get result
Expand Down Expand Up @@ -348,7 +344,6 @@ def test_wa_check_contact_error(self):
"{}/v1/contacts".format(FAKE_ENGAGE_URL),
"Invalid WhatsApp Token",
status=status.HTTP_403_FORBIDDEN,
match_querystring=True,
)

# get result
Expand Down Expand Up @@ -901,7 +896,6 @@ def test_get_rapidpro_flows(self):
"http://localhost:8002/api/v2/flows.json",
json=response_body,
status=200,
match_querystring=True,
)

self.client.force_authenticate(self.user)
Expand Down Expand Up @@ -950,7 +944,6 @@ def test_start_rapidpro_flow(self):
"http://localhost:8002/api/v2/flow_starts.json",
json=response_body,
status=200,
match_querystring=True,
)
self.client.force_authenticate(self.user)

Expand Down Expand Up @@ -1010,7 +1003,6 @@ def test_get_rapidpro_contact(self):
"http://localhost:8002/api/v2/contacts.json",
json=response_body,
status=200,
match_querystring=True,
)

self.client.force_authenticate(self.user)
Expand Down Expand Up @@ -1049,7 +1041,6 @@ def test_get_rapidpro_contact_with_field_filter(self):
"http://localhost:8002/api/v2/contacts.json",
json=response_body,
status=200,
match_querystring=True,
)

self.client.force_authenticate(self.user)
Expand Down
Empty file added staticfiles/.gitkeep
Empty file.

0 comments on commit c073f6b

Please sign in to comment.