Skip to content

Commit

Permalink
[qa] black
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBldy committed Jul 11, 2024
1 parent 5afc443 commit 41f8c7b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 87 deletions.
46 changes: 12 additions & 34 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,7 @@ def generate_fixture_task_standard(self):
return self.task_standard

def generate_fixture_shot_task(
self,
name="Master",
shot_id=None,
task_type_id=None
self, name="Master", shot_id=None, task_type_id=None
):
if task_type_id is None:
task_type_id = self.task_type_animation.id
Expand Down Expand Up @@ -1087,10 +1084,7 @@ def generate_shot_suite(self):
self.generate_fixture_shot()
self.generate_fixture_scene()

def generate_fixture_shot_tasks_and_previews(
self,
task_type_id
):
def generate_fixture_shot_tasks_and_previews(self, task_type_id):
episode_01 = self.episode
sequence_01 = self.sequence
shot_01 = self.shot
Expand All @@ -1106,50 +1100,34 @@ def generate_fixture_shot_tasks_and_previews(
)

task_shot_01 = self.generate_fixture_shot_task(
shot_id=shot_01.id,
task_type_id=task_type_id
shot_id=shot_01.id, task_type_id=task_type_id
)
task_shot_02 = self.generate_fixture_shot_task(
shot_id=shot_02.id,
task_type_id=task_type_id
shot_id=shot_02.id, task_type_id=task_type_id
)
task_shot_03 = self.generate_fixture_shot_task(
shot_id=shot_03.id,
task_type_id=task_type_id
shot_id=shot_03.id, task_type_id=task_type_id
)
task_shot_e201 = self.generate_fixture_shot_task(
shot_id=shot_e201.id,
task_type_id=task_type_id
shot_id=shot_e201.id, task_type_id=task_type_id
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=1,
duration=15
task_id=task_shot_01.id, revision=1, duration=15
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=2,
duration=25
task_id=task_shot_01.id, revision=2, duration=25
)
preview_01 = self.generate_fixture_preview_file(
task_id=task_shot_01.id,
revision=3,
duration=30
task_id=task_shot_01.id, revision=3, duration=30
)
preview_02 = self.generate_fixture_preview_file(
task_id=task_shot_02.id,
revision=1,
duration=20
task_id=task_shot_02.id, revision=1, duration=20
)
preview_03 = self.generate_fixture_preview_file(
task_id=task_shot_03.id,
revision=1,
duration=10
task_id=task_shot_03.id, revision=1, duration=10
)
preview_e201 = self.generate_fixture_preview_file(
task_id=task_shot_e201.id,
revision=1,
duration=40
task_id=task_shot_e201.id, revision=1, duration=40
)
return (
episode_01,
Expand Down
13 changes: 4 additions & 9 deletions tests/services/test_shots_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,10 @@ def test_set_frames_from_task_type_previews(self):
preview_02,
preview_03,
preview_e201,
) = self.generate_fixture_shot_tasks_and_previews(
task_type_id
)
) = self.generate_fixture_shot_tasks_and_previews(task_type_id)

shots_service.set_frames_from_task_type_preview_files(
project_id,
task_type_id,
episode_id=episode_01.id
project_id, task_type_id, episode_id=episode_01.id
)

self.assertEqual(
Expand All @@ -301,8 +297,7 @@ def test_set_frames_from_task_type_previews(self):
self.assertEqual(shot_e201["nb_frames"], 0)

shots_service.set_frames_from_task_type_preview_files(
project_id,
task_type_id
project_id, task_type_id
)
shot_e201 = shots_service.get_shot(shot_e201["id"])
self.assertEqual(shot_e201["nb_frames"], 1000)
self.assertEqual(shot_e201["nb_frames"], 1000)
46 changes: 22 additions & 24 deletions tests/shots/test_shots.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,35 +183,30 @@ def test_set_frames_from_task_type_previews(self):
preview_e201,
) = self.generate_fixture_shot_tasks_and_previews(task_type_id)


self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
"wrong-id",
task_type_id,
str(episode_01.id)
), {}, 400
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s"
% ("wrong-id", task_type_id, str(episode_01.id)),
{},
400,
)
self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
"wrong-id",
str(episode_01.id)
), {}, 400
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s"
% (project_id, "wrong-id", str(episode_01.id)),
{},
400,
)

