Exemple #1
0
 def test_org_verification_individual(self, mock_boto_utils,
                                      mock_ipfs_utils):
     username = "******"
     for count in range(0, 3):
         org_id = uuid4().hex
         org_repo.add_organization(
             DomainOrganization(org_id, org_id, f"org_{org_id}",
                                OrganizationType.INDIVIDUAL.value, ORIGIN,
                                "", "", "", [], {}, "", "", [], [], [], []),
             username, OrganizationStatus.ONBOARDING.value)
     for count in range(0, 3):
         org_id = uuid4().hex
         org_repo.add_organization(
             DomainOrganization(org_id, org_id, f"org_{org_id}",
                                OrganizationType.INDIVIDUAL.value, ORIGIN,
                                "", "", "", [], {}, "", "", [], [], [], []),
             username, OrganizationStatus.APPROVED.value)
     OrganizationPublisherService(None, None).update_verification(
         "INDIVIDUAL",
         verification_details={
             "updated_by": "TEST_CASES",
             "status": "APPROVED",
             "username": username
         })
     organization = org_repo.get_organizations(
         OrganizationStatus.ONBOARDING_APPROVED.value)
     self.assertEqual(len(organization), 3)
Exemple #2
0
    def test_verify_invite(self, mock_invoke_lambda):
        test_org_uuid = uuid4().hex
        owner_username = "******"
        org_repo.add_organization(
            DomainOrganization(
                test_org_uuid, "org_id", "org_dummy",
                "ORGANIZATION", ORIGIN, "description",
                "short_description", "https://test.io", ORG_CONTACTS, {}, "ipfs_hash", "123456879", [], [], [], []),
            owner_username, OrganizationStatus.PUBLISHED.value)

        member_username = "******"
        member_invite_code = uuid4().hex
        org_repo.add_item(
            OrganizationMember(
                username=member_username,
                org_uuid=test_org_uuid,
                role=Role.MEMBER.value,
                address="0x123",
                status=OrganizationMemberStatus.PENDING.value,
                transaction_hash="0x123",
                invite_code=member_invite_code,
                invited_on=datetime.utcnow(),
                updated_on=datetime.utcnow()
            )
        )
        self.assertEqual(OrganizationPublisherService(None, member_username).verify_invite(member_invite_code), "OK")
        self.assertEqual(OrganizationPublisherService(None, member_username).verify_invite("1234"), "NOT_FOUND")
Exemple #3
0
    def test_get_member(self, mock_invoke_lambda):
        test_org_uuid = uuid4().hex
        owner_username = "******"
        org_repo.add_organization(
            DomainOrganization(
                test_org_uuid, "org_id", "org_dummy",
                "ORGANIZATION", ORIGIN, "description",
                "short_description", "https://test.io", ORG_CONTACTS, {}, "ipfs_hash", "123456879", [], [], [], []),
            owner_username, OrganizationStatus.PUBLISHED.value)

        members = OrganizationPublisherService(test_org_uuid, owner_username).get_member(owner_username)

        if isinstance(members, list) and len(members) == 1:
            members[0].pop("invited_on")
            members[0].pop("updated_on")
            self.assertDictEqual(
                members[0],
                {
                    'username': owner_username,
                    'address': "",
                    'status': 'ACCEPTED',
                    'role': 'OWNER'
                }
            )
        else:
            assert False
