def new_dataset_subscription(): return Subscription( user_id="00000000-0000-0000-0000-000000000000", kind="NEW_DATASETS", user_name="julietezekwe", email="*****@*****.**", )
def subscription_data(): return Subscription( user_id="user-id-1", email="*****@*****.**", kind="DATASET", dataset_id="dataset_id", dataset_name="dataset_name", user_name="Alice", )
def subscription(): return Subscription( dataset_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", user_id="00000000-0000-0000-0000-000000000000", user_name="julietezekwe", email="*****@*****.**", dataset_name="test_dataset", kind="DATASET", )
def test_get_subscribed_datasets_nonexits_user_404(client, db, subscription_list): # Return 404 NOT FOUND for users who are not subscribing to any dataset. for sub in subscription_list: db.session.add( Subscription( dataset_id=sub["dataset_id"], user_id=sub["user_id"], user_name="julietezekwe1", kind="DATASET", email="*****@*****.**", )) db.session.commit() user_id = "user4" # non existing user response = client.get(f"/api/v1/user/{user_id}") assert response.status_code == 404
def test_prepare_stat_for_new_datasets_subscription(): subscription = Subscription( created_at=dt.datetime(2020, 12, 31), user_id="1", user_name="Laura", dataset_id=None, dataset_name=None, kind=Kind.NEW_DATASETS, ) assert prepare_stat(subscription) == { "subscribed_at": "2020-12-31 00:00:00", "user_id": "1", "user_name": "Laura", "dataset_id": "N/A", "dataset_name": "N/A", "kind": "NEW_DATASETS", }
def test_prepare_stat_for_dataset_subscription(): subscription = Subscription( created_at=dt.datetime(2020, 12, 31), user_id="1", user_name="Laura", dataset_id="x", dataset_name="The number X dataset", kind=Kind.DATASET, ) assert prepare_stat(subscription) == { "subscribed_at": "2020-12-31 00:00:00", "user_id": "1", "user_name": "Laura", "dataset_id": "x", "dataset_name": "The number X dataset", "kind": "DATASET", }
def test_get_subscribed_datasets_200(client, db, subscription_list): # Return 200 OK for users with an existing subscription list. for sub in subscription_list: db.session.add( Subscription( dataset_id=sub["dataset_id"], user_id=sub["user_id"], user_name="julietezekwe1", kind="DATASET", email="*****@*****.**", )) db.session.commit() user_id = subscription_list[0]["user_id"] response = client.get(f"/api/v1/user/{user_id}") data = response.get_json() assert data == { "subscriptions": [subscription_list[0], subscription_list[1]] } assert response.status_code == 200
def all_subscription(db, all_subscription_list): for x in [Subscription(**x) for x in all_subscription_list]: db.session.add(x) db.session.commit() return all_subscription_list