def test_import_task(self): self.load_task() self.assertEqual(len(self.tasks), 1) self.tasks = self.get("data/tasks") self.assertEqual(len(self.tasks), 1) task = self.tasks[0] task = tasks_service.get_task_with_relations(task["id"]) 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( short_name=self.sg_task["sg_status_list"]) assets = assets_service.get_assets( {"shotgun_id": self.sg_task["entity"]["id"]}) entity = assets[0] assigner = Person.get_by( last_name=self.sg_task["created_by"]["name"].split(" ")[1]) assignee = Person.get_by( last_name=self.sg_task["task_assignees"][0]["name"].split(" ")[1]) self.assertEqual(task["name"], self.sg_task["cached_display_name"]) self.assertEqual(task["duration"], self.sg_task["duration"]) self.assertEqual(task["shotgun_id"], self.sg_task["id"]) self.assertEqual(task["project_id"], str(project.id)) self.assertEqual(task["task_type_id"], str(task_type.id)) self.assertEqual(task["task_status_id"], str(task_status.id)) self.assertEqual(task["entity_id"], entity["id"]) self.assertEqual(task["assigner_id"], str(assigner.id)) self.assertEqual(task["assignees"][0], str(assignee.id))
def generate_fixture_person(self): self.person = Person(first_name="John", last_name="Doe", desktop_login="******", email=u"*****@*****.**", password=auth.encrypt_password("mypassword")) self.person.save()
def test_person(self): person_dict = { "departments": [ ], "id": "b86127df-909b-4bc2-983e-a959ea5a7319", "created_at": "2019-06-29T15:05:22", "updated_at": "2019-06-29T15:05:22", "first_name": "John", "last_name": "Doe", "email": "*****@*****.**", "phone": "", "active": True, "desktop_login": "", "timezone": "Europe/Paris", "locale": "en_US", "role": "user", "has_avatar": True, "notifications_enabled": False, "notifications_slack_enabled": False, "notifications_slack_userid": None, "type": "Person", "full_name": "John Doe" } Person.create_from_import(person_dict) person = Person.get(person_dict["id"]) self.assertEqual(person.first_name, person_dict["first_name"])
def test_serialize_orm_array(self): person = Person( id=uuid.uuid4(), first_name="Jhon", last_name="Doe" ) person2 = Person( id=uuid.uuid4(), first_name="Emma", last_name="Peel" ) task = Task( id=uuid.uuid4(), name="Test Task", assignees=[person, person2] ) is_id = str(person.id) in fields.serialize_orm_arrays(task.assignees) self.assertTrue(is_id) is_id = str(person2.id) in fields.serialize_orm_arrays(task.assignees) self.assertTrue(is_id) is_id = str(person.id) in fields.serialize_value(task.assignees) self.assertTrue(is_id) is_id = str(person2.id) in fields.serialize_value(task.assignees) self.assertTrue(is_id)
def create_person(email, password, first_name, last_name): person = Person(email=email, password=password, first_name=first_name, last_name=last_name) person.save() return person
def import_row(self, row): first_name = row["First Name"] last_name = row["Last Name"] email = row["Email"] phone = row.get("Phone", None) role = row.get("Role", None) role_map = { "Studio Manager": "admin", "Production Manager": "manager", "Supervisor": "supervisor", "Artist": "user", "Client": "client", "Vendor": "vendor", } data = {"first_name": first_name, "last_name": last_name} if role is not None and role != "": if role in role_map.keys(): role = role_map[role] data["role"] = role if phone is not None and phone != "": data["phone"] = phone person = Person.get_by(email=email) if person is None: data["email"] = email data["password"] = auth.encrypt_password("default") person = Person.create(**data) elif self.is_update: person.update(data) index_service.index_person(person) return person.serialize_safe()
def generate_fixture_person(self, first_name="John", last_name="Doe", desktop_login="******", email="*****@*****.**"): self.person = Person.get_by(email=email) if self.person is None: self.person = Person.create( first_name=first_name, last_name=last_name, desktop_login=desktop_login, email=email, password=auth.encrypt_password("mypassword")) return self.person
def prepare_import(self): self.project_ids = Project.get_id_map() self.person_ids = Person.get_id_map() self.task_type_ids = TaskType.get_id_map(field="name") self.task_status_ids = TaskStatus.get_id_map(field="short_name") self.asset_ids = self.get_asset_map() self.shot_ids = self.get_shot_map()
def update_person(person_id, data): """ Update person entry with data given in parameter. """ person = Person.get(person_id) person.update(data) return person.serialize()
def generate_fixture_user(self): self.user = Person.create(first_name="John", last_name="Did", role="admin", email=u"*****@*****.**", password=auth.encrypt_password("mypassword")) return self.user
def test_create_person_with_departments(self): self.generate_fixture_department() departments = [ str(department.id) for department in Department.query.all() ] data = { "first_name": "John2", "last_name": "Doe", "email": "*****@*****.**", "departments": departments, } person = self.post("data/persons/new", data) self.assertIsNotNone(person["id"]) self.assertEquals( set(person["departments"]), set(departments), ) created_person = Person.get(person["id"]) self.assertEquals( set( str(department.id) for department in created_person.departments ), set(departments), )
def test_import_version(self): sg_version = { "code": "S01_Animation", "description": "description test", "id": 2, "user": { "id": 1, "name": "Jhon Doe", "type": "HumanUser" }, "entity": { "id": 1, "name": "SH01", "type": "Shot" }, "project": { "id": 1, "name": "Cosmos Landromat", "type": "Project" }, "sg_task": { "id": 1, "name": "Animation", "type": "Task" }, "sg_uploaded_movie": { "content_type": "video/mp4", "id": 1, "link_type": "upload", "name": "movie_new.mp4", "type": "Attachment", "url": "https://sg-media.amazonaws.com/9e73/movie_new.mp4" }, "type": "Version" } api_path = "/import/shotgun/versions" self.preview_files = self.post(api_path, [sg_version], 200) self.assertEqual(len(self.preview_files), 1) self.preview_files = self.get("data/preview-files") self.assertEqual(len(self.preview_files), 1) preview_file = self.preview_files[0] task = Task.get_by(shotgun_id=sg_version["sg_task"]["id"]) person = Person.get_by(shotgun_id=sg_version["user"]["id"]) self.assertEqual(preview_file["name"], sg_version["code"]) self.assertEqual(preview_file["source"], "Shotgun") self.assertEqual(preview_file["task_id"], str(task.id)) self.assertEqual(preview_file["name"], sg_version["code"]) self.assertEqual(preview_file["description"], sg_version["description"]) self.assertEqual(preview_file["shotgun_id"], sg_version["id"]) self.assertEqual(preview_file["uploaded_movie_url"], sg_version["sg_uploaded_movie"]["url"]) self.assertEqual(preview_file["uploaded_movie_url"], sg_version["sg_uploaded_movie"]["url"]) self.assertEqual(preview_file["person_id"], str(person.id))
def create_person( email, password, first_name, last_name, phone="", role="user", desktop_login="", ): """ Create a new person entry in the database. No operation are performed on password, so encrypted password is expected. """ if email is not None: email = email.strip() person = Person.create( email=email, password=password, first_name=first_name, last_name=last_name, phone=phone, role=role, desktop_login=desktop_login, ) events.emit("person:new", {"person_id": person.id}) clear_person_cache() return person.serialize()
def to_review_task(task, output_file_dict): to_review_status = get_to_review_status() task_dict_before = task.serialize() task.update({"task_status_id": to_review_status.id}) task.save() project = Project.get(task.project_id) entity = Entity.get(task.entity_id) entity_type = EntityType.get(entity.entity_type_id) person = Person.get(output_file_dict["person_id"]) task_dict_after = task.serialize() task_dict_after["output_file"] = output_file_dict task_dict_after["project"] = project.serialize() task_dict_after["entity"] = entity.serialize() task_dict_after["entity_type"] = entity_type.serialize() task_dict_after["person"] = person.serialize() events.emit("task:to-review", { "task_before": task_dict_before, "task_after": task_dict_after }) return task
def test_present(self): person = self.get_first("data/persons") person_model = Person.get(person["id"]) person_dict = person_model.present_minimal() self.assertEquals(person_dict["departments"], []) person_dict = person_model.present_minimal(relations=True) self.assertEquals(person_dict["departments"], [])
def import_row(self, row): first_name = row["First Name"] last_name = row["Last Name"] email = row["Email"] phone = row["Phone"] role = row.get("Role", None) if role == "Studio Manager": role = "admin" elif role == "Supervisor": role = "manager" elif role == "Client": role = "client" if ( role is not None and len(role) > 0 and role not in ["admin", "manager"] ): role = "user" try: password = auth.encrypt_password("default") person = Person.get_by(email=email) if person is None: person = Person.create( email=email, password=password, first_name=first_name, last_name=last_name, phone=phone, role=role, ) else: data = { "first_name": first_name, "last_name": last_name, "phone": phone, } if role is not None and len(role) > 0: data["role"] = role person.update(data) except IntegrityError: person = Person.get_by(email=email) return person.serialize_safe()
def import_row(self, row): first_name = row["First Name"] last_name = row["Last Name"] email = row["Email"] phone = row["Phone"] try: password = auth.encrypt_password("default") person = Person.create(email=email, password=password, first_name=first_name, last_name=last_name, phone=phone) except IntegrityError: person = Person.get_by(email=email) return person
def delete_person(person_id): """ Delete person entry from database. """ person = Person.get(person_id) person_dict = person.serialize() person.delete() return person_dict
def generate_fixture_user_cg_artist(self): self.user_cg_artist = Person.create( first_name="John", last_name="Did3", email=u"*****@*****.**", role="user", password=auth.encrypt_password("mypassword")) return self.user_cg_artist
def generate_fixture_user_vendor(self): self.user_vendor = Person.create( first_name="John", last_name="Did5", role="vendor", email=u"*****@*****.**", password=auth.encrypt_password("mypassword")).serialize() return self.user_vendor
def generate_fixture_user_client(self): self.user_client = Person.create( first_name="John", last_name="Did4", role="client", email=u"*****@*****.**", password=auth.encrypt_password("mypassword")).serialize() return self.user_client
def extract_assignees(self, sg_task, person_ids): assignees = [] if len(sg_task["task_assignees"]) > 0: for sg_person in sg_task["task_assignees"]: person_id = person_ids[sg_person["id"]] person = Person.get(person_id) assignees.append(person) return assignees
def get_person_by_email_raw(email): """ Return person that matches given email as an active record. """ person = Person.get_by(email=email) if person is None: raise PersonNotFoundException() return person
def get_person(person_id): try: person = Person.get(person_id) except StatementError: raise PersonNotFoundException() if person is None: raise PersonNotFoundException() return person
def get_by_email(email): try: person = Person.get_by(email=email) except StatementError: raise PersonNotFoundException() if person is None: raise PersonNotFoundException() return person
def set_mentions(self, person_ids): from zou.app.models.person import Person self.mentions = [] for person_id in person_ids: person = Person.get(person_id) if person is not None: self.mentions.append(person) self.save()
def add_team_member(project_id, person_id): """ Add a a person listed in database to the the project team. """ project = get_project_raw(project_id) person = Person.get(person_id) project.team.append(person) project.save() return project.serialize()
def remove_team_member(project_id, person_id): """ Remove a a person listed in database from the the project team. """ project = get_project_raw(project_id) person = Person.get(person_id) project.team.remove(person) project.save() return project.serialize()
def generate_fixture_user_manager(self): self.user_manager = Person.create( first_name="John", last_name="Did2", role="manager", email="*****@*****.**", password=auth.encrypt_password("mypassword"), ).serialize() return self.user_manager
def delete_person(person_id): """ Delete person entry from database. """ person = Person.get(person_id) person_dict = person.serialize() person.delete() events.emit("person:delete", {"person_id": person_id}) clear_person_cache() return person_dict