-
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.
ZDL-104: Create django signal upon user login
- Loading branch information
1 parent
d2e5d32
commit 6a54d54
Showing
9 changed files
with
136 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
from datetime import date | ||
from uuid import uuid4 | ||
|
||
import boto3 | ||
from django.conf import settings | ||
|
||
|
||
class SNSOperations: | ||
def __init__(self): | ||
""" | ||
Initialize AWS SNS client | ||
""" | ||
self.sns_client = boto3.client( | ||
"sns", | ||
region_name="us-east-1", | ||
aws_access_key_id=settings.AWS_SECRET_KEY_ID, | ||
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY, | ||
) | ||
|
||
def publish_message(self, subject: str, message: dict): | ||
""" | ||
Publish message to AWS SNS Topic | ||
""" | ||
self.sns_client.publish( | ||
TopicArn=settings.AWS_SNS_ARN, | ||
Subject=subject, | ||
Message=json.dumps(message), | ||
MessageDeduplicationId=str(uuid4()), | ||
MessageGroupId=f"group-{str(date.today())}", | ||
) |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from datetime import datetime | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from django.contrib.auth.models import Group | ||
|
@@ -69,6 +70,24 @@ def test_supplier_register(logged_in_client): | |
|
||
|
||
@pytest.mark.django_db | ||
def test_user_login_with_google_provider(client): | ||
""" | ||
Test User login with email on existing OAuth user | ||
""" | ||
user = UserFactory( | ||
email="[email protected]", password="temp-password", auth_provider="google" | ||
) | ||
data = {"email": user.email, "password": "temp-password"} | ||
|
||
response = client.post("/v1/auth/login/", data) | ||
response_data = response.json() | ||
|
||
assert response.status_code == 403 | ||
assert response_data == {"detail": "Please login using your login provider."} | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_user_login(client): | ||
""" | ||
Test User login | ||
|
@@ -84,35 +103,34 @@ def test_user_login(client): | |
|
||
|
||
@pytest.mark.django_db | ||
def test_user_login_with_google_provider(client): | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_invalid_email_credentials_user_login(client): | ||
""" | ||
Test User login with email on existing OAuth user | ||
Test Failed User login | ||
""" | ||
user = UserFactory( | ||
email="[email protected]", password="temp-password", auth_provider="google" | ||
) | ||
data = {"email": user.email, "password": "temp-password"} | ||
data = {"email": "[email protected]", "password": "password"} | ||
|
||
response = client.post("/v1/auth/login/", data) | ||
response_data = response.json() | ||
|
||
assert response.status_code == 403 | ||
assert response_data == {"detail": "Please login using your login provider."} | ||
assert response.json() == {"detail": "Invalid email/password"} | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_invalid_credentials_user_login(client): | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_invalid_password_credentials_user_login(client): | ||
""" | ||
Test Failed User login | ||
""" | ||
data = {"email": "[email protected]", "password": "password"} | ||
user = UserFactory() | ||
data = {"email": user.email, "password": "wrong-password"} | ||
|
||
response = client.post("/v1/auth/login/", data) | ||
assert response.status_code == 403 | ||
assert response.json() == {"detail": "Invalid email/password"} | ||
|
||
|
||
@pytest.mark.django_db | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_tokens(logged_in_client): | ||
""" | ||
Test refresh token | ||
|
@@ -136,6 +154,7 @@ def test_tokens(logged_in_client): | |
|
||
|
||
@pytest.mark.django_db | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_refresh_token_with_access_token(logged_in_client): | ||
""" | ||
Test refresh token with access token should fail | ||
|
@@ -251,6 +270,7 @@ def test_patch_profile_password_of_oauth_user_should_not_update(): | |
|
||
|
||
@pytest.mark.django_db | ||
@patch("botocore.client.BaseClient._make_api_call", lambda *args, **kwargs: None) | ||
def test_login_should_update_last_login_date_time(client): | ||
""" | ||
Test User login should update last login date time | ||
|
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
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