def test_changes_after_onboarding(self):
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING.value))
        self.assertEqual(OrganizationStatus.ONBOARDING.value,
                         Organization.next_state(current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING.value,
                         Organization.next_state(current_org, Mock(), OrganizationActions.SUBMIT.value))
    def test_changes_after_onboarding_approved(self):
        """ Non Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(False, None)))
        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(True, {})))
        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.ONBOARDING_APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes with org_id """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.ONBOARDING_APPROVED.value),
                           is_major_change=Mock(return_value=(True, {"values_changed": {"root._Organization__id"}})))
        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.DRAFT.value)

        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.SUBMIT.value)
    def test_changes_after_published(self):
        current_org = Mock(get_status=Mock(
            return_value=OrganizationStatus.PUBLISHED.value))
        self.assertEqual(
            OrganizationStatus.APPROVED.value,
            Organization.next_state(current_org, Mock(),
                                    OrganizationActions.DRAFT.value))

        self.assertEqual(
            OrganizationStatus.APPROVED.value,
            Organization.next_state(current_org, Mock(),
                                    OrganizationActions.SUBMIT.value))
    def test_changes_after_published(self):
        """ Non Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.PUBLISHED.value),
                           is_major_change=Mock(return_value=(False, None)))
        self.assertEqual(OrganizationStatus.APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.DRAFT.value))

        self.assertEqual(OrganizationStatus.APPROVED.value, Organization.next_state(
            current_org, Mock(), OrganizationActions.SUBMIT.value))

        """ Major changes """
        current_org = Mock(get_status=Mock(return_value=OrganizationStatus.PUBLISHED.value),
                           is_major_change=Mock(return_value=(True, {})))
        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.DRAFT.value)

        self.assertRaises(OperationNotAllowed, Organization.next_state,
                          current_org, Mock(), OrganizationActions.SUBMIT.value)
Exemplo n.º 5
0
 def create_organization(self, payload):
     logger.info(f"create organization for user: {self.username}")
     organization = OrganizationFactory.org_domain_entity_from_payload(payload)
     organization.setup_id()
     logger.info(f"assigned org_uuid : {organization.uuid}")
     org_ids = self.get_all_org_id()
     if organization.id in org_ids:
         raise Exception("Org_id already exists")
     updated_state = Organization.next_state(None, None, OrganizationActions.CREATE.value)
     org_repo.add_organization(organization, self.username, updated_state)
     return organization.to_response()
Exemplo n.º 6
0
    def update_organization(self, payload, action):
        logger.info(f"update organization for user: {self.username} org_uuid: {self.org_uuid} action: {action}")
        updated_organization = OrganizationFactory.org_domain_entity_from_payload(payload)
        current_organization = org_repo.get_org_for_org_uuid(self.org_uuid)

        self._archive_current_organization(current_organization)
        updated_state = Organization.next_state(current_organization, updated_organization, action)
        if updated_state == OrganizationStatus.ONBOARDING.value:
            self.notify_approval_team(updated_organization.id, updated_organization.name)
            self.notify_user_on_start_of_onboarding_process(updated_organization.id, recipients=[self.username])
        org_repo.update_organization(updated_organization, self.username, updated_state)
        return "OK"
 def update_organization(self, payload, action):
     logger.info(
         f"update organization for user: {self.username} org_uuid: {self.org_uuid} action: {action}"
     )
     updated_organization = OrganizationFactory.org_domain_entity_from_payload(
         payload)
     current_organization = org_repo.get_organization(
         org_uuid=self.org_uuid)
     self._archive_current_organization(current_organization)
     updated_state = Organization.next_state(current_organization,
                                             updated_organization, action)
     org_repo.update_organization(updated_organization, self.username,
                                  updated_state)
     return "OK"
Exemplo n.º 8
0
 def create_organization(self, payload):
     logger.info(f"create organization for user: {self.username}")
     organization = OrganizationFactory.org_domain_entity_from_payload(
         payload)
     organization.setup_id()
     if not organization.create_setup():
         raise Exception("Invalid Organization information")
     logger.info(f"assigned org_uuid : {organization.uuid}")
     org_ids = self.get_all_org_id()
     if organization.id in org_ids:
         raise Exception("Org_id already exists")
     updated_state = Organization.next_state(
         None, None, OrganizationActions.CREATE.value)
     self.notify_approval_team(organization.id, organization.name)
     self.notify_user_on_start_of_onboarding_process(
         organization.id, recipients=[self.username])
     org_repo.add_organization(organization, self.username, updated_state)
     return organization.to_response()