Skip to content

Commit

Permalink
Merge pull request #894 from EvanBldy/main
Browse files Browse the repository at this point in the history
Various improvements
  • Loading branch information
EvanBldy authored Nov 29, 2024
2 parents 30c3a72 + b16bf86 commit e769360
Show file tree
Hide file tree
Showing 32 changed files with 132 additions and 184 deletions.
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install_requires =
discord.py==2.4.0
email-validator==2.2.0
ffmpeg-python==0.2.0
fido2==1.1.3
fido2==1.2.0
flasgger==0.9.7.1
flask_bcrypt==1.0.1
flask_caching==2.3.0
Expand All @@ -47,7 +47,7 @@ install_requires =
flask-migrate==4.0.7
flask-socketio==5.4.1
flask==3.1.0
gazu==0.10.19
gazu==0.10.20
gevent-websocket==0.10.1
gevent==24.11.1
gunicorn==23.0.0
Expand All @@ -56,7 +56,7 @@ install_requires =
Jinja2==3.1.4
ldap3==2.9.1
matterhook==0.2
meilisearch==0.31.6
meilisearch==0.32.0
numpy==2.0.1; python_version == '3.9'
numpy==2.1.3; python_version >= '3.10'
opencv-python==4.10.0.84
Expand All @@ -78,7 +78,7 @@ install_requires =
slackclient==2.9.4
sqlalchemy_utils==0.41.2
sqlalchemy==2.0.36
ua-parser==0.18.0
ua-parser==1.0.0
werkzeug==3.1.3

[options.package_data]
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_create_too_much_person(self):
"email": "[email protected]",
}
resp = self.post("data/persons", data, 400)
self.assertEqual(resp["limit"], 4)
self.assertEqual(resp["data"]["limit"], 4)
config.USER_LIMIT = 100

def test_create_person_with_no_data(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/projects/test_route_open_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_add_team_member(self):
"data/projects/%s/team" % self.project_id,
{"person_id": self.person_id},
)
project = projects_service.get_project_with_relations(self.project_id)
project = projects_service.get_project(self.project_id, relations=True)
self.assertEqual(project["team"], [str(self.person_id)])

def test_remove_team_member(self):
Expand All @@ -33,5 +33,5 @@ def test_remove_team_member(self):
self.delete(
"data/projects/%s/team/%s" % (self.project_id, self.person_id)
)
project = projects_service.get_project_with_relations(self.project_id)
project = projects_service.get_project(self.project_id, relations=True)
self.assertEqual(project["team"], [])
10 changes: 8 additions & 2 deletions tests/services/test_assets_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ def test_add_asset_link(self):
self.generate_fixture_asset_types()
self.generate_fixture_asset_character()
assets_service.add_asset_link(self.asset.id, self.asset_character.id)
asset = assets_service.get_asset_with_relations(self.asset.id)
asset = assets_service.get_asset(
self.asset.id,
relations=True,
)
self.assertEqual(
asset["entities_out"][0], str(self.asset_character.id)
)
Expand All @@ -198,5 +201,8 @@ def test_remove_asset_link(self):
assets_service.remove_asset_link(
self.asset.id, self.asset_character.id
)
asset = assets_service.get_asset_with_relations(self.asset.id)
asset = assets_service.get_asset(
self.asset.id,
relations=True,
)
self.assertEqual(len(asset["entities_out"]), 0)
16 changes: 8 additions & 8 deletions tests/services/test_projects_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ def test_update_project(self):
def test_add_team_member(self):
self.generate_fixture_person()
projects_service.add_team_member(self.project.id, self.person.id)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["team"], [str(self.person.id)])

def test_remove_team_member(self):
self.generate_fixture_person()
projects_service.add_team_member(self.project.id, self.person.id)
projects_service.remove_team_member(self.project.id, self.person.id)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["team"], [])

def test_add_asset_type_setting(self):
self.generate_fixture_asset_type()
projects_service.add_asset_type_setting(
self.project.id, self.asset_type.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["asset_types"], [str(self.asset_type.id)])

def test_remove_asset_type(self):
Expand All @@ -118,7 +118,7 @@ def test_remove_asset_type(self):
projects_service.remove_asset_type_setting(
self.project.id, self.asset_type.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["asset_types"], [])

def test_add_task_type_setting(self):
Expand All @@ -127,7 +127,7 @@ def test_add_task_type_setting(self):
projects_service.add_task_type_setting(
self.project.id, self.task_type.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["task_types"], [str(self.task_type.id)])

