def test_get_service_for_service_uuid(self): self.tearDown() org_repo.add_item( Organization(name="test_org", org_id="test_org_id", uuid="test_org_uuid", org_type="organization", description="that is the dummy org for testcases", short_description="that is the short description", url="https://dummy.url", contacts=[], assets={}, duns_no=12345678, origin="PUBLISHER_DAPP", groups=[], addresses=[], metadata_ipfs_uri="#dummyhashdummyhash")) service_repo.add_item( Service(org_uuid="test_org_uuid", uuid="test_service_uuid", display_name="test_display_name", service_id="test_service_id", metadata_ipfs_hash="Qasdfghjklqwertyuiopzxcvbnm", short_description="test_short_description", description="test_description", project_url="https://dummy.io", ranking=1, created_on=dt.utcnow())) service_repo.add_item( ServiceState(row_id=1000, org_uuid="test_org_uuid", service_uuid="test_service_uuid", state=ServiceStatus.DRAFT.value, created_by="dummy_user", updated_by="dummy_user", created_on=dt.utcnow())) event = { "path": "/org/test_org_uuid/service", "requestContext": { "authorizer": { "claims": { "email": "*****@*****.**" } } }, "httpMethod": "GET", "pathParameters": { "org_uuid": "test_org_uuid", "service_uuid": "test_service_uuid" } } response = get_service_for_service_uuid(event=event, context=None) assert (response["statusCode"] == 200) response_body = json.loads(response["body"]) assert (response_body["status"] == "success") assert (response_body["data"]["org_uuid"] == "test_org_uuid") assert (response_body["data"]["service_uuid"] == "test_service_uuid") assert (response_body["data"]["service_state"]["state"] == ServiceStatus.DRAFT.value)
def test_update_service_transaction_status(self, mock_blockchain_utils): mock_blockchain_utils.return_value = Mock( get_transaction_receipt_from_blockchain=Mock(return_value=Mock(status=0))) test_org_uuid = uuid4().hex test_service_uuid = uuid4().hex test_org_id = "org_id" username = "******" current_time = datetime.now() org_state = OrganizationState( org_uuid=test_org_uuid, state=OrganizationStatus.PUBLISH_IN_PROGRESS.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") organization = Organization( uuid=test_org_uuid, name="test_org", org_id=test_org_id, org_type="organization", origin="PUBLISHER_PORTAL", 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]) 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) service_state = ServiceState(org_uuid=test_org_uuid, service_uuid=test_service_uuid, state=ServiceStatus.PUBLISH_IN_PROGRESS.value, created_on=current_time, created_by=username, updated_by=username, updated_on=current_time) service = Service(org_uuid=test_org_uuid, uuid=test_service_uuid, display_name="123", service_id="test_service", created_on=current_time, service_state=service_state) service_repo.add_item(service) ServiceTransactionStatus().update_transaction_status() service_state_db = service_repo.session.query(ServiceState)\ .filter(ServiceState.service_uuid == test_service_uuid).first() if service_state_db is None: assert False self.assertEqual(ServiceStatus.FAILED.value, service_state_db.state)
def test_on_service_created_event(self, mock_fetch_tags, mock_block_chain_util, mock_s3_push, mock_boto, mock_ipfs): org_uuid = str(uuid4()) service_uuid = str(uuid4()) self.org_repo.add_item( Organization(name="test_org", org_id="test_org_id", uuid=org_uuid, org_type="organization", description="that is the dummy org for testcases", short_description="that is the short description", url="https://dummy.url", contacts=[], assets={}, duns_no=12345678, origin="PUBLISHER_DAPP", groups=[], addresses=[], metadata_ipfs_uri="#dummyhashdummyhash")) self.service_repo.add_item( Service(org_uuid=org_uuid, uuid=service_uuid, display_name="test_display_name", service_id="test_service_id", metadata_uri="Qasdfghjklqwertyuiopzxcvbnm", short_description="test_short_description", description="test_description", project_url="https://dummy.io", ranking=1, created_on=datetime.utcnow(), updated_on=datetime.utcnow())) self.service_repo.add_item( ServiceState(row_id=randrange(10000), org_uuid=org_uuid, service_uuid=service_uuid, state=ServiceStatus.DRAFT.value, transaction_hash='0x1234', created_by="dummy_user", updated_by="dummy_user", created_on=datetime.utcnow(), updated_on=datetime.utcnow())) self.service_repo.add_item( ServiceGroup(row_id=randrange(1000), org_uuid=org_uuid, service_uuid=service_uuid, group_id="test_group_id", endpoints={ "https://dummydaemonendpoint.io": { "verfied": True } }, daemon_address=["0xq2w3e4rr5t6y7u8i9"], free_calls=10, free_call_signer_address="0xq2s3e4r5t6y7u8i9o0", created_on=datetime.utcnow(), updated_on=datetime.utcnow())) event = { "data": { 'row_id': 202, 'block_no': 6325625, 'event': 'ServiceCreated', 'json_str': "{'orgId': b'test_org_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'serviceId': b'test_service_id\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', 'metadataURI': b'ipfs://QmdGjaVYPMSGpC1qT3LDALSNCCu7JPf7j51H1GQirvQJYf\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'}", 'processed': b'\x00', 'transactionHash': '0x12345', 'logIndex': '0', 'error_code': 1, 'error_msg': '', 'row_updated': datetime(2019, 10, 21, 9, 59, 37), 'row_created': datetime(2019, 10, 21, 9, 59, 37) }, "name": "ServiceCreated" } mock_fetch_tags.return_value = ["tag1", "tag2"] mock_s3_push.return_value = "https://test-s3-push" service_event_consumer = ServiceCreatedEventConsumer( "wss://ropsten.infura.io/ws", "http://ipfs.singularitynet.io", 80, self.service_repo, self.org_repo) service_event_consumer.on_event(event=event) published_service = self.service_repo.get_service_for_given_service_uuid( org_uuid, service_uuid) self.assertEqual(["tag1", "tag2"], published_service.tags) self.assertEqual(ServiceStatus.PUBLISHED.value, published_service.service_state.state) self.assertEqual(service_metadata["display_name"], published_service.display_name) self.assertEqual( service_metadata["service_description"]["description"], published_service.description) self.assertEqual( service_metadata["service_description"]["short_description"], published_service.short_description) self.assertEqual(service_metadata["service_description"]["url"], published_service.project_url) self.assertDictEqual( { "encoding": "proto", "service_type": "grpc", "model_ipfs_hash": "QmXqonxB9EvNBe11J8oCYXMQAtPKAb2x8CyFLmQpkvVaLf" }, published_service.proto) self.assertEqual(service_metadata["mpe_address"], published_service.mpe_address) self.assertEqual( "ipfs://QmdGjaVYPMSGpC1qT3LDALSNCCu7JPf7j51H1GQirvQJYf", published_service.metadata_uri) self.assertDictEqual(service_metadata["contributors"][0], published_service.contributors[0]) group = published_service.groups[0] expected_group = service_metadata["groups"][0] self.assertEqual(expected_group["daemon_addresses"], group.daemon_address) self.assertEqual(expected_group["group_name"], group.group_name) self.assertEqual(expected_group["endpoints"], group._get_endpoints()) self.assertEqual(expected_group["free_calls"], group.free_calls) self.assertEqual(expected_group["free_call_signer_address"], group.free_call_signer_address) self.assertEqual(expected_group["group_id"], group.group_id) self.assertEqual(expected_group["pricing"], group.pricing)
def test_submit_service_for_approval(self): self.tearDown() org_repo.add_item( Organization(name="test_org", org_id="test_org_id", uuid="test_org_uuid", org_type="organization", description="that is the dummy org for testcases", short_description="that is the short description", url="https://dummy.url", contacts=[], assets={}, duns_no=12345678, origin="PUBLISHER_DAPP", groups=[], addresses=[], metadata_ipfs_uri="#dummyhashdummyhash")) service_repo.add_item( Service(org_uuid="test_org_uuid", uuid="test_service_uuid", display_name="test_display_name", service_id="test_service_id", metadata_ipfs_hash="Qasdfghjklqwertyuiopzxcvbnm", short_description="test_short_description", description="test_description", project_url="https://dummy.io", ranking=1, created_on=dt.utcnow())) service_repo.add_item( ServiceState(row_id=1000, org_uuid="test_org_uuid", service_uuid="test_service_uuid", state=ServiceStatus.DRAFT.value, created_by="dummy_user", updated_by="dummy_user", created_on=dt.utcnow())) service_repo.add_item( ServiceGroup(row_id="1000", org_uuid="test_org_uuid", service_uuid="test_service_uuid", group_id="test_group_id", endpoints=["https://dummydaemonendpoint.io"], daemon_address=["0xq2w3e4rr5t6y7u8i9"], free_calls=10, free_call_signer_address="0xq2s3e4r5t6y7u8i9o0", created_on=dt.utcnow())) event = { "path": "/org/test_org_uuid/service", "requestContext": { "authorizer": { "claims": { "email": "*****@*****.**" } } }, "httpMethod": "PUT", "pathParameters": { "org_uuid": "test_org_uuid", "service_uuid": "test_service_uuid" }, "body": json.dumps({"description": "test description updated"}) } response = submit_service_for_approval(event=event, context=None) assert (response["statusCode"] == 200) response_body = json.loads(response["body"]) assert (response_body["status"] == "success") assert (response_body["data"]["service_uuid"] == "test_service_uuid") assert (response_body["data"]["service_state"]["state"] == ServiceStatus.APPROVAL_PENDING.value)
def test_save_service(self): self.tearDown() org_repo.add_item( Organization(name="test_org", org_id="test_org_id", uuid="test_org_uuid", org_type="organization", description="that is the dummy org for testcases", short_description="that is the short description", url="https://dummy.url", contacts=[], assets={}, duns_no=12345678, origin="PUBLISHER_DAPP", groups=[], addresses=[], metadata_ipfs_uri="#dummyhashdummyhash")) service_repo.add_item( Service(org_uuid="test_org_uuid", uuid="test_service_uuid", display_name="test_display_name", service_id="test_service_id", metadata_ipfs_hash="Qasdfghjklqwertyuiopzxcvbnm", short_description="test_short_description", description="test_description", project_url="https://dummy.io", ranking=1, created_on=dt.utcnow())) service_repo.add_item( ServiceState(row_id=1000, org_uuid="test_org_uuid", service_uuid="test_service_uuid", state=ServiceStatus.DRAFT.value, created_by="dummy_user", updated_by="dummy_user", created_on=dt.utcnow())) service_repo.add_item( ServiceGroup(row_id="1000", org_uuid="test_org_uuid", service_uuid="test_service_uuid", group_id="test_group_id", endpoints=["https://dummydaemonendpoint.io"], daemon_address=["0xq2w3e4rr5t6y7u8i9"], free_calls=10, free_call_signer_address="0xq2s3e4r5t6y7u8i9o0", created_on=dt.utcnow())) event = { "path": "/org/test_org_uuid/service", "requestContext": { "authorizer": { "claims": { "email": "*****@*****.**" } } }, "httpMethod": "PUT", "pathParameters": { "org_uuid": "test_org_uuid", "service_uuid": "test_service_uuid" }, "body": json.dumps({ "description": "test description updated 1", "groups": [{ "group_name": "defaultGroup", "group_id": "l/hp6f1RXFPANeLWFZYwTB93Xi42S8NpZHfnceS6eUw=", "free_calls": 10, "free_call_signer_address": "0x7DF35C98f41F3Af0df1dc4c7F7D4C19a71Dd059F", "pricing": [{ "default": True, "price_model": "fixed_price", "price_in_cogs": 1 }], "endpoints": [] }] }) } response = save_service(event=event, context=None) assert (response["statusCode"] == 200) response_body = json.loads(response["body"]) assert (response_body["status"] == "success") assert (response_body["data"]["service_uuid"] == "test_service_uuid") assert (response_body["data"]["service_state"]["state"] == ServiceStatus.DRAFT.value) event = { "path": "/org/test_org_uuid/service", "requestContext": { "authorizer": { "claims": { "email": "*****@*****.**" } } }, "httpMethod": "PUT", "pathParameters": { "org_uuid": "test_org_uuid", "service_uuid": "test_service_uuid" }, "body": json.dumps({ "description": "test description updated 2", "groups": [{ "group_name": "defaultGroup", "group_id": "l/hp6f1RXFPANeLWFZYwTB93Xi42S8NpZHfnceS6eUw=", "free_calls": 20, "free_call_signer_address": "0x7DF35C98f41F3Af0df1dc4c7F7D4C19a71Dd059F", "pricing": [{ "default": True, "price_model": "fixed_price", "price_in_cogs": 2 }], "endpoints": [] }] }) } response = save_service(event=event, context=None) assert (response["statusCode"] == 200) response_body = json.loads(response["body"]) assert (response_body["status"] == "success") assert (response_body["data"]["service_uuid"] == "test_service_uuid") assert (response_body["data"]["service_state"]["state"] == ServiceStatus.DRAFT.value)
def test_get_services_for_organization(self): self.tearDown() org_repo.add_item( Organization(name="test_org", org_id="test_org_id", uuid="test_org_uuid", org_type="organization", description="that is the dummy org for testcases", short_description="that is the short description", url="https://dummy.url", contacts=[], assets={}, duns_no=12345678, origin="PUBLISHER_DAPP", groups=[], addresses=[], metadata_ipfs_uri="#dummyhashdummyhash")) service_repo.add_item( Service(org_uuid="test_org_uuid", uuid="test_service_uuid", display_name="test_display_name", service_id="test_service_id", metadata_ipfs_hash="Qasdfghjklqwertyuiopzxcvbnm", short_description="test_short_description", description="test_description", project_url="https://dummy.io", ranking=1, created_on=dt.utcnow())) service_repo.add_item( ServiceState(row_id=1000, org_uuid="test_org_uuid", service_uuid="test_service_uuid", state="DRAFT", transaction_hash=None, created_by="dummy_user", updated_by="dummy_user", created_on=dt.utcnow())) service_repo.add_item( ServiceGroup(row_id="1000", org_uuid="test_org_uuid", service_uuid="test_service_uuid", group_id="test_group_id", pricing={}, endpoints=["https://dummydaemonendpoint.io"], daemon_address=["0xq2w3e4rr5t6y7u8i9"], free_calls=10, free_call_signer_address="", created_on=dt.utcnow())) event = { "requestContext": { "authorizer": { "claims": { "email": "*****@*****.**" } } }, "httpMethod": "GET", "pathParameters": { "org_uuid": "test_org_uuid" }, "body": json.dumps({ "q": "display", "limit": 10, "offset": 0, "s": "all", "sort_by": "display_name", "order_by": "desc", "filters": [] }) } response = get_services_for_organization(event=event, context=None) assert (response["statusCode"] == 200) response_body = json.loads(response["body"]) assert (response_body["status"] == "success") assert (response_body["data"]["total_count"] == 1) assert (response_body["data"]["offset"] == 0) assert (response_body["data"]["limit"] == 10) assert (len(response_body["data"]["result"]) == 1)