Exemple #4
0
    def test_invite_members(self, mock_invoke_lambda):
        mock_invoke_lambda.return_value = None
        test_org_uuid = uuid4().hex
        owner_username = "******"
        org_repo.add_organization(
            DomainOrganization(
                test_org_uuid, "org_id", "org_dummy",
                "ORGANIZATION", ORIGIN, "description",
                "short_description", "https://test.io", ORG_CONTACTS, {}, "ipfs_hash", "123456879", [], [], [], []),
            owner_username, OrganizationStatus.PUBLISHED.value)

        new_org_members = [
            {
                "username": "******"
            },
            {
                "username": "******"
            },
            {
                "username": "******"
            }
        ]
        OrganizationPublisherService(test_org_uuid, owner_username).invite_members(new_org_members)
        invited_org_members = org_repo.get_org_member(org_uuid=test_org_uuid, status=OrganizationMemberStatus.PENDING.value)
        if len(invited_org_members) == 3:
            assert True
        else:
            assert False
 def test_edit_organization_with_major_changes_onboarding(self, mock_user_mail, mock_approval_team, mock_boto,
                                                          mock_ipfs):
     username = "******"
     test_org_uuid = uuid4().hex
     test_org_id = "org_id"
     groups = OrganizationFactory.group_domain_entity_from_group_list_payload(json.loads(ORG_GROUPS))
     org_repo.add_organization(
         DomainOrganization(test_org_uuid, test_org_id, "org_dummy", "ORGANIZATION", ORIGIN, "", "",
                            "", [], {}, "", "", groups, [], [], []),
         username, OrganizationStatus.CHANGE_REQUESTED.value)
     payload = json.loads(ORG_PAYLOAD_MODEL)
     payload["org_uuid"] = test_org_uuid
     payload["org_id"] = test_org_id
     OrganizationPublisherService(test_org_uuid, username) \
         .update_organization(payload, OrganizationActions.DRAFT.value)
     org_db_model = org_repo.session.query(Organization).first()
     if org_db_model is None:
         assert False
     organization = OrganizationFactory.org_domain_entity_from_repo_model(org_db_model)
     org_dict = organization.to_response()
     org_dict["state"] = {}
     org_dict["groups"] = []
     org_dict["assets"]["hero_image"]["url"] = ""
     expected_organization = json.loads(ORG_RESPONSE_MODEL)
     expected_organization["org_id"] = test_org_id
     expected_organization["groups"] = []
     expected_organization["org_uuid"] = test_org_uuid
     self.assertDictEqual(expected_organization, org_dict)
 def test_store_transaction_hash(self):
     test_org_uuid = uuid4().hex
     username = "******"
     wallet_address = "0x321"
     transaction_hash = "0x123"
     nonce = 12
     org_repo.add_organization(
         DomainOrganization(
             test_org_uuid, "org_id", "org_dummy",
             "ORGANIZATION", ORIGIN, "description",
             "short_description", "https://test.io", ORG_CONTACTS, {}, "ipfs_hash", "123456879", [], [], [], [], "", ""),
         username, OrganizationStatus.PUBLISHED.value)
     event = {
         "requestContext": {"authorizer": {"claims": {"email": username}}},
         "pathParameters": {
             "org_uuid": test_org_uuid
         },
         "body": json.dumps({
             "transaction_hash": transaction_hash,
             "wallet_address": wallet_address,
             "nonce": nonce
         })
     }
     save_transaction_hash_for_publish_org(event, None)
     organization = org_repo.session.query(Organization).filter(Organization.uuid == test_org_uuid).first()
     owner = org_repo.session.query(OrganizationMember).filter(OrganizationMember.org_uuid == test_org_uuid)\
         .filter(OrganizationMember.role == Role.OWNER.value).first()
     if owner is None or organization is None:
         assert False
     self.assertEqual(transaction_hash, organization.org_state[0].transaction_hash)
     self.assertEqual(wallet_address, owner.address)
     self.assertEqual(nonce, organization.org_state[0].nonce)
 def test_org_publish_to_ipfs(self, mock_json_to_file_util, mock_test_network_publish, mock_ipfs_utils):
     test_org_id = uuid4().hex
     username = "******"
     org_repo.add_organization(
         DomainOrganization(test_org_id, "org_id", "org_dummy", "ORGANIZATION", ORIGIN, "", "",
                            "", [], {}, "", "", [], [], [], []),
         username, OrganizationStatus.APPROVED.value)
     response = OrganizationPublisherService(test_org_id, username).publish_org_to_ipfs()
     self.assertEqual(response["metadata_ipfs_uri"], "ipfs://Q12PWP")
 def test_edit_organization_with_org_id(self, mock_boto, mock_ipfs):
     username = "******"
     test_org_uuid = uuid4().hex
     test_org_id = "org_id"
     groups = OrganizationFactory.group_domain_entity_from_group_list_payload(json.loads(ORG_GROUPS))
     org_repo.add_organization(
         DomainOrganization(test_org_uuid, test_org_id, "org_dummy", "ORGANIZATION", ORIGIN, "", "",
                            "", [], {}, "", "", groups, [], [], []),
         username, OrganizationStatus.PUBLISHED.value)
     payload = json.loads(ORG_PAYLOAD_MODEL)
     payload["org_uuid"] = test_org_uuid
     self.assertRaises(OperationNotAllowed, OrganizationPublisherService(test_org_uuid, username)
                       .update_organization, payload, OrganizationActions.DRAFT.value)
 def test_get_org_for_admin(self, mock_boto, mock_ipfs):
     test_org_uuid = uuid4().hex
     username = "******"
     org_repo.add_organization(
         DomainOrganization(test_org_uuid, "org_id", "org_dummy",
                            "ORGANIZATION", ORIGIN, "", "", "", [], {}, "",
                            "", [], [], [], []), username,
         OrganizationStatus.APPROVED.value)
     org = OrganizationPublisherService(None, None).get_for_admin(
         {"status": OrganizationStatus.APPROVED.value})
     if len(org) != 1:
         assert False
     assert True
    def test_org_verification_organization(self, mock_boto_utils, mock_ipfs_utils, mock_email):
        username = "******"
        org_id = "test_org_id"
        org_uuid = "test_org_uuid"
        org_repo.add_organization(DomainOrganization(org_uuid, org_id, f"org_{org_id}",
                                                     OrganizationType.ORGANIZATION.value, ORIGIN, "",
                                                     "", "", [], {}, "", "", [], [], [], []),
                                  username, OrganizationStatus.ONBOARDING.value)

        OrganizationPublisherService(None, None).update_verification(
            "DUNS", verification_details={"updated_by": "TEST_CASES", "comment": "approved",
                                          "status": "APPROVED", "org_uuid": org_uuid})
        organization = org_repo.get_org(OrganizationStatus.ONBOARDING_APPROVED.value)
        self.assertEqual(len(organization), 1)
