Skip to content

Commit

Permalink
fix unit-test, teardown method depends on order of tests in file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcusk19 committed Nov 7, 2024
1 parent c20820f commit d0d8100
Showing 1 changed file with 37 additions and 46 deletions.
83 changes: 37 additions & 46 deletions test/test_api_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5185,6 +5185,38 @@ def test_delete_message(self):
self.assertEqual(len(json["messages"]), 1)


class TestUserSku(ApiTestCase):
def test_get_user_skus(self):
self.login(SUBSCRIPTION_USER)
json = self.getJsonResponse(UserSkuList)
self.assertEqual(len(json), 3)

def test_quantity(self):
self.login(SUBSCRIPTION_USER)
subscription_user = model.user.get_user(SUBSCRIPTION_USER)
plans = check_internal_api_for_subscription(subscription_user)
assert len(plans) == 13

def test_split_sku(self):
self.login(SUBSCRIPTION_USER)
user = model.user.get_user(SUBSCRIPTION_USER)
org = model.organization.get_organization(SUBSCRIPTION_ORG)
model.organization_skus.bind_subscription_to_org(80808080, org.id, user.id, 3)

user_subs = self.getJsonResponse(resource_name=UserSkuList)

unassigned_sub = None
assigned_sub = None
for sub in user_subs:
if sub["id"] == 80808080 and sub["assigned_to_org"] is None:
unassigned_sub = sub
elif sub["id"] == 80808080 and sub["assigned_to_org"] is not None:
assigned_sub = sub
self.assertIsNotNone(unassigned_sub, "Could not find unassigned remaining subscription")
self.assertIsNotNone(assigned_sub, "Could not find assigned subscription")
self.assertEqual(7, unassigned_sub["quantity"])


class TestOrganizationRhSku(ApiTestCase):
def test_bind_sku_to_org(self):
self.login(SUBSCRIPTION_USER)
Expand Down Expand Up @@ -5329,60 +5361,19 @@ def test_splittable_sku(self):
data={"subscriptions": [{"subscription_id": 80808080, "quantity": 3}]},
expected_code=201,
)
org_subs = self.getJsonResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=SUBSCRIPTION_ORG),
)
self.assertEqual(org_subs[0]["quantity"], 3)

def test_splittable_quantity(self):
self.login(SUBSCRIPTION_USER)
user = model.user.get_user(SUBSCRIPTION_USER)
org = model.organization.get_organization(SUBSCRIPTION_ORG)
model.organization_skus.bind_subscription_to_org(80808080, org.id, user.id, 5)
# try to attach more than is given after binding a subscription to
# an org
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=SUBSCRIPTION_ORG),
data={"subscriptions": [{"subscription_id": 80808080, "quantity": 10}]},
expected_code=400,
)


class TestUserSku(ApiTestCase):
def test_get_user_skus(self):
self.login(SUBSCRIPTION_USER)
json = self.getJsonResponse(UserSkuList)
self.assertEqual(len(json), 3)

def test_quantity(self):
self.login(SUBSCRIPTION_USER)
# make sure there are no bound orgs from pervious splittable test
org = model.organization.get_organization(SUBSCRIPTION_ORG)
model.organization_skus.remove_subscription_from_org(org.id, 80808080)
subscription_user = model.user.get_user(SUBSCRIPTION_USER)
plans = check_internal_api_for_subscription(subscription_user)
assert len(plans) == 13

def test_split_sku(self):
self.login(SUBSCRIPTION_USER)
user = model.user.get_user(SUBSCRIPTION_USER)
org = model.organization.get_organization(SUBSCRIPTION_ORG)
model.organization_skus.bind_subscription_to_org(80808080, org.id, user.id, 3)

user_subs = self.getJsonResponse(resource_name=UserSkuList)

unassigned_sub = None
assigned_sub = None
for sub in user_subs:
if sub["id"] == 80808080 and sub["assigned_to_org"] is None:
unassigned_sub = sub
elif sub["id"] == 80808080 and sub["assigned_to_org"] is not None:
assigned_sub = sub
self.assertIsNotNone(unassigned_sub, "Could not find unassigned remaining subscription")
self.assertIsNotNone(assigned_sub, "Could not find assigned subscription")
self.assertEqual(7, unassigned_sub["quantity"])
org_subs = self.getJsonResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=SUBSCRIPTION_ORG),
)
self.assertEqual(org_subs[0]["quantity"], 3)


if __name__ == "__main__":
Expand Down

0 comments on commit d0d8100

Please sign in to comment.