def setUp(self): self.view = views.DeleteProjectView.as_view() self.request = fake_request() self.request.method = 'POST' self.request.user.is_authenticated = lambda: True post = self.request.POST.copy() post.update({ 'user': '******', 'password': '******'}) self.request.POST = post patch('actionlogger.ActionLogger.log', Mock(return_value=None)).start() # # kwargs = { # 'remote_addr': request.environ.get('REMOTE_ADDR', ''), # 'auth_url': getattr(settings, 'KEYSTONE_URL'), # 'insecure': True, # 'tenant_name': self.tenant_name, # 'username': self.username, # 'password': self.password, # 'timeout': 3, # } fake_project = FakeResource(n='abcdefg', name='fake_project') fake_project.description = 'desc do fake' # Mocking Keystone class used on vault views mixin self.mock_vault_keystone = patch('vault.views.Keystone').start() self.mock_project_get = patch('identity.keystone.Keystone.project_get').start() self.mock_project_get.return_value = fake_project
def setUp(self): self.request = fake_request() self.project = Project( '123', { u'id': str(uuid4()), u'name': 'project_test', u'description': 'project description', u'domain_id': 'default', u'enabled': True }) self.mock_project_create = patch( 'identity.keystone.Keystone.project_create').start() self.mock_project_create.return_value = self.project self.mock_project_update = patch( 'identity.keystone.Keystone.project_update').start() self.mock_project_update.return_value = self.project fake_project = FakeResource(n='abcdefg', name='fake_project') fake_project.description = 'desc do fake' self.mock_project_get = patch( 'identity.keystone.Keystone.project_get').start() self.mock_project_get.return_value = fake_project self.mock_keystone_conn = patch( 'identity.keystone.Keystone._create_keystone_connection').start() self.group = GroupFactory(id=1)
def setUp(self): self.request = fake_request() project_id = 'abcdefghiklmnopq' project_name = 'project_test' project_desc = 'project description' self.project = ProjectFactory(id=project_id, name=project_name, description=project_desc) self.mock_project_create = patch( 'identity.keystone.Keystone.project_create').start() self.mock_project_create.return_value = self.project self.mock_project_update = patch( 'identity.keystone.Keystone.project_update').start() self.mock_project_update.return_value = self.project fake_project = FakeResource(n='abcdefg', name='fake_project') fake_project.description = 'desc do fake' self.mock_project_get = patch( 'identity.keystone.Keystone.project_get').start() self.mock_project_get.return_value = fake_project self.mock_keystone_conn = patch( 'identity.keystone.Keystone._keystone_conn').start() self.group = GroupFactory(id=1) self.area = AreaFactory(id=1)
def test_initial_data_loaded(self, mock_ap, mock_gp): group_id = 123 area_id = 456 mock_gp.return_value = GroupProjectsFactory(id=1, group_id=group_id) mock_ap.return_value = AreaProjectsFactory(id=2, area_id=area_id) project = FakeResource(1, 'project1') project.default_project_id = 1 project.description = 'description' project.to_dict = lambda: {'name': project.name, 'description': project.description} patch('identity.keystone.Keystone.project_get', Mock(return_value=project)).start() response = self.view(self.request, project_id='project_id') computed_form = response.context_data['form'] self.assertEqual(computed_form.initial['name'], project.name) self.assertEqual(computed_form.initial['description'], project.description) self.assertEqual(computed_form.initial['groups'], group_id) self.assertEqual(computed_form.initial['areas'], area_id)
def setUp(self): self.request = fake_request() project_id = 'abcdefghiklmnopq' project_name = 'project_test' project_desc = 'project description' self.project = ProjectFactory(id=project_id, name=project_name, description=project_desc) self.mock_project_create = patch('identity.keystone.Keystone.project_create').start() self.mock_project_create.return_value = self.project self.mock_project_update = patch('identity.keystone.Keystone.project_update').start() self.mock_project_update.return_value = self.project fake_project = FakeResource(n='abcdefg', name='fake_project') fake_project.description = 'desc do fake' self.mock_project_get = patch('identity.keystone.Keystone.project_get').start() self.mock_project_get.return_value = fake_project self.mock_keystone_conn = patch('identity.keystone.Keystone._keystone_conn').start() self.group = GroupFactory(id=1) self.area = AreaFactory(id=1)