コード例 #1
0
 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)
コード例 #2
0
    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)
コード例 #3
0
 def test_create_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"))
     event = {
         "requestContext": {
             "authorizer": {
                 "claims": {
                     "email": "*****@*****.**"
                 }
             }
         },
         "httpMethod": "POST",
         "pathParameters": {
             "org_uuid": "test_org_uuid"
         },
         "body": json.dumps({"display_name": "test_display_name"})
     }
     response = create_service(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")
コード例 #4
0
    def test_organization_create_event(self,
                                       mock_get_org_details_from_blockchain,
                                       mock_blockchain_util,
                                       mock_read_bytesio_from_ipfs,
                                       mock_ipfs_read, mock_s3_push,
                                       mock_ipfs_write):
        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.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)
        self.org_repo.add_item(organization)
        self.org_repo.add_item(owner)
        mock_read_bytesio_from_ipfs.return_value = ""
        mock_s3_push.return_value = "http://test-s3-push"
        ipfs_mock_value = {
            "org_name":
            "test_org",
            "org_id":
            "org_id",
            "metadata_ipfs_hash":
            "Q3E12",
            "org_type":
            "organization",
            "contacts": [],
            "description": {
                "description": "this is long description",
                "short_description": "this is short description",
                "url": "https://dummy.com"
            },
            "assets": {
                'hero_image': 'Q123'
            },
            "groups": [{
                "group_name": "default_group",
                "group_id": "group_id",
                "payment": {
                    "payment_address": "0x123",
                    "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"]
                    }
                }
            }]
        }
        mock_ipfs_read.return_value = ipfs_mock_value
        mock_get_org_details_from_blockchain.return_value = "org_id", ipfs_mock_value, "Q3E12", "0x123", "0x123", []
        org_event_consumer = OrganizationCreatedAndModifiedEventConsumer(
            "wss://ropsten.infura.io/ws", "http://ipfs.singularitynet.io", 80,
            self.org_repo)

        org_event_consumer.on_event({})
        published_org = self.org_repo.get_organization(org_id=test_org_id)
        org_owner = self.org_repo.session.query(OrganizationMember).filter(
            OrganizationMember.org_uuid == test_org_uuid).filter(
                OrganizationMember.role == Role.OWNER.value).all()
        if len(org_owner) != 1:
            assert False
        self.assertEqual(org_owner[0].address, "0x123")
        self.assertEqual(org_owner[0].username, username)
        assert published_org.name == "test_org"
        assert published_org.id == "org_id"
        assert published_org.org_type == "organization"
        assert published_org.metadata_ipfs_uri == "Q3E12"
        assert published_org.groups[0].group_id == "group_id"
        assert published_org.groups[0].name == "default_group"
        assert published_org.groups[0].payment_address == "0x123"
        assert published_org.duns_no == '123456789'
        assert published_org.org_state.state == "PUBLISHED"
