'Test the special storage of domain_id=None in sql resource driver.
The resource driver uses a special value in place of None for domain_id
in the project record. This shouldn\'t escape the driver. Hence we test
the interface to ensure that you can store a domain_id of None, and
that any special value used inside the driver does not escape through
the interface.'

def test_storing_null_domain_id_in_project_ref(self):

    spoiler_project = unit.new_project_ref(domain_id=CONF.identity.default_domain_id)
    self.resource_api.create_project(spoiler_project['id'], spoiler_project)
    project = unit.new_project_ref(domain_id=None, is_domain=True)
    project = self.resource_api.create_project(project['id'], project)
    ref = self.resource_api.get_project(project['id'])
    self.assertDictEqual(project, ref)
    ref = self.resource_api.get_project_by_name(project['name'], None)
    self.assertDictEqual(project, ref)
    project2 = unit.new_project_ref(domain_id=None, is_domain=True)
    project2 = self.resource_api.create_project(project2['id'], project2)
    hints = driver_hints.Hints()
    hints.add_filter('domain_id', None)
    refs = self.resource_api.list_projects(hints)
    self.assertThat(refs, matchers.HasLength((2 + self.domain_count)))
    self.assertIn(project, refs)
    self.assertIn(project2, refs)
    project['name'] = uuid.uuid4().hex
    self.resource_api.update_project(project['id'], project)
    ref = self.resource_api.get_project(project['id'])
    self.assertDictEqual(project, ref)
    project['enabled'] = False
    self.resource_api.update_project(project['id'], project)
    self.resource_api.delete_project(project['id'])
    self.assertRaises(exception.ProjectNotFound, self.resource_api.get_project, project['id'])
