def setUp(self): self.view = views.CreateProjectView.as_view() self.request = fake_request(method='GET') self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.is_superuser = True self.request.user.is_authenticated = lambda: True patch('actionlogger.ActionLogger.log', Mock(return_value=None)).start() self.mock_keystone_is_allowed = patch('identity.keystone.Keystone._is_allowed_to_connect').start() self.mock_keystone_find_user = patch('identity.keystone.Keystone.return_find_u_user').start() # Retorna objeto usuário similar ao do request self.mock_keystone_find_user.return_value = fake_request(method='GET').user self.mock_area = patch('identity.forms.Area.objects.all').start() self.mock_area.return_value = [AreaFactory(id=1)] patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def setUp(self): self.view = UpdateProjectUserPasswordView.as_view() self.request = fake_request(method='GET') self.request.user.is_superuser = True self.mock_keystone_find_user = patch('identity.keystone.Keystone.return_find_u_user').start() # Retorna objeto usuário similar ao do request self.mock_keystone_find_user.return_value = fake_request(method='GET').user self.mock_users_list = patch('identity.keystone.Keystone.user_list').start() self.mock_users_list.return_value = [fake_request(method='GET').user] patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def test_get_storage_endpoint_without_service_catalog(self): user = fakes.FakeUser(1, 'user') request = fake_request(user=user) request.session['service_catalog'] = None endpoint = utils.get_storage_endpoint(request, 'internalURL') self.assertEqual(endpoint, None)
def test_delete_user_role_needs_authentication(self): req = fake_request(method='POST', user=False) self.request.user.token = None response = self.view(req) self.assertEqual(response.status_code, 302)
def test_get_endpoint_without_service_catalog(self): user = fakes.FakeUser(1, 'user') request = fake_request(user=user) request.session['service_catalog'] = None with self.assertRaises(ValueError): utils.get_endpoint(request, 'internalURL')
def setUp(self): self.request = fake_request() self.mock_keystone_is_allowed = patch( 'identity.keystone.Keystone._is_allowed_to_connect').start() self.mock_keystone_client = patch( 'identity.keystone.client.Client').start()
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 test_create_user_needs_authentication(self): req = fake_request(user=False) self.request.user.token = None response = self.view(req) self.assertEqual(response.status_code, 302)
def setUp(self): patch('identity.keystone.Keystone._create_keystone_connection').start() patch('identity.views.actionlog.log').start() patch('identity.views.log').start() patch('identity.views.Keystone.project_get', return_value=FakeResource(1, 'fake_resource')).start() self.mock_get_context_data = patch( 'identity.views.UpdateProjectView.get_context_data').start() # Mock form validation. It's mocked as a invalid form. form = patch('identity.views.ProjectForm').start() self.form_is_valid = form.return_value.is_valid self.view = views.UpdateProjectView.as_view() self.request = fake_request(method='POST') post = self.request.POST.copy() post.update({ 'name': 'update_teste', 'description': 'update desc', 'group': 1, 'enabled': 'False' }) self.request.POST = post
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 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() self.user_id = 'abcdefghiklmnopq' self.user_name = 'user_name' self.project = Project( '321', { u'id': str(uuid4()), u'name': 'project_test_delete', u'description': 'project test delete description', u'enabled': True }) self.mock_keystone_conn = patch( 'identity.keystone.Keystone._create_keystone_connection').start() self.mock_project_get_by_name = patch( 'identity.keystone.Keystone.project_get_by_name').start() self.mock_project_get_by_name.return_value = self.project self.mock_find_user_with_u_prefix = patch( 'identity.keystone.Keystone.find_user_with_u_prefix').start() self.mock_find_user_with_u_prefix.return_value = FakeResource( self.user_id, name=self.user_name)
def setUp(self): self.view = UpdateProjectUserPasswordView.as_view() self.request = fake_request(method='POST') post = self.request.POST.copy() post.update({"project": "AProjectID"}) self.request.POST = post self.mock_keystone_find_user = patch( 'identity.keystone.Keystone.find_user_with_u_prefix').start() self.mock_keystone_find_user.return_value = self.request.user self.mock_users_list = patch( 'identity.keystone.Keystone.user_list').start() self.mock_users_list.return_value = [fake_request(method='GET').user] patch('identity.keystone.Keystone._create_keystone_connection').start()
def setUp(self): self.view = DashboardView.as_view() self.request = fake_request(method='GET') self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.is_authenticated = lambda: True
def setUp(self): self.view = ListUserView.as_view() self.request = fake_request(method='GET') self.request.user.is_superuser = True patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def setUp(self): patch('identity.keystone.Keystone._create_keystone_connection').start() patch('identity.views.actionlog.log').start() patch('identity.views.log').start() patch('identity.views.DeleteProjectView.get_context_data').start() self.form = patch('identity.views.DeleteProjectConfirm').start() self.view = views.DeleteProjectView.as_view() self.request = fake_request(method='GET')
def setUp(self): self.request = fake_request() self.request.user.is_superuser = True self.keystone = Keystone(self.request) self.project = None self.user = None
def setUp(self): self.view = self.view_class.as_view() self.request = fake_request(method='POST') self.request.user.token = FakeToken self.request.user.is_superuser = True patch('identity.keystone.Keystone._create_keystone_connection').start() patch('identity.views.log').start()
def setUp(self): self.request = fake_request() # silence log patch('storage.views.log', Mock(return_value=None)).start() patch('identity.keystone.Keystone', Mock(return_value=None)).start()
def setUp(self): self.view = UpdateProjectUserPasswordView.as_view() self.request = fake_request(method='GET') self.request.user.is_superuser = True self.mock_keystone_find_user = patch( 'identity.keystone.Keystone.return_find_u_user').start() # Retorna objeto usuário similar ao do request self.mock_keystone_find_user.return_value = fake_request( method='GET').user self.mock_users_list = patch( 'identity.keystone.Keystone.user_list').start() self.mock_users_list.return_value = [fake_request(method='GET').user] patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def setUp(self): self.request = fake_request() self.mock_filter = patch('identity.keystone.GroupProjects.objects.filter').start() self.mock_model_project_get = patch('identity.keystone.Project.objects.get').start() self.mock_model_project_get.return_value = ProjectFactory() self.mock_keystone_client = patch('identity.keystone.client').start()
def setUp(self): self.request = fake_request() self.project_id = "1ad2d06a38c643fb8550fe35b0ef579a_test" self.container = "container_test" # silence log patch('storage.views.log', Mock(return_value=None)).start() patch('identity.keystone.Keystone', Mock(return_value=None)).start()
def test_maybe_update_token_without_time_token_value( self, keystone_conn_mock): conn_mock = keystone_conn_mock.return_value conn_mock.auth_token = '12345678' request = fake_request(method='GET') request.session['token_time'] = None result = utils.maybe_update_token(request) self.assertTrue(result)
def setUp(self): self.view = views.ListProjectView.as_view() self.request = fake_request(method='GET') self.mock_keystone_is_allowed = patch('identity.keystone.Keystone._is_allowed_to_connect').start() self.mock_area = patch('identity.forms.Area.objects.all').start() self.mock_area.return_value = [AreaFactory(id=1)] patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def setUp(self): self.request = fake_request() self.mock_filter = patch( 'identity.keystone.GroupProjects.objects.filter').start() self.mock_model_project_get = patch( 'identity.keystone.Project.objects.get').start() self.mock_model_project_get.return_value = ProjectFactory() self.mock_keystone_client = patch('identity.keystone.client').start()
def setUp(self): self.view = self.view_class.as_view() self.request = fake_request(method='POST') self.request.user.is_authenticated = lambda: True self.request.user.token = FakeToken self.request.user.is_superuser = True patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
def test_maybe_update_token_with_valid_time_token(self, keystone_conn_mock): conn_mock = keystone_conn_mock.return_value conn_mock.auth_token = '12345678' request = fake_request(method='GET') valid_time = datetime.datetime.utcnow() + datetime.timedelta( minutes=15) request.session['token_time'] = valid_time result = utils.maybe_update_token(request) self.assertFalse(result)
def setUp(self): self.view = views.CreateProjectSuccessView.as_view() self.request = fake_request(method='GET') self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.is_superuser = True self.request.user.is_authenticated = lambda: True self.mock_keystone_conn = patch('identity.keystone.Keystone._keystone_conn').start() self.mock_is_allowed_to_connect = patch('identity.keystone.Keystone._is_allowed_to_connect').start()
def test_add_user_and_team_flow_from_user_fail(self): req = fake_request(method='POST') req.user.is_superuser = False post = req.POST.copy() post.setdefault('group', int('10')) post.setdefault('user', int('1')) req.POST = post response = self.view(req) self.assertEqual(response.status_code, 500)
def setUp(self): self.view = UpdateUserView.as_view() self.request = fake_request() self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.is_superuser = False self.request.user.token = FakeToken patch('actionlogger.actionlogger.ActionLogger.log', Mock(return_value=None)).start()
def setUp(self): self.request = fake_request() self.project_id = 'rstuvwxyz' self.user_id = 'abcdefghiklmnopq' self.user_name = 'user_name' self.mock_keystone_conn = patch('identity.keystone.Keystone._keystone_conn').start() self.mock_project_delete = patch('identity.keystone.Keystone.project_delete').start() self.mock_user_delete = patch('identity.keystone.Keystone.user_delete').start() self.mock_return_find_u_user = patch('identity.keystone.Keystone.return_find_u_user').start() self.mock_return_find_u_user.return_value = FakeResource(self.user_id, name=self.user_name)
def setUp(self): self.view = DeleteUserView.as_view() self.request = fake_request() self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.token = FakeToken patch('actionlogger.actionlogger.ActionLogger.log', Mock(return_value=None)).start() patch('identity.keystone.Keystone._create_keystone_connection').start()
def setUp(self): self.view = UpdateUserView.as_view() self.request = fake_request() self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.token = FakeToken patch('actionlogger.actionlogger.ActionLogger.log', Mock(return_value=None)).start() # does not connect to the keystone client patch('keystoneclient.v3.client.Client').start()
def setUp(self): self.view = DeleteUserView.as_view() self.request = fake_request() self.request.META.update({ 'SERVER_NAME': 'globo.com', 'SERVER_PORT': '80' }) self.request.user.is_superuser = True self.request.user.is_authenticated = lambda: True self.request.user.token = FakeToken patch('actionlogger.ActionLogger.log', Mock(return_value=None)).start() patch('identity.keystone.Keystone._keystone_conn', Mock(return_value=None)).start()
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 setUp(self): self.request = fake_request(method='GET') self.request.user.is_authenticated = lambda: True
def setUp(self): self.view = SetProjectView.as_view() self.request = fake_request(method='GET') self.request.user.is_authenticated = lambda: False
def setUp(self): self.request = fake_request() self.mock_keystone_is_allowed = patch('identity.keystone.Keystone._is_allowed_to_connect').start() self.mock_keystone_client = patch('identity.keystone.client.Client').start()