Skip to content

Commit

Permalink
Get unit tests into passing state
Browse files Browse the repository at this point in the history
  • Loading branch information
synkd committed Dec 2, 2024
1 parent 6352bbe commit 4e67de9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
15 changes: 8 additions & 7 deletions manifester/manifester.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def create_subscription_allocation(self):
cmd_kwargs=allocation_data,
).json()
logger.debug(f"Received response {self.allocation} when attempting to create allocation.")
self.allocation_uuid = self.allocation["body"]["uuid"]
self.allocation_uuid = (
self.allocation.uuid if self.is_mock else self.allocation["body"]["uuid"]
)
if self.simple_content_access == "disabled":
simple_retry(
self.requester.put,
Expand All @@ -196,8 +198,6 @@ def delete_subscription_allocation(self, uuid=None):
"proxies": self.manifest_data.get("proxies"),
"params": {"force": "true"},
}
if self.is_mock:
self.allocation_uuid = self.allocation_uuid.uuid
response = simple_retry(
self.requester.delete,
cmd_args=[f"{self.allocations_url}/{uuid if uuid else self.allocation_uuid}"],
Expand Down Expand Up @@ -407,10 +407,11 @@ def trigger_manifest_export(self):
local_file.write_bytes(manifest.content)
manifest.path = local_file
manifest.name = self.manifest_name
if self.is_mock:
manifest.uuid = self.allocation_uuid.uuid
else:
manifest.uuid = self.allocation_uuid
# if self.is_mock:
# manifest.uuid = self.allocation_uuid.uuid
# else:
# manifest.uuid = self.allocation_uuid
manifest.uuid = self.allocation_uuid
update_inventory(self.subscription_allocations, uuid=self.allocation_uuid)
return manifest

Expand Down
26 changes: 19 additions & 7 deletions tests/test_manifester.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@
+ "".join(random.choices(string.ascii_letters, k=8)),
"type": "Satellite",
"version": f"{MANIFEST_DATA['sat_version']}",
"entitlementQuantity": sum(d["quantity"] for d in MANIFEST_DATA["subscription_data"]),
"url": f"{MANIFEST_DATA['url']['allocations']}/{SUB_ALLOCATION_UUID}",
"entitlementsAttachedQuantity": sum(
d["quantity"] for d in MANIFEST_DATA["subscription_data"]
),
# "url": f"{MANIFEST_DATA['url']['allocations']}/{SUB_ALLOCATION_UUID}",
"simpleContentAccess": f"{MANIFEST_DATA['simple_content_access']}",
}
]
],
"status_code": 200,
}


Expand Down Expand Up @@ -148,9 +151,9 @@ def get(self, *args, **kwargs):
self.pool_response["body"] += SUB_POOL_RESPONSE["body"]
return self
if args[0].endswith("allocations") and self._has_offset:
if kwargs["params"]["offset"] != 50:
if kwargs["params"]["offset"] != 100:
self.allocations_response = {"body": []}
for _x in range(50):
for _x in range(100):
self.allocations_response["body"].append(
{
"uuid": f"{uuid.uuid4().hex}",
Expand Down Expand Up @@ -197,6 +200,15 @@ def delete(self, *args, **kwargs):
self._good_codes = [204]
return self

def __repr__(self):
"""Return a string representation of the RhsmApiStub instance."""
inner = ", ".join(
f"{k}={v}"
for k, v in self.__dict__.items()
if not k.startswith("_") and not callable(v)
)
return f"{self.__class__.__name__}({inner})"


def test_basic_init():
"""Test that manifester can initialize with the minimum required arguments."""
Expand All @@ -211,7 +223,7 @@ def test_create_allocation():
"""Test that manifester's create_subscription_allocation method returns a UUID."""
manifester = Manifester(manifest_category=MANIFEST_DATA, requester=RhsmApiStub(in_dict=None))
allocation_uuid = manifester.create_subscription_allocation()
assert allocation_uuid.uuid == SUB_ALLOCATION_UUID
assert allocation_uuid == SUB_ALLOCATION_UUID


def test_negative_simple_retry_timeout():
Expand Down Expand Up @@ -300,7 +312,7 @@ def test_invalid_sat_version():
def test_update_inventory():
"""Test that inventory file is populated with expected contents after updating."""
manifester = Manifester(manifest_category=MANIFEST_DATA, requester=RhsmApiStub(in_dict=None))
update_inventory(manifester.subscription_allocations)
update_inventory(manifester.subscription_allocations, sync=True, uuid=SUB_ALLOCATION_UUID)
assert (
load_inventory_file(Path(MANIFEST_DATA["inventory_path"]))
== SUB_ALLOCATIONS_RESPONSE["body"]
Expand Down

0 comments on commit 4e67de9

Please sign in to comment.