Skip to content

Commit

Permalink
Merge pull request #1115 from golemfactory/blue/manifest-helper-fix
Browse files Browse the repository at this point in the history
fix the manifest helper
  • Loading branch information
shadeofblue authored Apr 3, 2023
2 parents b506c24 + 982a8c7 commit a4dee6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions tests/payload/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_manifest_parse_obj(manifest_obj, manifest_dict):


@mock.patch(
"yapapi.payload.manifest.datetime", **{"utcnow.return_value": datetime(2020, 1, 1, tzinfo=UTC)}
"yapapi.payload.manifest.datetime", **{"now.return_value": datetime(2020, 1, 1, tzinfo=UTC)}
)
def test_manifest_with_minimal_data(mocked_datetime):
payload_hash = "asd"
Expand All @@ -206,13 +206,13 @@ def test_manifest_with_minimal_data(mocked_datetime):
},
},
],
"version": "",
"version": "0.0.0",
}


@pytest.mark.asyncio
@mock.patch(
"yapapi.payload.manifest.datetime", **{"utcnow.return_value": datetime(2020, 1, 1, tzinfo=UTC)}
"yapapi.payload.manifest.datetime", **{"now.return_value": datetime(2020, 1, 1, tzinfo=UTC)}
)
@mock.patch(
"yapapi.payload.vm.repo",
Expand Down Expand Up @@ -270,13 +270,13 @@ async def test_manifest_generate(mocked_datetime):
},
},
},
"version": "",
"version": "0.0.0",
},
"created_at": "2020-01-01T00:00:00+00:00",
"expires_at": "2100-01-01T00:00:00+00:00",
"payload": [
{
"hash": payload_hash,
"hash": f"sha3:{payload_hash}",
"urls": [
payload_urls[0],
payload_urls[1],
Expand All @@ -289,7 +289,7 @@ async def test_manifest_generate(mocked_datetime):
},
},
],
"version": "",
"version": "0.0.0",
}


Expand Down
9 changes: 6 additions & 3 deletions yapapi/payload/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def parse_obj(cls, obj: Dict) -> "ManifestPayload":
async def resolve_urls_from_hash(self) -> None:
package = await vm.repo(image_hash=self.hash)

if ":" not in self.hash:
self.hash = f"sha3:{self.hash}"

full_url = await package.resolve_url()

image_url = full_url.split(":", 3)[3]
Expand Down Expand Up @@ -206,7 +209,7 @@ def parse_obj(cls, obj: Dict) -> "CompManifestNet":

@dataclass
class CompManifest:
version: str = ""
version: str = "0.0.0"
script: Optional[CompManifestScript] = None
net: Optional[CompManifestNet] = None

Expand Down Expand Up @@ -239,10 +242,10 @@ def parse_obj(cls, obj: Dict) -> "CompManifest":
@dataclass
class Manifest:
payload: List[ManifestPayload]
version: str = ""
version: str = "0.0.0"
comp_manifest: Optional[CompManifest] = None
# Using lambda helps with mocking in tests
created_at: datetime = field(default_factory=lambda: datetime.utcnow())
created_at: datetime = field(default_factory=lambda: datetime.now(UTC))
expires_at: datetime = datetime(2100, 1, 1, tzinfo=UTC)
metadata: Optional[ManifestMetadata] = None

Expand Down

0 comments on commit a4dee6b

Please sign in to comment.