Skip to content

Commit

Permalink
Fix: migration and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotheem committed Jan 3, 2025
1 parent 50b5358 commit d888cda
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
43 changes: 38 additions & 5 deletions migrations/versions/27-MyECLPay.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ class RequestStatus(str, Enum):

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"myeclpay_structure",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column(
"membership",
sa.Enum("aeecl", "useecl", name="availableassociationmembership"),
nullable=True,
),
sa.Column("manager_user_id", sa.String(), nullable=False),
sa.ForeignKeyConstraint(
["manager_user_id"],
["core_user.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"myeclpay_structure_manager_transfert",
sa.Column("structure_id", sa.Uuid(), nullable=False),
sa.Column("user_id", sa.String(), nullable=False),
sa.Column("confirmation_token", sa.String(), nullable=False),
sa.Column("valid_until", TZDateTime(), nullable=False),
sa.ForeignKeyConstraint(
["structure_id"],
["myeclpay_structure.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["core_user.id"],
),
sa.PrimaryKeyConstraint("structure_id"),
)

op.create_table(
"myeclpay_used_qrcode",
sa.Column("qr_code_id", sa.Uuid(), nullable=False),
Expand All @@ -82,18 +115,18 @@ def upgrade() -> None:
"myeclpay_store",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column(
"membership",
postgresql.ENUM(name="availableassociationmembership", create_type=False),
nullable=False,
),
sa.Column("structure_id", sa.Uuid(), nullable=False),
sa.Column("wallet_id", sa.Uuid(), nullable=False, unique=True),
sa.ForeignKeyConstraint(
["wallet_id"],
["myeclpay_wallet.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("name"),
sa.ForeignKeyConstraint(
["structure_id"],
["myeclpay_structure.id"],
),
)
op.create_table(
"myeclpay_transfer",
Expand Down
24 changes: 24 additions & 0 deletions tests/test_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,30 @@ async def test_transfer_structure_manager_as_admin(client: TestClient):
assert response.json()["detail"] == "User is not the manager for this structure"


async def test_transfer_structure_manager_with_wrong_token(client: TestClient):
tranfert = models_myeclpay.StructureManagerTransfert(
structure_id=structure.id,
user_id=ecl_user2.id,
confirmation_token="RANDOM_TOKEN",
valid_until=datetime.now(UTC),
)
await add_object_to_db(tranfert)

response = client.get(
"/myeclpay/structures/confirm-manager-transfert",
params={"token": "WRONG_TOKEN"},
)
assert response.status_code == 404
assert response.json()["detail"] == "Request does not exist"

response = client.get(
"/myeclpay/structures/confirm-manager-transfert",
params={"token": "RANDOM_TOKEN"},
)
assert response.status_code == 400
assert response.json()["detail"] == "Request has expired"


async def test_transfer_structure_manager_as_manager(
client: TestClient,
mocker: MockerFixture,
Expand Down

0 comments on commit d888cda

Please sign in to comment.