'Test the generated SAML object can become valid XML.
Test the generator directly by passing known arguments, the result
should be a SAML object that consistently includes attributes based on
the known arguments that were passed in.'

def test_valid_saml_xml(self):

    with mock.patch.object(keystone_idp, '_sign_assertion', return_value=self.signed_assertion):
        generator = keystone_idp.SAMLGenerator()
        response = generator.samlize_token(self.ISSUER, self.RECIPIENT, self.SUBJECT, self.SUBJECT_DOMAIN, self.ROLES, self.PROJECT, self.PROJECT_DOMAIN)
    saml_str = response.to_string()
    response = etree.fromstring(saml_str)
    issuer = response[0]
    assertion = response[2]
    self.assertEqual(self.RECIPIENT, response.get('Destination'))
    self.assertEqual(self.ISSUER, issuer.text)
    user_attribute = assertion[4][0]
    self.assertEqual(self.SUBJECT, user_attribute[0].text)
    user_domain_attribute = assertion[4][1]
    self.assertEqual(self.SUBJECT_DOMAIN, user_domain_attribute[0].text)
    role_attribute = assertion[4][2]
    for attribute_value in role_attribute:
        self.assertIn(attribute_value.text, self.ROLES)
    project_attribute = assertion[4][3]
    self.assertEqual(self.PROJECT, project_attribute[0].text)
    project_domain_attribute = assertion[4][4]
    self.assertEqual(self.PROJECT_DOMAIN, project_domain_attribute[0].text)