def test_remove_task_type(self):
Expand All @@ -139,15 +139,15 @@ def test_remove_task_type(self):
projects_service.remove_task_type_setting(
self.project.id, self.task_type.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["task_types"], [])

def test_add_task_status_setting(self):
self.generate_fixture_task_status()
projects_service.add_task_status_setting(
self.project.id, self.task_status.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["task_statuses"], [str(self.task_status.id)])

def test_remove_task_status(self):
Expand All @@ -158,7 +158,7 @@ def test_remove_task_status(self):
projects_service.remove_task_status_setting(
self.project.id, self.task_status.id
)
project = projects_service.get_project_with_relations(self.project.id)
project = projects_service.get_project(self.project.id, relations=True)
self.assertEqual(project["task_statuses"], [])

def test_add_asset_metadata_descriptor(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/services/test_tasks_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_clear_assignation(self):
task_id = self.task.id
tasks_service.assign_task(self.task.id, self.person.id)
tasks_service.clear_assignation(task_id)
task = tasks_service.get_task_with_relations(task_id)
task = tasks_service.get_task(task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)

def test_get_tasks_for_person(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/services/test_user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_check_project_access(self):
projects_service.add_team_member(
str(self.project.id), str(self.get_current_user_raw().id)
)
projects_service.get_project_with_relations(self.project_id)
projects_service.get_project(self.project_id, relations=True)
self.assertTrue(
user_service.check_project_access(str(self.project_id))
)
Expand Down
5 changes: 4 additions & 1 deletion tests/source/shotgun/test_shotgun_import_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def test_import_asset(self):

assets = sorted(self.assets, key=lambda x: x["name"])
asset = assets[0]
asset = assets_service.get_asset_with_relations(asset["id"])
asset = assets_service.get_asset(
asset["id"],
relations=True,
)
project = Project.get_by(shotgun_id=sg_asset["project"]["id"])
self.assertEqual(asset["description"], sg_asset["description"])
self.assertEqual(asset["shotgun_id"], sg_asset["id"])
Expand Down
5 changes: 4 additions & 1 deletion tests/source/shotgun/test_shotgun_import_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def test_import_shot(self):
self.assertEqual(len(self.shots), 1)

shot = self.shots[0]
shot = shots_service.get_shot_with_relations(shot["id"])
shot = shots_service.get_shot(
shot["id"],
relations=True,
)
sequence = Entity.get_by(
shotgun_id=self.sg_shot["sg_sequence"]["id"],
entity_type_id=shots_service.get_sequence_type()["id"],
Expand Down
5 changes: 4 additions & 1 deletion tests/source/shotgun/test_shotgun_import_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def test_import_task(self):
self.assertEqual(len(self.tasks), 1)

task = self.tasks[0]
task = tasks_service.get_task_with_relations(task["id"])
task = tasks_service.get_task(
task["id"],
relations=True,
)
project = Project.get_by(name=self.sg_task["project"]["name"])
task_type = TaskType.get_by(name=self.sg_task["step"]["name"])
task_status = TaskStatus.get_by(
Expand Down
20 changes: 12 additions & 8 deletions tests/source/shotgun/test_shotgun_import_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def test_import_project_connections(self):
self.load_fixture("projects")
self.load_fixture("projectconnections")
projects = self.get("data/projects")
project = projects_service.get_project_with_relations(
projects[0]["id"]
project = projects_service.get_project(
projects[0]["id"],
relations=True,
)
self.assertEqual(len(project["team"]), 1)
project = projects_service.get_project_with_relations(
projects[1]["id"]
project = projects_service.get_project(
projects[1]["id"],
relations=True,
)
self.assertEqual(len(project["team"]), 2)

Expand All @@ -26,8 +28,9 @@ def test_import_projects_twice(self):
self.load_fixture("projectconnections")
self.load_fixture("projectconnections")
projects = self.get("data/projects")
project = projects_service.get_project_with_relations(
projects[0]["id"]
project = projects_service.get_project(
projects[0]["id"],
relations=True,
)
self.assertEqual(len(project["team"]), 2)

Expand All @@ -46,7 +49,8 @@ def test_import_project_connection(self):
self.assertEqual(len(self.projects), 1)

projects = self.get("data/projects")
project = projects_service.get_project_with_relations(
projects[1]["id"]
project = projects_service.get_project(
projects[1]["id"],
relations=True,
)
self.assertEqual(len(project["team"]), 1)
16 changes: 8 additions & 8 deletions tests/tasks/test_route_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def test_multiple_task_assign(self):
data = {"task_ids": [task_id, shot_task_id]}
self.put("/actions/persons/%s/assign" % person_id, data)

task = tasks_service.get_task_with_relations(task_id)
task = tasks_service.get_task(task_id, relations=True)
self.assertEqual(len(task["assignees"]), 1)
task = tasks_service.get_task_with_relations(shot_task_id)
task = tasks_service.get_task(shot_task_id, relations=True)
self.assertEqual(len(task["assignees"]), 1)
notifications = notifications_service.get_last_notifications()
self.assertEqual(len(notifications), 2)
Expand All @@ -143,15 +143,15 @@ def test_multiple_task_assign_artist(self):
self.put("/actions/tasks/clear-assignation", data)
self.log_in_cg_artist()
self.put("/actions/persons/%s/assign" % person_id, data)
task = tasks_service.get_task_with_relations(task_id)
task = tasks_service.get_task(task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)
task = tasks_service.get_task_with_relations(shot_task_id)
task = tasks_service.get_task(shot_task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)
persons_service.add_to_department(department_id, person_id)
self.put("/actions/persons/%s/assign" % person_id, data)
task = tasks_service.get_task_with_relations(task_id)
task = tasks_service.get_task(task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)
task = tasks_service.get_task_with_relations(shot_task_id)
task = tasks_service.get_task(shot_task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)

def test_clear_assignation(self):
Expand All @@ -164,9 +164,9 @@ def test_clear_assignation(self):
data = {"task_ids": [task_id, shot_task_id]}
self.put("/actions/tasks/clear-assignation", data)

task = tasks_service.get_task_with_relations(task_id)
task = tasks_service.get_task(task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)
task = tasks_service.get_task_with_relations(shot_task_id)
task = tasks_service.get_task(shot_task_id, relations=True)
self.assertEqual(len(task["assignees"]), 0)

def test_comment_task(self):
Expand Down
4 changes: 2 additions & 2 deletions zou/app/blueprints/comments/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ def get_allowed_comments_only(self, comments, person):
allowed_comments = []
for comment in comments:
try:
task = tasks_service.get_task_with_relations(
comment["object_id"],
task = tasks_service.get_task(
comment["object_id"], relations=True
)
if (
person["role"] == "supervisor"
Expand Down
26 changes: 7 additions & 19 deletions zou/app/blueprints/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from zou.app.utils import events, fields, permissions, query
from zou.app.services.exception import (
WrongParameterException,
WrongParameterException,
)


Expand Down Expand Up @@ -259,14 +258,6 @@ def post(self):
current_app.logger.error(str(exception), exc_info=1)
return {"message": str(exception)}, 400

except WrongParameterException as exception:
current_app.logger.error(str(exception), exc_info=1)
return (
exception.dict
if exception.dict is not None
else {"message": str(exception)}
), 400

def emit_create_event(self, instance_dict):
return events.emit(
"%s:new" % self.model.__tablename__.replace("_", "-"),
Expand All @@ -290,6 +281,10 @@ def get_model_or_404(self, instance_id):
abort(404)
return instance

def get_serialized_instance(self, instance_id, relations=True):
instance = self.get_model_or_404(instance_id)
return self.serialize_instance(instance, relations=relations)

def check_read_permissions(self, instance_dict):
return permissions.check_admin_permissions()

Expand Down Expand Up @@ -338,8 +333,9 @@ def get(self, instance_id):
"""
relations = self.get_bool_parameter("relations", "true")
try:
instance = self.get_model_or_404(instance_id)
result = self.serialize_instance(instance, relations=relations)
result = self.get_serialized_instance(
instance_id, relations=relations
)
self.check_read_permissions(result)
result = self.clean_get_result(result)

Expand Down Expand Up @@ -430,14 +426,6 @@ def put(self, instance_id):
current_app.logger.error(str(exception), exc_info=1)
return {"message": str(exception)}, 400

except WrongParameterException as exception:
current_app.logger.error(str(exception), exc_info=1)
return (
exception.dict
if exception.dict is not None
else {"message": str(exception)}
), 400

@jwt_required()
def delete(self, instance_id):
"""
Expand Down
Loading

0 comments on commit e769360

Please sign in to comment.