

def test_resource_loads_references(self):
    model = {
        'shape': 'InstanceShape',
        'identifiers': [{
            'name': 'GroupId',
        }],
        'has': {
            'Subnet': {
                'resource': {
                    'type': 'Subnet',
                    'identifiers': [{
                        'target': 'Id',
                        'source': 'data',
                        'path': 'SubnetId',
                    }],
                },
            },
            'Vpcs': {
                'resource': {
                    'type': 'Vpc',
                    'identifiers': [{
                        'target': 'Id',
                        'source': 'data',
                        'path': 'Vpcs[].Id',
                    }],
                },
            },
        },
    }
    defs = {
        'Subnet': {
            'identifiers': [{
                'name': 'Id',
            }],
        },
        'Vpc': {
            'identifiers': [{
                'name': 'Id',
            }],
        },
    }
    service_model = ServiceModel({
        'shapes': {
            'InstanceShape': {
                'type': 'structure',
                'members': {
                    'SubnetId': {
                        'shape': 'String',
                    },
                },
            },
            'String': {
                'type': 'string',
            },
        },
    })
    resource = self.load('Instance', model, defs, service_model)('group-id')
    resource.meta.data = {
        
    }
    self.assertTrue(hasattr(resource, 'subnet'), 'Resource should have a subnet reference')
    self.assertIsNone(resource.subnet, 'Missing identifier, should return None')
    self.assertIsNone(resource.vpcs)
    resource.meta.data = {
        'SubnetId': 'abc123',
        'Vpcs': [{
            'Id': 'vpc1',
        }, {
            'Id': 'vpc2',
        }],
    }
    self.assertIsInstance(resource.subnet, ServiceResource)
    self.assertEqual(resource.subnet.id, 'abc123')
    vpcs = resource.vpcs
    self.assertIsInstance(vpcs, list)
    self.assertEqual(len(vpcs), 2)
    self.assertEqual(vpcs[0].id, 'vpc1')
    self.assertEqual(vpcs[1].id, 'vpc2')

dataset/ETHPy150Open boto/boto3/tests/unit/resources/test_factory.py TestResourceFactory.test_resource_loads_references/original