-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M2-4964: Add option to save users session fixtures after tests
- Loading branch information
1 parent
ac5122b
commit 084eb96
Showing
10 changed files
with
356 additions
and
440 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import uuid | ||
|
||
from pytest import fixture, mark | ||
|
||
|
@@ -7,23 +6,23 @@ | |
EMPTY_DESCRIPTIONS = [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test1", | ||
notification_descriptions=None, | ||
notification_in_queue=[{"name": "in_queue1"}], | ||
scheduled_notifications=[{"name": "notifications1"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test2", | ||
notification_descriptions=[], | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
scheduled_notifications=[{"name": "notifications2"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test3", | ||
notification_descriptions=None, | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
|
@@ -34,23 +33,23 @@ | |
EMPTY_QUEUE = [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test1", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=None, | ||
scheduled_notifications=[{"name": "notifications1"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test2", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=[], | ||
scheduled_notifications=[{"name": "notifications2"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test3", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=None, | ||
|
@@ -61,23 +60,23 @@ | |
EMPTY_SCHEDULE = [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test1", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=[{"name": "in_queue1"}], | ||
scheduled_notifications=None, | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test2", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
scheduled_notifications=[], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test3", | ||
notification_descriptions=[{"name": "description"}], | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
|
@@ -91,7 +90,7 @@ def dummy_logs_payload() -> list[dict]: | |
return [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type=f"test{i}", | ||
notification_descriptions=[{"sample": f"descriptions{i}"}], | ||
notification_in_queue=[{"sample": f"queue{i}"}], | ||
|
@@ -103,14 +102,11 @@ def dummy_logs_payload() -> list[dict]: | |
|
||
class TestNotificationLogs(BaseTest): | ||
logs_url = "/logs/notification" | ||
fixtures = [ | ||
"users/fixtures/user_devices.json", | ||
] | ||
|
||
async def test_create_log(self, client): | ||
async def test_create_log(self, client, device_tom): | ||
create_data = dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=[{"sample": "json"}], | ||
notification_in_queue=[{"sample": "json"}], | ||
|
@@ -121,20 +117,21 @@ async def test_create_log(self, client): | |
assert response.status_code == 201, response.json() | ||
assert response.json()["result"]["id"] | ||
|
||
async def test_retrieve_log(self, client): | ||
async def test_retrieve_log(self, client, device_tom): | ||
query = dict( | ||
email="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id=device_tom, | ||
) | ||
|
||
response = await client.get(self.logs_url, query=query) | ||
|
||
assert response.status_code == 200, response.json() | ||
assert isinstance(response.json()["result"], list) | ||
|
||
new_device_id = "new_device_id" | ||
create_data = dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id=new_device_id, | ||
action_type="test", | ||
notification_descriptions=[{"sample": "json"}], | ||
notification_in_queue=[{"sample": "json"}], | ||
|
@@ -147,7 +144,7 @@ async def test_retrieve_log(self, client): | |
|
||
query = dict( | ||
email="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id=new_device_id, | ||
limit=10, | ||
) | ||
|
||
|
@@ -178,7 +175,7 @@ async def test_create_log_use_previous_value_if_attribute_null( | |
|
||
create_data = dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=description, | ||
notification_in_queue=queue, | ||
|
@@ -198,7 +195,7 @@ async def test_create_log_use_none_value_if_attribute_null_at_first_log(self, cl | |
self.logs_url, | ||
data=dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=None, | ||
notification_in_queue=[{"name": "notification_in_queue"}], | ||
|
@@ -216,15 +213,15 @@ async def test_create_log_use_previous_non_null_if_attribute_null(self, client): | |
payloads = [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=[{"name": "descriptions1"}], | ||
notification_in_queue=[{"name": "in_queue1"}], | ||
scheduled_notifications=[{"name": "notifications1"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=None, | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
|
@@ -237,7 +234,7 @@ async def test_create_log_use_previous_non_null_if_attribute_null(self, client): | |
|
||
create_data = dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=None, | ||
notification_in_queue=[{"name": "in_queue3"}], | ||
|
@@ -256,15 +253,15 @@ async def test_create_log_allow_empty_array(self, client): | |
payloads = [ | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=[{"name": "descriptions1"}], | ||
notification_in_queue=[{"name": "in_queue1"}], | ||
scheduled_notifications=[{"name": "notifications1"}], | ||
), | ||
dict( | ||
user_id="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
action_type="test", | ||
notification_descriptions=[], | ||
notification_in_queue=[{"name": "in_queue2"}], | ||
|
@@ -278,7 +275,7 @@ async def test_create_log_allow_empty_array(self, client): | |
|
||
query = dict( | ||
email="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
limit=5, | ||
) | ||
|
||
|
@@ -309,7 +306,7 @@ async def test_create_log_allow_empty_array_if_prev_is_none(self, client, param, | |
|
||
query = dict( | ||
email="[email protected]", | ||
device_id=str(uuid.uuid4()), | ||
device_id="deviceid", | ||
limit=5, | ||
) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import cast | ||
|
||
import pytest | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from apps.users.cruds.user_device import UserDevicesCRUD | ||
from apps.users.db.schemas import UserDeviceSchema | ||
from apps.users.domain import User | ||
from apps.users.services.user_device import UserDeviceService | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
async def device_tom(tom: User, global_session: AsyncSession): | ||
service = UserDeviceService(global_session, tom.id) | ||
await service.add_device("deviceid") | ||
await global_session.commit() | ||
crud = UserDevicesCRUD(global_session) | ||
device = await crud._get("device_id", "deviceid") | ||
device = cast(UserDeviceSchema, device) | ||
yield device.device_id | ||
await service.remove_device("deviceid") | ||
await global_session.commit() |
Oops, something went wrong.