Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Resource Distributor to enable name change #1221

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
modify test for resource distributor
need to be tested locally
homework36 committed Nov 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e0a9c2a6238913f6008ade0cc4e94c495684cfa9
44 changes: 29 additions & 15 deletions rodan-main/code/rodan/jobs/resource_distributor.py
Original file line number Diff line number Diff line change
@@ -176,27 +176,38 @@ def test_my_task(self, testcase):
import PIL.Image
import numpy as np
resource_types_list = list(map(lambda rt: str(rt.mimetype), ResourceType.objects.all()))
from model_mommy import mommy
from rodan.models import Resource, ResourceType

# Create a Resource instance using mommy
resource_type = mommy.make(ResourceType, mimetype="image/rgb+png")
rc = mommy.make(Resource, resource_type=resource_type)

# Not so sure what this job is for, but I'll use image/png as the testcase.
inputs = {
"Resource input": [
{
'resource_type': 'image/rgb+png',
'resource_path': testcase.new_available_path()
"Resource input": [
{
"resource_path": rc.resource_path,
"resource_type": rc.resource_type.mimetype,
"resource": rc
}
]
}
]
}
outputs = {
"Resource output": [
{
"resource_type": "image/rgb+png",
"resource_path": testcase.new_available_path()
"Resource output": [
{
"resource_type": "image/rgb+png",
"resource_path": testcase.new_available_path()
}
]
}
]
}
settings = {
"Resource type": resource_types_list.index("image/rgb+png")
}
"Resource type": resource_types_list.index("image/rgb+png"),
"User custom prefix": "test prefix - ",
"User custom suffix": "- test suffix"
}

original_image = rc.name

PIL.Image.new("RGB", size=(50, 50), color=(255, 0, 0)).save(inputs['Resource input'][0]['resource_path'], 'PNG')
array_gt = np.zeros((50, 50, 3)).astype(np.uint8)
array_gt[:, :, 0] = 255
@@ -211,3 +222,6 @@ def test_my_task(self, testcase):
testcase.assertEqual(result.format, 'PNG')
# and the data should be identical
np.testing.assert_equal(array_gt, array_result)

new_name = f"{settings['User custom prefix']}{original_image}{settings['User custom suffix']}"
testcase.assertEqual(inputs['Resource input'][0]['resource'].name, new_name)