def _update_organization(self, organization_db_model, organization, username, state, test_transaction_hash=None): current_time = datetime.utcnow() organization_db_model.name = organization.name organization_db_model.org_id = organization.id organization_db_model.org_type = organization.org_type organization_db_model.origin = organization.origin organization_db_model.description = organization.description organization_db_model.short_description = organization.short_description organization_db_model.url = organization.url organization_db_model.duns_no = organization.duns_no organization_db_model.contacts = organization.contacts organization_db_model.assets = organization.assets organization_db_model.metadata_ipfs_uri = organization.metadata_ipfs_uri organization_db_model.org_state[0].state = state organization_db_model.org_state[0].updated_on = current_time if test_transaction_hash is not None: organization_db_model.org_state[ 0].test_transaction_hash = test_transaction_hash organization_db_model.org_state[0].updated_by = username self.session.commit() org_addresses_domain_entity = organization.addresses group_domain_entity = organization.groups addresses = [ OrganizationAddress(org_uuid=organization.uuid, address_type=address.address_type, street_address=address.street_address, apartment=address.apartment, city=address.city, pincode=address.pincode, state=address.state, country=address.country, created_on=current_time, updated_on=current_time) for address in org_addresses_domain_entity ] groups = [ Group(name=group.name, id=group.group_id, org_uuid=organization.uuid, payment_address=group.payment_address, payment_config=group.payment_config, status=group.status) for group in group_domain_entity ] self.session.query(OrganizationAddress).filter(OrganizationAddress.org_uuid == organization.uuid) \ .delete(synchronize_session='fetch') self.session.query(Group).filter( Group.org_uuid == organization.uuid).delete( synchronize_session='fetch') self.session.commit() self.add_all_items(addresses) self.add_all_items(groups)
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
def add_organization(self, organization, username, state, address="", test_transaction_hash=None): current_time = datetime.utcnow() org_addresses_domain_entity = organization.addresses group_domain_entity = organization.groups groups = [ Group(name=group.name, id=group.group_id, org_uuid=organization.uuid, payment_address=group.payment_address, payment_config=group.payment_config, status=group.status) for group in group_domain_entity ] addresses = [ OrganizationAddress(org_uuid=organization.uuid, address_type=address.address_type, street_address=address.street_address, apartment=address.apartment, city=address.city, pincode=address.pincode, state=address.state, country=address.country, created_on=current_time, updated_on=current_time) for address in org_addresses_domain_entity ] org_state = [ OrganizationState(org_uuid=organization.uuid, state=state, transaction_hash="", wallet_address="", created_by=username, created_on=current_time, test_transaction_hash=test_transaction_hash, updated_by=username, updated_on=current_time, reviewed_by="") ] self.add_item( Organization(uuid=organization.uuid, name=organization.name, org_id=organization.id, org_type=organization.org_type, origin=organization.origin, description=organization.description, short_description=organization.short_description, url=organization.url, duns_no=organization.duns_no, contacts=organization.contacts, assets=organization.assets, metadata_ipfs_uri=organization.metadata_ipfs_uri, org_state=org_state, groups=groups, addresses=addresses)) self.add_item( OrganizationMember(invite_code=uuid4().hex, org_uuid=organization.uuid, role=Role.OWNER.value, username=username, address=address, status=OrganizationMemberStatus.ACCEPTED.value, transaction_hash="", invited_on=current_time, created_on=current_time, updated_on=current_time))