Exemple #11
0
    def test_publish_members(self):
        test_org_uuid = uuid4().hex
        owner_username = "******"
        org_repo.add_organization(
            DomainOrganization(
                test_org_uuid, "org_id", "org_dummy",
                "ORGANIZATION", ORIGIN, "description",
                "short_description", "https://test.io", ORG_CONTACTS, {}, "ipfs_hash", "123456879", [], [], [], []),
            owner_username, OrganizationStatus.PUBLISHED.value)

        new_org_members = [
            {
                "username": "******",
                "address": "0x123"
            },
            {
                "username": "******",
                "address": "0x234"
            },
            {
                "username": "******",
                "address": "0x345"
            }
        ]
        org_repo.add_all_items(
            [
                OrganizationMember(
                    username=member["username"],
                    org_uuid=test_org_uuid,
                    role=Role.MEMBER.value,
                    address=member["address"],
                    status=OrganizationMemberStatus.ACCEPTED.value,
                    transaction_hash="0x123",
                    invite_code=uuid4().hex,
                    invited_on=datetime.utcnow(),
                    updated_on=datetime.utcnow()
                ) for member in new_org_members
            ]
        )
        OrganizationPublisherService(test_org_uuid, owner_username).publish_members("0x123", new_org_members)
        org_members = org_repo.session.query(OrganizationMember).filter(OrganizationMember.org_uuid == test_org_uuid)\
            .filter(OrganizationMember.status == OrganizationMemberStatus.PUBLISH_IN_PROGRESS.value).all()

        if len(org_members) == 3:
            assert True
        else:
            assert False
    def test_register_member(self):
        test_org_uuid = uuid4().hex
        owner_username = "******"
        org_repo.add_organization(
            DomainOrganization(test_org_uuid, "org_id", "org_dummy",
                               "ORGANIZATION", ORIGIN, "description",
                               "short_description", "https://test.io",
                               ORG_CONTACTS, {}, "ipfs_hash", "123456879", [],
                               [], [], []), owner_username,
            OrganizationStatus.PUBLISHED.value)

        member_username = "******"
        member_invite_code = uuid4().hex
        org_repo.add_item(
            OrganizationMember(username=member_username,
                               org_uuid=test_org_uuid,
                               role=Role.MEMBER.value,
                               address="",
                               status=OrganizationMemberStatus.PENDING.value,
                               transaction_hash="0x123",
                               invite_code=member_invite_code,
                               invited_on=datetime.utcnow(),
                               updated_on=datetime.utcnow()))
        member_wallet_address = "0x962FD47b5afBc8D03025cE52155890667E58dEBA"
        self.assertRaises(
            Exception,
            OrganizationPublisherService(test_org_uuid,
                                         member_username).register_member,
            "1234", "0x9876")
        OrganizationPublisherService(test_org_uuid, member_username)\
            .register_member(member_invite_code, member_wallet_address)
        members = org_repo.session.query(OrganizationMember).filter(OrganizationMember.org_uuid == test_org_uuid)\
            .filter(OrganizationMember.username == member_username) \
            .all()
        if len(members) == 1:
            org_member = members[0]
            if org_member.status == OrganizationMemberStatus.ACCEPTED.value \
                    and org_member.address == member_wallet_address:
                assert True
            else:
                assert False
        else:
            assert False
 def test_individual_organization_review(self, mock_boto, mock_ipfs):
     from registry.application.services.slack_chat_operation import SlackChatOperation
     username = "******"
     org_id = "test_org_id"
     org_uuid = "test_org_uuid"
     registration_type = "type"
     registration_id = "123"
     current_time = datetime.now()
     org_repo.add_organization(
         DomainOrganization(org_uuid, org_id, f"org_{org_id}", OrganizationType.INDIVIDUAL.value, ORIGIN, "",
                            "", "", [], {}, "", "", [], [], [], [], registration_type=registration_type,
                            registration_id=registration_id), username, OrganizationStatus.ONBOARDING.value)
     SlackChatOperation("admin", "").process_approval_comment(
         "organization", "APPROVED", "here is the comment", {"org_id": "test_org_id"})
     organization = org_repo.get_org_for_org_uuid(org_uuid)
     comments = organization.org_state.comments
     if len(comments) != 1:
         assert False
     self.assertEqual("admin", comments[0].created_by)
     self.assertEqual("here is the comment", comments[0].comment)
     self.assertEqual(datetime_to_string(current_time), comments[0].created_at)