1
0
mirror of https://github.com/quay/quay.git synced 2025-07-28 20:22:05 +03:00

billing: Assign SKU to org (PROJQUAY-5363) (#1989)

* add migration for orgrhskus table

* add endpoints for managing and listing skus bound to an org

* create checks in billing flow to look for org-bound skus

* refactor RH marketplace api objects to be more usable in tests

* update cypress test db data and exclude it from pre-commit hook formatting
This commit is contained in:
Marcus Kok
2023-08-25 14:52:54 -04:00
committed by GitHub
parent 5f63b3a7bb
commit e44783fe19
19 changed files with 715 additions and 327 deletions

View File

@ -37,6 +37,8 @@ from endpoints.api.billing import (
ListPlans,
OrganizationCard,
OrganizationPlan,
OrganizationRhSku,
OrganizationRhSkuSubscriptionField,
UserCard,
UserPlan,
)
@ -5065,5 +5067,62 @@ class TestSuperUserManagement(ApiTestCase):
self.assertEqual(len(json["messages"]), 1)
class TestOrganizationRhSku(ApiTestCase):
def test_bind_sku_to_org(self):
self.login(ADMIN_ACCESS_USER)
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
data={"subscription_id": 12345},
expected_code=201,
)
json = self.getJsonResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
)
self.assertEqual(len(json), 1)
def test_bind_sku_duplicate(self):
user = model.user.get_user(ADMIN_ACCESS_USER)
org = model.organization.get_organization(ORGANIZATION)
model.organization_skus.bind_subscription_to_org(12345, org.id, user.id)
self.login(ADMIN_ACCESS_USER)
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
data={"subscription_id": 12345},
expected_code=400,
)
def test_bind_sku_unauthorized(self):
# bind a sku that user does not own
self.login(ADMIN_ACCESS_USER)
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
data={"subscription_id": 11111},
expected_code=401,
)
def test_remove_sku_from_org(self):
self.login(ADMIN_ACCESS_USER)
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
data={"subscription_id": 12345},
expected_code=201,
)
self.deleteResponse(
resource_name=OrganizationRhSkuSubscriptionField,
params=dict(orgname=ORGANIZATION, subscription_id=12345),
expected_code=204,
)
json = self.getJsonResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=ORGANIZATION),
)
self.assertEqual(len(json), 0)
if __name__ == "__main__":
unittest.main()