'Test that resulting resource has the right prop and attrib schema.
Note that this test requires the Wordpress_Single_Instance.yaml
template in the templates directory since we want to test using a
non-trivial template.'

def test_template_as_resource(self):

    test_templ_name = 'WordPress_Single_Instance.yaml'
    path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates', test_templ_name)
    self.assertIn(test_templ_name, os.listdir(os.path.dirname(path)))
    with open(path) as test_templ_file:
        test_templ = test_templ_file.read()
    self.assertTrue(test_templ, 'Empty    test    template')
    self.m.StubOutWithMock(urlfetch, 'get')
    urlfetch.get(test_templ_name, allowed_schemes=('http', 'https')).AndReturn(test_templ)
    parsed_test_templ = template_format.parse(test_templ)
    self.m.ReplayAll()
    stack = parser.Stack(utils.dummy_context(), 'test_stack', template.Template(empty_template), stack_id=str(uuid.uuid4()))
    properties = {'KeyName': 'mykeyname', 'DBName': 'wordpress1', 'DBUsername': 'wpdbuser', 'DBPassword': 'wpdbpass', 'DBRootPassword': 'wpdbrootpass', 'LinuxDistribution': 'U10'}
    definition = rsrc_defn.ResourceDefinition('test_templ_resource', test_templ_name, properties)
    templ_resource = resource.Resource('test_templ_resource', definition, stack)
    self.m.VerifyAll()
    self.assertIsInstance(templ_resource, template_resource.TemplateResource)
    for prop in parsed_test_templ.get('Parameters', {}):
        self.assertIn(prop, templ_resource.properties)
    for attrib in parsed_test_templ.get('Outputs', {}):
        self.assertIn(attrib, templ_resource.attributes)
    for (k, v) in properties.items():
        self.assertEqual(v, templ_resource.properties[k])
    self.assertEqual({'WordPress_Single_Instance.yaml': 'WordPress_Single_Instance.yaml', 'resources': {}}, stack.env.user_env_as_dict()['resource_registry'])
    self.assertNotIn('WordPress_Single_Instance.yaml', resources.global_env().registry._registry)
