-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
33 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 |
---|---|---|
|
@@ -23,6 +23,9 @@ | |
invalid_connection = {"name": "Mike", "email": "[email protected]", "connection": "INVALID", "password": "123456"} | ||
invalid_pass_length = {"name": "Victor", "email": "[email protected]", "connection": "SERVIDOR", "password": "123"} | ||
invalid_pass = {"name": "Luisa", "email": "[email protected]", "connection": "SERVIDOR", "password": "123abc"} | ||
valid_social_user = { "name": "Paulo Kogos", "email": "[email protected]" } | ||
|
||
total_registed_users = 5 | ||
|
||
client = TestClient(app) | ||
|
||
|
@@ -89,6 +92,14 @@ def setup(self, session_mocker): | |
TestAuth.__user_access_token__ = data['access_token'] | ||
TestAuth.__user_refresh_token__ = data['access_token'] | ||
|
||
# login social - criação conta (nova) | ||
response = client.post('/api/auth/login/social', json=valid_social_user) | ||
data = response.json() | ||
assert response.status_code == 200 | ||
assert data["access_token"] != None | ||
assert data["token_type"] == "bearer" | ||
assert data["is_new_user"] == True | ||
|
||
# Atualiza role do active_user_admin de USER para ADMIN | ||
with engine.connect() as connection: | ||
query = "UPDATE users SET role = 'ADMIN' WHERE id = 1;" | ||
|
@@ -144,6 +155,15 @@ def test_auth_login_not_active(self, setup): | |
assert response.status_code == 401 | ||
assert data['detail'] == errorMessages.ACCOUNT_IS_NOT_ACTIVE | ||
|
||
def test_auth_login_social(self, setup): | ||
response = client.post('/api/auth/login/social', json=valid_social_user) | ||
data = response.json() | ||
assert response.status_code == 200 | ||
assert data["access_token"] != None | ||
assert data["refresh_token"] != None | ||
assert data["token_type"] == "bearer" | ||
assert data["is_new_user"] == False | ||
|
||
# RESEND CODE | ||
def test_auth_resend_code_user_not_found(self, setup): | ||
response = client.post("/api/auth/resend-code", json={"email": invalid_connection['email']}) | ||
|
@@ -304,38 +324,25 @@ def test_utils_validate_dotenv(self, setup): | |
assert str(exc_info.value) == "SOME ENVIRONMENT VALUES WERE NOT DEFINED (missing: SECRET)" | ||
|
||
os.environ["SECRET"] = environment_secret_value | ||
|
||
def test_auth_sso_google_callback_error(self, setup): | ||
response = client.get("/auth/callback") | ||
data = response.json() | ||
assert response.status_code == 400 | ||
assert data['detail'] == "'code' parameter was not found in callback request" | ||
|
||
def test_auth_sso_google_login_success_load(self, setup): | ||
response = client.get("/callback") | ||
data = response.json() | ||
assert response.status_code == 400 | ||
assert data['detail'] == "'code' parameter was not found in callback request" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_auth_send_mail_send_verification_code_success(self, setup): | ||
send_mail.fm.config.SUPPRESS_SEND = 1 | ||
with send_mail.fm.record_messages() as outbox: | ||
response = await send_mail.send_verification_code(valid_user_active_admin['email'], 123456) | ||
assert response.status_code == 200 | ||
assert len(outbox) == 1 | ||
assert outbox[0]['from'] == f'UNB TV <{os.environ["MAIL_FROM"]}>' | ||
assert outbox[0]['To'] == valid_user_active_admin['email'] | ||
response = await send_mail.send_verification_code(valid_user_active_admin['email'], 123456) | ||
|
||
assert response.status_code == 200 | ||
assert len(outbox) == 1 | ||
assert outbox[0]['from'] == f'UNB TV <{os.environ["MAIL_FROM"]}>' | ||
assert outbox[0]['To'] == valid_user_active_admin['email'] | ||
|
||
@pytest.mark.asyncio | ||
async def test_auth_send_reset_password_code_success(self, setup): | ||
send_mail.fm.config.SUPPRESS_SEND = 1 | ||
with send_mail.fm.record_messages() as outbox: | ||
response = await send_mail.send_reset_password_code(valid_user_active_admin['email'], 123456) | ||
assert response.status_code == 200 | ||
assert len(outbox) == 1 | ||
assert outbox[0]['from'] == f'UNB TV <{os.environ["MAIL_FROM"]}>' | ||
assert outbox[0]['To'] == valid_user_active_admin['email'] | ||
response = await send_mail.send_reset_password_code(valid_user_active_admin['email'], 123456) | ||
|
||
assert response.status_code == 200 | ||
assert len(outbox) == 1 | ||
assert outbox[0]['from'] == f'UNB TV <{os.environ["MAIL_FROM"]}>' | ||
assert outbox[0]['To'] == valid_user_active_admin['email'] |
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