-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KYC Service Layer #35774
base: master
Are you sure you want to change the base?
KYC Service Layer #35774
Changes from 1 commit
fc323ea
929185b
4ea342f
143f16c
4ae1201
1d2c951
7666d11
b06292d
945da40
d709e5d
7697748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.test import TestCase | ||
|
||
import pytest | ||
|
||
from corehq.apps.integration.kyc.models import KycConfig, UserDataStore | ||
from corehq.motech.models import ConnectionSettings | ||
|
||
DOMAIN = 'test-domain' | ||
|
||
|
||
class TestGetConnectionSettings(TestCase): | ||
|
||
def test_valid_without_connection_settings(self): | ||
config = KycConfig( | ||
domain=DOMAIN, | ||
user_data_store=UserDataStore.USER_CASE, | ||
) | ||
# Does not raise `django.db.utils.IntegrityError` | ||
config.save() | ||
|
||
def test_get_connection_settings(self): | ||
config = KycConfig( | ||
domain=DOMAIN, | ||
user_data_store=UserDataStore.USER_CASE, | ||
) | ||
assert ConnectionSettings.objects.count() == 0 | ||
|
||
connx = config.get_connection_settings() | ||
assert isinstance(connx, ConnectionSettings) | ||
# First call creates ConnectionSettings | ||
assert ConnectionSettings.objects.count() == 1 | ||
|
||
connx = config.get_connection_settings() | ||
assert isinstance(connx, ConnectionSettings) | ||
# Subsequent calls get existing ConnectionSettings | ||
assert ConnectionSettings.objects.count() == 1 | ||
|
||
def test_bad_config(self): | ||
config = KycConfig( | ||
domain=DOMAIN, | ||
user_data_store=UserDataStore.USER_CASE, | ||
provider='invalid', | ||
) | ||
with pytest.raises( | ||
ValueError, | ||
match="^Unable to determine connection settings for KYC provider " | ||
"'invalid'.$", | ||
): | ||
config.get_connection_settings() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 4.2.18 on 2025-02-16 22:53 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("motech", "0017_connectionsettings_use_aes_cbc_encryption"), | ||
("integration", "0008_kycconfig_provider_kycconfig_unique_domain_provider"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="kycconfig", | ||
name="connection_settings", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="motech.connectionsettings", | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1172,6 +1172,14 @@ def _pkce_required(client_id): | |
# used by periodic tasks that delete soft deleted data older than PERMANENT_DELETION_WINDOW days | ||
PERMANENT_DELETION_WINDOW = 30 # days | ||
|
||
# Used by `corehq.apps.integration.kyc`. Override in localsettings.py | ||
MTN_KYC_CONNECTION_SETTINGS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I am probably behind on recent updates with MTN ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out that the API service provider will have a contract with the platform provider (i.e. Dimagi), and will grant access to them, and not to each project ... ... which has just made me think that saving the ConnectionSettings instance is not a good idea. Projects/users can't read the secrets of ConnectionSettings instances, but they can change them. So either we need to have a way to write-protect ConnectioinSettings, or we need to create them on the fly without persisting them. |
||
'url': 'https://dev.api.chenosis.io/', | ||
'token_url': 'https://dev.api.chenosis.io/oauth/client/accesstoken', | ||
'client_id': 'test', | ||
'client_secret': 'password', | ||
} | ||
|
||
|
||
try: | ||
# try to see if there's an environmental variable set for local_settings | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have a short documentation for steps to add a new provider.
Could be done in the follow up work along with TODOs.