Exemplo n.º 1
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")
    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_publish_organization_after_published(self, mock_boto, mock_ipfs):
        test_org_uuid = uuid4().hex
        test_org_id = "org_id"
        username = "******"
        current_time = datetime.now()
        org_state = OrganizationState(
            org_uuid=test_org_uuid, state=OrganizationStatus.APPROVED.value, transaction_hash="0x123",
            test_transaction_hash="0x456", wallet_address="0x987", created_by=username, created_on=current_time,
            updated_by=username, updated_on=current_time, reviewed_by="admin", reviewed_on=current_time)

        group = Group(
            name="default_group", id="group_id", org_uuid=test_org_uuid, payment_address="0x123",
            payment_config={
                "payment_expiration_threshold": 40320,
                "payment_channel_storage_type": "etcd",
                "payment_channel_storage_client": {
                    "connection_timeout": "5s",
                    "request_timeout": "3s", "endpoints": ["http://127.0.0.1:2379"]}}, status="0")
        org_address = [OrganizationAddress(
            org_uuid=test_org_uuid, address_type=OrganizationAddressType.HEAD_QUARTER_ADDRESS.value,
            street_address="F102", apartment="ABC Apartment", city="TestCity", pincode="123456",
            state="state", country="TestCountry"),
            OrganizationAddress(
                org_uuid=test_org_uuid, address_type=OrganizationAddressType.MAIL_ADDRESS.value,
                street_address="F102", apartment="ABC Apartment", city="TestCity", pincode="123456",
                state="state", country="TestCountry")
        ]

        organization = Organization(
            uuid=test_org_uuid, name="test_org", org_id=test_org_id, org_type="organization",
            origin=ORIGIN, description="this is long description",
            short_description="this is short description", url="https://dummy.com", duns_no="123456789", contacts=[],
            assets={"hero_image": {"url": "some_url", "ipfs_hash": "Q123"}},
            metadata_ipfs_uri="Q3E12", org_state=[org_state], groups=[group], addresses=org_address)

        owner = OrganizationMember(
            invite_code="123", org_uuid=test_org_uuid, role=Role.OWNER.value, username=username,
            status=OrganizationMemberStatus.ACCEPTED.value, address="0x123", created_on=current_time,
            updated_on=current_time, invited_on=current_time)
        org_repo.add_item(organization)
        org_repo.add_item(owner)
        event = {
            "pathParameters": {"org_uuid": test_org_uuid},
            "requestContext": {"authorizer": {"claims": {"email": username}}},
            "queryStringParameters": {"action": "DRAFT"},
            "body": json.dumps({
                "org_id": test_org_id, "org_uuid": test_org_uuid, "org_name": "test_org", "org_type": "organization",
                "metadata_ipfs_uri": "", "duns_no": "123456789", "origin": ORIGIN,
                "description": "this is long description", "short_description": "this is short description",
                "url": "https://dummy.com", "contacts": [],
                "assets": {"hero_image": {"url": "https://my_image", "ipfs_hash": ""}},
                "org_address": ORG_ADDRESS, "groups": [{
                    "name": "default",
                    "id": "group_id",
                    "payment_address": "0x123",
                    "payment_config": {
                        "payment_expiration_threshold": 40320,
                        "payment_channel_storage_type": "etcd",
                        "payment_channel_storage_client": {
                            "connection_timeout": "1s",
                            "request_timeout": "1s",
                            "endpoints": [
                                "123"
                            ]
                        }
                    }
                }],
                "state": {}
            })
        }
        update_org(event, None)
        updated_org = org_repo.get_org_for_org_id(test_org_id)
        owner = org_repo.session.query(OrganizationMember).filter(
            OrganizationMember.org_uuid == test_org_uuid).filter(OrganizationMember.role == Role.OWNER.value).all()
        if len(owner) != 1:
            assert False
        assert updated_org.name == "test_org"
        assert updated_org.id == "org_id"
        assert updated_org.org_type == "organization"
        assert updated_org.metadata_ipfs_uri == ""
        assert updated_org.groups[0].group_id == "group_id"
        assert updated_org.groups[0].name == "default"
        assert updated_org.groups[0].payment_address == "0x123"
        assert updated_org.duns_no == '123456789'
        assert updated_org.org_state.state == OrganizationStatus.APPROVED.value