def test_put_projects_ok(self, mock_get_project_list, mock_get_keystone_admin_auth, mock_get_admin_role_user_ids, mock_get_swift_url_and_token, mock_put_container, mock_post_account, mock_create_docker_image): mock_get_project_list.return_value = { '0123456789abcdef': 'tenantA', 'abcdef0123456789': 'tenantB' } mock_get_swift_url_and_token.return_value = ( 'http://example.com/fakeurl', 'fakeToken', ) mock_get_admin_role_user_ids.return_value = ( 'fakeId', 'fakeId', 'fakeName', ) project_id = 'abcdef0123456789' request = self.factory.put('/projects' + project_id) response = projects(request, project_id) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(mock_put_container.call_count, 2) mock_post_account.assert_called_with('http://example.com/fakeurl', 'fakeToken', mock.ANY) mock_create_docker_image.assert_called_with(mock.ANY, project_id) # Check request = self.factory.get('/projects') response = projects(request) self.assertEqual(response.status_code, status.HTTP_200_OK) enabled_projects = json.loads(response.content) self.assertEqual(len(enabled_projects), 2) self.assertTrue('abcdef0123456789' in enabled_projects)
def test_get_projects_ok(self): request = self.factory.get('/projects') response = projects(request) self.assertEqual(response.status_code, status.HTTP_200_OK) enabled_projects = json.loads(response.content) self.assertEqual(len(enabled_projects), 1) self.assertEqual(enabled_projects[0], '0123456789abcdef')
def test_check_projects_non_existent(self): project_id = 'abcdef0123456789' request = self.factory.post('/projects/' + project_id) response = projects(request, project_id) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_projects_method_not_allowed(self): # HEAD method is not allowed request = self.factory.head('/projects') response = projects(request) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_check_projects_ok(self): project_id = '0123456789abcdef' request = self.factory.post('/projects/' + project_id) response = projects(request, project_id) self.assertEqual(response.status_code, status.HTTP_200_OK)