示例#1
0
    def test_validate_proto(self, mock_proto_compile_response):
        mock_proto_compile_response.return_value = {"statusCode": 200}
        event = {
            "Records": [{
                "s3": {
                    "bucket": {
                        "name": "ropsten-marketplace-service-assets"
                    },
                    "object": {
                        "key":
                        "testorguuid/services/testserviceuuid/proto/20210618114940_proto_files.zip"
                    }
                }
            }]
        }
        response = update_service_assets(event=event, context=None)
        service = ServicePublisherRepository(
        ).get_service_for_given_service_uuid(org_uuid="testorguuid",
                                             service_uuid="testserviceuuid")
        assert response["statusCode"] == 200
        assert service.assets == {
            "demo_files": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
                "build_id": "sample_build_id",
                "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
            },
            "hero_image": {
                "url":
                "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
                "ipfs_hash":
                "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
            },
            "proto_files": {
                "url":
                "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/testorguuid/services/testserviceuuid/proto/20210618114940_proto_files.zip",
                "status": "SUCCEEDED"
            }
        }

        paths = [
            "testorguuid/assets/any", "testorguuid/assets/any/link/",
            "testorguuid/assets/any/val_ue"
        ]
        for path in paths:
            event = {
                "Records": [{
                    "s3": {
                        "bucket": {
                            "name": "ropsten-marketplace-service-assets"
                        },
                        "object": {
                            "key": path
                        }
                    }
                }]
            }
            response = update_service_assets(event=event, context=None)
            self.assertEqual(response["statusCode"], 200)
            self.assertEqual(json.loads(response["body"])["data"], None)
 def test_validate_hero_image(self):
     event = {
         "Records": [{
             "s3": {
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/assets/20210127060155_asset.jpeg",
                     "size": 6949,
                     "eTag": "c80928fa72a7ceb972b54a214c2181b3",
                     "sequencer": "0060CCFC79D1D7CCDF"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     assert response["statusCode"] == 200
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     print(service.to_dict())
     assert service.assets == {
         "demo_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
             "build_id": "sample_build_id",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         },
         "hero_image": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/assets/20210127060155_asset.jpeg"
         },
         "proto_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         }
     }
示例#3
0
 def test_validate_demo_component(self, mock_code_build):
     mock_code_build.return_value = {"build": {"id": "test_build_id"}}
     event = {
         "Records": [{
             "s3": {
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "testorguuid/services/testserviceuuid/component/example_service_component.zip"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="testorguuid",
                                          service_uuid="testserviceuuid")
     assert response["statusCode"] == 200
     assert json.loads(
         response["body"])["data"]["build_id"] == "test_build_id"
     assert service.assets["hero_image"] == {
         'url':
         'https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png',
         'ipfs_hash':
         'QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png'
     }
     assert service.assets["proto_files"] == {
         'url':
         'https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip',
         'ipfs_hash': 'QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy'
     }
     assert service.assets["demo_files"][
         "url"] == "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/testorguuid/services/testserviceuuid/component/example_service_component.zip"
     assert service.assets["demo_files"]["status"] == "PENDING"
     assert service.assets["demo_files"]["build_id"] == "test_build_id"
     assert True if (
         service.assets["demo_files"]["last_modified"]) else False == True
 def test_validate_demo_component(self, mock_code_build):
     mock_code_build.return_value = {"build": {"id": "test_build_id"}}
     event = {
         "Records": [{
             "eventVersion": "2.1",
             "eventSource": "aws:s3",
             "awsRegion": "us-east-1",
             "eventTime": "2021-06-16T15:49:00.312Z",
             "eventName": "ObjectCreated:Put",
             "userIdentity": {
                 "principalId": "AWS:AIDAXYSEM4MOPXXLSNUMO"
             },
             "requestParameters": {
                 "sourceIPAddress": "117.213.142.222"
             },
             "responseElements": {
                 "x-amz-request-id":
                 "XNESWXSYFNZA8HKK",
                 "x-amz-id-2":
                 "ir/3JEviL89t07LOtI2+oQE6X+EMtHWFOWyojXXNkNF/p2ZcsgeBg9X81dbZA2sj4gJw/CI8mhEfyJNcXdpPhkjcRqBYpwRHYH7vzMvrRsU="
             },
             "s3": {
                 "s3SchemaVersion": "1.0",
                 "configurationId": "b2733823-1355-4982-abdd-8f14cb7ddba4",
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/component/example_service_component.zip",
                     "size": 5248,
                     "eTag": "54ea849194040b43601f44ed53e5dc1b",
                     "sequencer": "0060CA1D6C80321671"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     assert response["statusCode"] == 200
     assert json.loads(
         response["body"])["data"]["build_id"] == "test_build_id"
     assert service.assets == {
         "demo_files": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/component/example_service_component.zip",
             "status": "PENDING",
             "build_id": "test_build_id"
         },
         "hero_image": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
             "ipfs_hash":
             "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
         },
         "proto_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/proto/20210131042033_proto_files.zip",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         }
     }
 def test_validate_proto(self, mock_proto_compile_response):
     mock_proto_compile_response.return_value = {"statusCode": 200}
     event = {
         "Records": [{
             "eventVersion": "2.1",
             "eventSource": "aws:s3",
             "awsRegion": "us-east-1",
             "eventTime": "2021-06-18T11:49:39.596Z",
             "eventName": "ObjectCreated:Put",
             "userIdentity": {
                 "principalId":
                 "AWS:AROAIJDMM5CI656XV7AOY:common-utility-rt-v2-upload"
             },
             "requestParameters": {
                 "sourceIPAddress": "18.210.102.181"
             },
             "responseElements": {
                 "x-amz-request-id":
                 "CK234N3ZN84W1TZ5",
                 "x-amz-id-2":
                 "9lHUaMDKbuCB9C6YnI6CjJuuWWhSiunQgXSnHHDK1+6ETaAjq95qSuYsqQGUhfbSOGStTohI3qiWpCjNrg36mFh4uTvh+PdW"
             },
             "s3": {
                 "s3SchemaVersion": "1.0",
                 "configurationId": "31f60a9a-a853-406c-b697-495098f6257d",
                 "bucket": {
                     "name": "ropsten-marketplace-service-assets",
                     "ownerIdentity": {
                         "principalId": "A1AEOFBS4PX33"
                     },
                     "arn":
                     "arn:aws:s3:::ropsten-marketplace-service-assets"
                 },
                 "object": {
                     "key":
                     "test_org_uuid/services/test_service_uuid/proto/20210618114940_proto_files.zip",
                     "size": 374,
                     "eTag": "57a5f8d4130aab3172c6aac7b898c4d7",
                     "sequencer": "0060CC8854D23C18E7"
                 }
             }
         }]
     }
     response = update_service_assets(event=event, context=None)
     service = ServicePublisherRepository(
     ).get_service_for_given_service_uuid(org_uuid="test_org_uuid",
                                          service_uuid="test_service_uuid")
     assert response["statusCode"] == 200
     assert service.assets == {
         "demo_files": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/component/20210228000436_component.zip",
             "build_id": "sample_build_id",
             "ipfs_hash": "QmUKfyv5c8Ru93xyxTcXGswnNzuBTCBU9NGjMV7SMwLSgy"
         },
         "hero_image": {
             "url":
             "https://marketplace-registry-assets.s3.amazonaws.com/6509581150c8446e8a73b3fa71ebdb69/services/05676ad531cd40a889841ff1f3c5608b/assets/20210127060152_asset.png",
             "ipfs_hash":
             "QmdSh54XcNPJo8v89LRFDN5FAoGL92mn174rKFzoHwUCM1/20210127060152_asset.png"
         },
         "proto_files": {
             "url":
             "https://ropsten-marketplace-service-assets.s3.us-east-1.amazonaws.com/test_org_uuid/services/test_service_uuid/proto/20210618114940_proto_files.zip",
             "status": "SUCCEEDED"
         }
     }