コード例 #5
0
    def test_organization_owner_change_event(
            self, mock_get_org_details_from_blockchain, mock_blockchain_util,
            mock_read_bytesio_from_ipfs, mock_ipfs_read, mock_s3_push,
            mock_ipfs_write):
        username = "******"
        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.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.PUBLISHED.value,
            address="0x123",
            created_on=current_time,
            updated_on=current_time,
            invited_on=current_time)
        self.org_repo.add_item(organization)
        self.org_repo.add_item(owner)
        event = {
            "data": {
                'row_id': 2,
                'block_no': 6243627,
                'event': 'OrganizationCreated',
                'json_str':
                "{'orgId': b'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'}",
                'processed': b'\x00',
                'transactionHash':
                "b'y4\\xa4$By/mZ\\x17\\x1d\\xf2\\x18\\xb6aa\\x02\\x1c\\x88P\\x85\\x18w\\x19\\xc9\\x91\\xecX\\xd7E\\x98!'",
                'logIndex': '1',
                'error_code': 1,
                'error_msg': '',
                'row_updated': datetime(2019, 10, 21, 9, 44, 9),
                'row_created': datetime(2019, 10, 21, 9, 44, 9)
            },
            "name": "OrganizationCreated"
        }
        mock_read_bytesio_from_ipfs.return_value = ""
        mock_s3_push.return_value = "http://test-s3-push"
        ipfs_mock_value = {
            "org_name":
            "test_org",
            "org_id":
            "org_id",
            "org_type":
            "organization",
            "contacts": [],
            "description": {
                "description": "this is long description",
                "short_description": "this is short description",
                "url": "https://dummy.com"
            },
            "assets": {
                'hero_image': 'Q123'
            },
            "groups": [{
                "group_name": "default_group",
                "group_id": "group_id",
                "payment": {
                    "payment_address": "0x123",
                    "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"]
                    }
                }
            }]
        }
        self.org_repo.session.commit()
        mock_ipfs_read.return_value = ipfs_mock_value
        mock_get_org_details_from_blockchain.return_value = "org_id", ipfs_mock_value, "Q3E12", "79345c7861342442792f6d5a5c7831375c7831645c7866325c7831385c78623661615c7830325c7831635c783838505c7838355c783138775c7831395c7863395c7839315c786563585c786437455c78393821", "0x1234", []
        org_event_consumer = OrganizationCreatedAndModifiedEventConsumer(
            "wss://ropsten.infura.io/ws", "http://ipfs.singularitynet.io", 80,
            self.org_repo)

        org_event_consumer.on_event({})
        published_org = self.org_repo.get_organization(org_id=test_org_id)
        owner = self.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
        self.assertEqual(owner[0].address, "0x1234")
        self.assertEqual(owner[0].username, "")

        assert published_org.name == "test_org"
        assert published_org.id == "org_id"
        assert published_org.org_type == "organization"
        assert published_org.metadata_ipfs_uri == "Q3E12"
        assert published_org.groups[0].group_id == "group_id"
        assert published_org.groups[0].name == "default_group"
        assert published_org.groups[0].payment_address == "0x123"
        assert published_org.duns_no == '123456789'
        assert published_org.org_state.state == "PUBLISHED"
    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
コード例 #7
0
    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))
コード例 #8
0
    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)
コード例 #9
0
    def test_on_gas_price_boosted_service_created_event(
            self, mock_block_chain_util, mock_s3_push, mock_ipfs):
        org_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"))

        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': None,
                '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_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)

        org_uuid, published_service = self.service_repo.get_service_for_given_service_id_and_org_id(
            "test_org_id", "test_service_id")
        self.assertEqual([], published_service.tags)
        self.assertEqual(ServiceStatus.PUBLISHED_UNAPPROVED.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.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)
コード例 #10
0
 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)
コード例 #11
0
 def test_verify_service_id(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",
                 proto={},
                 short_description="test_short_description",
                 description="test_description",
                 project_url="https://dummy.io",
                 assets={},
                 rating={},
                 ranking=1,
                 contributors=[],
                 created_on=dt.utcnow(),
                 updated_on=dt.utcnow()))
     event = {
         "requestContext": {
             "authorizer": {
                 "claims": {
                     "email": "*****@*****.**"
                 }
             }
         },
         "httpMethod": "GET",
         "pathParameters": {
             "org_uuid": "test_org_uuid"
         },
         "queryStringParameters": {
             "service_id": "test_service_id"
         }
     }
     response = verify_service_id(event=event, context=None)
     assert (response["statusCode"] == 200)
     response_body = json.loads(response["body"])
     assert (response_body["status"] == "success")
     assert (response_body["data"] ==
             ServiceAvailabilityStatus.UNAVAILABLE.value)
     event = {
         "requestContext": {
             "authorizer": {
                 "claims": {
                     "email": "*****@*****.**"
                 }
             }
         },
         "httpMethod": "GET",
         "pathParameters": {
             "org_uuid": "test_org_uuid"
         },
         "queryStringParameters": {
             "service_id": "new_test_service_id"
         }
     }
     response = verify_service_id(event=event, context=None)
     assert (response["statusCode"] == 200)
     response_body = json.loads(response["body"])
     assert (response_body["status"] == "success")
     assert (
         response_body["data"] == ServiceAvailabilityStatus.AVAILABLE.value)
コード例 #12
0
 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)
コード例 #13
0
 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)