self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
task_type_id,
"wrong-id"
), {}, 400
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s"
% (project_id, task_type_id, "wrong-id"),
{},
400,
)
self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s" % (
project_id,
task_type_id,
str(episode_01.id)
), {}, 200
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=%s"
% (project_id, task_type_id, str(episode_01.id)),
{},
200,
)
shot_01 = shots_service.get_shot(shot_01.id)
shot_02 = shots_service.get_shot(shot_02.id)
Expand All @@ -223,10 +218,13 @@ def test_set_frames_from_task_type_previews(self):
self.assertEqual(shot_e201["nb_frames"], 0)

self.post(
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id=" % (
"actions/projects/%s/task-types/%s/set-shot-nb-frames?episode_id="
% (
project_id,
task_type_id,
), {}, 200
),
{},
200,
)
shot_e201 = shots_service.get_shot(shot_e201["id"])
self.assertEqual(shot_e201["nb_frames"], 1000)
self.assertEqual(shot_e201["nb_frames"], 1000)
2 changes: 1 addition & 1 deletion zou/app/blueprints/shots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
(
"/actions/projects/<project_id>/task-types/<task_type_id>/set-shot-nb-frames",
SetShotsFramesResource,
)
),
]


Expand Down
9 changes: 4 additions & 5 deletions zou/app/blueprints/shots/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,6 @@ def get(self, project_id, task_type_id):
)



class SetShotsFramesResource(Resource, ArgsMixin):
@jwt_required()
def post(self, project_id, task_type_id):
Expand Down Expand Up @@ -1558,13 +1557,13 @@ def post(self, project_id, task_type_id):
description: Frames set for given shots
"""
user_service.check_manager_project_access(project_id)
if not fields.is_valid_id(task_type_id) or \
not fields.is_valid_id(project_id):
if not fields.is_valid_id(task_type_id) or not fields.is_valid_id(
project_id
):
raise WrongParameterException("Invalid project or task type id")

episode_id = self.get_episode_id()
if not episode_id in ["", None] and \
not fields.is_valid_id(episode_id):
if not episode_id in ["", None] and not fields.is_valid_id(episode_id):
raise WrongParameterException("Invalid episode id")

if episode_id == "":
Expand Down
29 changes: 15 additions & 14 deletions zou/app/services/shots_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ def set_frames_from_task_type_preview_files(
subquery = (
db.session.query(
Shot.id.label("entity_id"),
func.max(PreviewFile.created_at).label("max_created_at")
func.max(PreviewFile.created_at).label("max_created_at"),
)
.join(Task, PreviewFile.task_id == Task.id)
.join(Shot, Task.entity_id == Shot.id)
Expand All @@ -1559,7 +1559,7 @@ def set_frames_from_task_type_preview_files(
subquery = (
db.session.query(
Shot.id.label("entity_id"),
func.max(PreviewFile.created_at).label("max_created_at")
func.max(PreviewFile.created_at).label("max_created_at"),
)
.join(Task, PreviewFile.task_id == Task.id)
.join(Shot, Task.entity_id == Shot.id)
Expand All @@ -1571,28 +1571,29 @@ def set_frames_from_task_type_preview_files(
)

query = (
db.session.query(
Shot,
PreviewFile.duration
)
db.session.query(Shot, PreviewFile.duration)
.join(Task, Task.entity_id == Shot.id)
.join(subquery, (Shot.id == subquery.c.entity_id))
.join(PreviewFile,
(PreviewFile.task_id == Task.id) &
(PreviewFile.created_at == subquery.c.max_created_at))
.join(
PreviewFile,
(PreviewFile.task_id == Task.id)
& (PreviewFile.created_at == subquery.c.max_created_at),
)
.filter(Task.task_type_id == task_type_id)
.filter(Shot.project_id == project_id)
)

results = query.all()
project = projects_service.get_project(project_id)
updates = []
for (shot, preview_duration) in results:
for shot, preview_duration in results:
nb_frames = round(preview_duration * int(project["fps"]))
updates.append({
"id": shot.id,
"nb_frames": nb_frames,
})
updates.append(
{
"id": shot.id,
"nb_frames": nb_frames,
}
)
clear_shot_cache(str(shot.id))

db.session.bulk_update_mappings(Shot, updates)
Expand Down

0 comments on commit 41f8c7b

Please sign in to comment.