-
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.
* Update add_customers endpoint * Refactor validation when getting app customers * Raise validation error if invalid env is provided * Catch invalid env name when adding customers
- Loading branch information
1 parent
c010466
commit bb318f1
Showing
4 changed files
with
126 additions
and
48 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
# First-party/Local | ||
from controlpanel.api.jwt_auth import AuthenticatedServiceClient | ||
from controlpanel.api.models import App | ||
from controlpanel.api.permissions import AppJwtPermissions | ||
|
||
|
||
|
@@ -42,7 +43,16 @@ def users(users, authenticated_client, invalid_client_sub, invalid_client_scope) | |
|
||
@pytest.fixture(autouse=True) | ||
def app(users): | ||
app = baker.make("api.App", name="Test App 1", app_conf={"m2m": {"client_id": "abc123"}}) | ||
app = baker.make( | ||
"api.App", | ||
name="Test App 1", | ||
app_conf={ | ||
"m2m": {"client_id": "abc123"}, | ||
App.KEY_WORD_FOR_AUTH_SETTINGS: { | ||
"test": {"group_id": "test_group_id"}, | ||
}, | ||
}, | ||
) | ||
user = users["app_admin"] | ||
baker.make("api.UserApp", user=user, app=app, is_admin=True) | ||
|
||
|
@@ -125,12 +135,11 @@ def app_by_name_customers(client, app, *args): | |
|
||
|
||
def app_by_name_add_customers(client, app, *args): | ||
data = {"email": "[email protected]"} | ||
data = {"emails": "[email protected]", "env_name": "test"} | ||
with patch("controlpanel.api.models.App.add_customers"): | ||
return client.post( | ||
reverse("apps-by-name-customers", kwargs={"name": app.name}), | ||
data, | ||
query_params={"env_name": "test"}, | ||
) | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -21,6 +21,12 @@ def app(): | |
return baker.make( | ||
"api.App", | ||
repo_url="https://github.com/ministryofjustice/example.git", | ||
app_conf={ | ||
App.KEY_WORD_FOR_AUTH_SETTINGS: { | ||
"dev": {"group_id": "dev_group_id"}, | ||
"prod": {"group_id": "prod_group_id"}, | ||
} | ||
}, | ||
) | ||
|
||
|
||
|
@@ -114,7 +120,7 @@ def customer(): | |
} | ||
|
||
|
||
@pytest.mark.parametrize("env_name", ["dev", "prod"]) | ||
@pytest.mark.parametrize("env_name", ["dev", "prod"], ids=["dev", "prod"]) | ||
def test_app_by_name_get_customers(client, app, customer, env_name): | ||
with patch("controlpanel.api.models.App.customer_paginated") as customer_paginated: | ||
customer_paginated.return_value = {"total": 1, "users": [customer]} | ||
|
@@ -135,17 +141,43 @@ def test_app_by_name_get_customers(client, app, customer, env_name): | |
assert response.data["results"] == [{field: customer[field] for field in expected_fields}] | ||
|
||
|
||
@pytest.mark.parametrize("env_name", ["", "foo"]) | ||
def test_app_by_name_get_customers_invalid(client, app, env_name): | ||
with patch("controlpanel.api.models.App.customer_paginated") as customer_paginated: | ||
|
||
response = client.get( | ||
reverse("apps-by-name-customers", kwargs={"name": app.name}), | ||
query_params={"env_name": env_name}, | ||
) | ||
customer_paginated.assert_not_called() | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
||
@pytest.mark.parametrize("env_name", ["dev", "prod"]) | ||
def test_app_by_name_add_customers(client, app, env_name): | ||
emails = ["[email protected]", "[email protected]"] | ||
data = {"email": ", ".join(emails)} | ||
data = {"emails": ", ".join(emails), "env_name": env_name} | ||
|
||
with patch("controlpanel.api.models.App.add_customers") as add_customers: | ||
url = reverse("apps-by-name-customers", kwargs={"name": app.name}) | ||
response = client.post(f"{url}?env_name={env_name}", data=data) | ||
response = client.post(url, data=data) | ||
|
||
add_customers.assert_called_once_with(emails, env_name=env_name) | ||
assert response.status_code == status.HTTP_201_CREATED | ||
add_customers.assert_called_once_with(emails, env_name=env_name) | ||
|
||
|
||
@pytest.mark.parametrize("env_name", ["", "foo"]) | ||
def test_app_by_name_add_customers_invalid(client, app, env_name): | ||
emails = ["[email protected]", "[email protected]"] | ||
data = {"emails": ", ".join(emails)} | ||
|
||
with patch("controlpanel.api.models.App.add_customers") as add_customers: | ||
add_customers.side_effect = app.AddCustomerError | ||
url = reverse("apps-by-name-customers", kwargs={"name": app.name}) | ||
response = client.post(url, data=data) | ||
|
||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
add_customers.assert_not_called() | ||
|
||
|
||
def test_app_detail_by_name(client, app): | ||
|