From 4e67de999c7b7280c6262065c1ed7ecaac2b1c01 Mon Sep 17 00:00:00 2001 From: synkd Date: Mon, 2 Dec 2024 16:00:42 -0500 Subject: [PATCH] Get unit tests into passing state --- manifester/manifester.py | 15 ++++++++------- tests/test_manifester.py | 26 +++++++++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/manifester/manifester.py b/manifester/manifester.py index 1fabc0a..ae1a26c 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -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, @@ -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}"], @@ -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 diff --git a/tests/test_manifester.py b/tests/test_manifester.py index 3180395..ac7aa94 100644 --- a/tests/test_manifester.py +++ b/tests/test_manifester.py @@ -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, } @@ -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}", @@ -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.""" @@ -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(): @@ -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"]