def test_gyomu_app_load(self, environment_setup): app = GyomuAppsInfoCdtbl() app.application_id = TEST_APPLICATION_ID2 app.description = "Test Application" user: User = UserFactory.get_current_user() app.mail_from_name = user.userid app.mail_from_address = "*****@*****.**" json_data = gyomuapps_schema_load.dumps(app) dictionary = gyomuapps_schema.loads(json_data=json_data) with DbConnectionFactory.get_gyomu_db_session() as session: app_loaded = gyomuapps_schema_load.load(dictionary, session=session) assert app.application_id == app_loaded.application_id app2 = GyomuAppsInfoCdtbl() app2.application_id = TEST_APPLICAIONT_ID3 app2.description = "Testw Application" user: User = UserFactory.get_current_user() app2.mail_from_name = user.userid app2.mail_from_address = "*****@*****.**" app_list = [app, app2] json_data = gyomuapps_total_list_schema.dumps(app_list) dictionary = gyomuapps_total_list_schema.loads(json_data=json_data) with DbConnectionFactory.get_gyomu_db_session() as session: apps = gyomuapps_total_list_schema_load.load(dictionary, session=session) assert len(apps) == 2
def test_gyomu_app(self): app = GyomuAppsInfoCdtbl() app.application_id = TEST_APPLICATION_ID2 app.description = "Test Application" user: User = UserFactory.get_current_user() app.mail_from_name = user.userid app.mail_from_address = "*****@*****.**" json_data = Json.to_json(app, gyomuapps_schema) app_loaded = Json.deserialize(json_data, GyomuAppsInfoCdtbl, gyomuapps_schema) assert app.application_id == app_loaded.application_id app2 = GyomuAppsInfoCdtbl() app2.application_id = TEST_APPLICAIONT_ID3 app2.description = "Testw Application" user: User = UserFactory.get_current_user() app2.mail_from_name = user.userid app2.mail_from_address = "*****@*****.**" app_list = [app, app2] json_data = Json.to_json(app_list, gyomuapps_total_list_schema) #json_data = gyomuapps_total_list_schema.dumps(app_list) #dictionary = gyomuapps_total_list_schema.loads(json_data=json_data) #assert len(dictionary)==2 app_list_loaded = Json.deserialize(json_data, GyomuAppsInfoCdtbl, gyomuapps_total_list_schema) assert len(app_list_loaded) == 2
def test_insert_app_info(environment_setup): app = GyomuAppsInfoCdtblAccess.get(TEST_APPLICATION_ID2) if app is not None: GyomuAppsInfoCdtblAccess.delete(app) original_apps_count = len(GyomuAppsInfoCdtblAccess.get_all()) app = GyomuAppsInfoCdtbl() app.application_id = TEST_APPLICATION_ID2 app.description = "Test Application" user: User = UserFactory.get_current_user() app.mail_from_name = user.userid app.mail_from_address = "*****@*****.**" GyomuAppsInfoCdtblAccess.add(app) new_apps_count = len(GyomuAppsInfoCdtblAccess.get_all()) assert new_apps_count == (original_apps_count+1) app = GyomuAppsInfoCdtblAccess.get(TEST_APPLICATION_ID2) amend_description="Test2 Application" app.description=amend_description amend_mail_name='dummy' app.mail_from_name=amend_mail_name amend_mail_address='*****@*****.**' app.mail_from_address = amend_mail_address GyomuAppsInfoCdtblAccess.update(app) app = GyomuAppsInfoCdtblAccess.get(TEST_APPLICATION_ID2) assert app.description == amend_description assert app.mail_from_name==amend_mail_name assert app.mail_from_address == amend_mail_address app.application_id= TEST_APPLICAIONT_ID_AMEND GyomuAppsInfoCdtblAccess.update(app, original_application_id=TEST_APPLICATION_ID2) app = GyomuAppsInfoCdtblAccess.get(TEST_APPLICATION_ID2) assert app is None app = GyomuAppsInfoCdtblAccess.get(TEST_APPLICAIONT_ID_AMEND) assert app.application_id == TEST_APPLICAIONT_ID_AMEND GyomuAppsInfoCdtblAccess.delete(app)
def __internal_check_task_accessibility(self) -> bool: if len(self.access_list) == 0: return True current_user_name = self.config.username.upper() can_access: bool = False for access in self.access_list: account_name: str = access.account_name if current_user_name == account_name.upper(): if access.forbidden: return False if access.can_access: can_access = True target_user: User = UserFactory.get_user(account_name) if target_user.is_valid and target_user.is_group: if self.config.user.is_in_member(target_user): if access.forbidden: return False if access.can_access: can_access = True return can_access
def test_gyomu_app_validation(self): app = GyomuAppsInfoCdtbl() app.application_id = TEST_APPLICATION_ID2 app.description = "Test Application" user: User = UserFactory.get_current_user() app.mail_from_name = user.userid app.mail_from_address = "*****@*****.**" json_data = Json.to_json(app, gyomuapps_schema) json_data = '{"mail_from_name": "yoshm", "description": "Test Application", "application_id": "Test", "mail_from_address": "*****@*****.**"}' with pytest.raises(ValidationError) as ve: app2 = Json.deserialize(json_data, GyomuAppsInfoCdtbl, gyomuapps_schema) assert 'application_id' in ve.value.messages json_data = '{"mail_from_name": "yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789", ' \ '"description": "Test Application", "application_id": 32651, "mail_from_address": "*****@*****.**"}' with pytest.raises(ValidationError) as ve: dictionary = gyomuapps_schema.loads(json_data=json_data) assert 'mail_from_name' in ve.value.messages json_data = '{"mail_from_name": "yoshm",' \ ' "description": "Test Application123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789Application123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789", ' \ '"application_id": 32651, "mail_from_address": "*****@*****.**"}' with pytest.raises(ValidationError) as ve: dictionary = gyomuapps_schema.loads(json_data=json_data) assert 'description' in ve.value.messages json_data = '{"mail_from_name": "yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789yoshma123456789123456789123456789123456789123456789123456789", ' \ ' "description": "Test Application123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789Application123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789", ' \ '"application_id": 32651, "mail_from_address": "*****@*****.**"}' with pytest.raises(ValidationError) as ve: dictionary = gyomuapps_schema.loads(json_data=json_data) assert 'description' in ve.value.messages assert 'mail_from_name' in ve.value.messages json_data = '{"mail_from_name": "yoshm", "description": "Test Application", "application_id": 35456, "mail_from_address": "Testt.com"}' with pytest.raises(ValidationError) as ve: dictionary = gyomuapps_schema.loads(json_data=json_data) pass assert 'mail_from_address' in ve.value.messages
def application_info_setup(environment_setup): with DbConnectionFactory.get_gyomu_db_session() as session: app2 = session.query(GyomuAppsInfoCdtbl).get(TEST_APPLICATION_ID) if app2 is not None: session.delete(app2) session.commit() app = GyomuAppsInfoCdtbl() app.application_id = TEST_APPLICATION_ID app.description = "Test Application" user: User = UserFactory.get_current_user() app.mail_from_name = user.userid app.mail_from_address = "*****@*****.**" with DbConnectionFactory.get_gyomu_db_session() as session: session.add(app) session.commit() yield TEST_APPLICATION_ID with DbConnectionFactory.get_gyomu_db_session() as session: session.delete(app) session.commit()
def __init__(self, user: User = None, shared_dictionary: dict = None): if user is None: user = UserFactory.get_current_user() self._user = user self.init(shared_dictionary)
def __init__(self, user: User = None): if user is None: user = UserFactory.get_current_user() self._user = user self.init()
def __internal_valid_owner(self, target_status_mnemonic: str) -> bool: if self.latest_instance is None: return True if target_status_mnemonic == self.STATUS_INIT: return True if self.__internal_check_task_accessibility else False current_status: str current_status = self.latest_instance.task_status if target_status_mnemonic == self.STATUS_APPROVAL or target_status_mnemonic == self.STATUS_REJECT: if not self._is_self_approve_enable(): requester: User = UserFactory.get_user(self.latest_instance.entry_author) if requester.is_valid and requester == self.current_user: return False for task_submit_information in self.__get_task_submission_information_list(self.latest_instance): submit_user: User = UserFactory.get_user(task_submit_information.submit_to) if submit_user.is_valid: if not submit_user.is_group and submit_user == self.current_user: return True if submit_user.is_group and self.current_user.is_in_member(submit_user): return True elif target_status_mnemonic == self.STATUS_EXECUTE: if current_status != self.STATUS_DELEGATE: if self.delegate_information.delegation_required: # self.instances current_delegated_instances = [instance for instance in self.instances if instance.task_status == self.STATUS_DELEGATE and instance.entry_author == self.current_user.userid] if len(current_delegated_instances) > 0: return True previous_user: User = UserFactory.get_user(self.latest_instance.entry_author) if previous_user.is_valid and previous_user == self.current_user: return True else: for task_submit_information in self.__get_task_submission_information_list(self.latest_instance): submit_user: User = UserFactory.get_user(task_submit_information.submit_to) if submit_user.is_valid: if not submit_user.is_group and submit_user == self.current_user: return True if submit_user.is_group and self.current_user.is_in_member(submit_user): return True elif target_status_mnemonic == self.STATUS_REQUEST: # Approver or Starter starter: User = UserFactory.get_user(self._current_task.entry_author) if starter.is_valid and starter == self.current_user: return True if self.latest_instance.task_status == self.STATUS_APPROVAL: approver: User = UserFactory.get_user(self.latest_instance.entry_author) if approver.is_valid and approver == self.current_user: return True elif target_status_mnemonic == self.STATUS_CANCEL: # Requestor requester: User = UserFactory.get_user(self.latest_instance.entry_author) if requester.is_valid and requester == self.current_user: return True elif target_status_mnemonic == self.STATUS_COMPLETE: if not self.__internal_check_task_accessibility: return False if current_status == self.STATUS_FAIL: return True else: return True return False