示例#1
0
    def test_create_user(self, mock_ctrl, mock_model, mock_factory, mock_resp,
                         mock_redirect):
        """
        Test user creation.
        """
        request = mock.MagicMock()
        request.body = json.dumps({
            'login': '******',
            'name': 'test-user',
            'password': '******'
        })
        mock_model.SERIALIZER.return_value.data = {
            '_id': 'copy to id',
            '_href': 'mock/path'
        }
        user = UsersView()
        response = user.post(request)

        mock_ctrl.create_user.assert_called_once_with('test-user',
                                                      password='******',
                                                      name='test-user')
        mock_model.SERIALIZER.assert_called_once_with(
            mock_ctrl.create_user.return_value)
        mock_auto_perm = mock_factory.permission_manager(
        ).grant_automatic_permissions_for_resource
        mock_auto_perm.assert_called_once_with('mock/path')
        mock_resp.assert_called_once_with({
            'id': 'copy to id',
            '_href': 'mock/path',
            '_id': 'copy to id'
        })
        mock_redirect.assert_called_once_with(mock_resp.return_value,
                                              'mock/path')
        self.assertTrue(response is mock_redirect.return_value)
示例#2
0
    def test_create_user(self, mock_factory, mock_resp, mock_redirect):
        """
        Test user creation.
        """
        resp = {'login': '******', 'name': 'test-user'}
        mock_factory.user_manager.return_value.create_user.return_value = resp

        request = mock.MagicMock()
        request.body = json.dumps({
            'login': '******',
            'name': 'test-user',
            'password': '******'
        })
        user = UsersView()
        response = user.post(request)

        expected_cont = {
            '_href': '/v2/users/test-user/',
            'login': '******',
            'name': 'test-user'
        }
        mock_resp.assert_called_once_with(expected_cont)
        mock_redirect.assert_called_once_with(mock_resp.return_value,
                                              expected_cont['_href'])
        self.assertTrue(response is mock_redirect.return_value)
示例#3
0
 def test_create_missing_login(self):
     """
     Test user creation with missing login.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'name': 'test-user'})
     user = UsersView()
     try:
         response = user.post(request)
     except MissingValue, response:
         pass
示例#4
0
文件: test_users.py 项目: kaos/pulp
 def test_create_missing_login(self):
     """
     Test user creation with missing login.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'name': 'test-user'})
     user = UsersView()
     try:
         response = user.post(request)
     except MissingValue, response:
         pass
示例#5
0
文件: test_users.py 项目: alanoe/pulp
 def test_get_users(self, mock_model, mock_resp):
     """
     Test users retrieval.
     """
     request = mock.MagicMock()
     view = UsersView()
     response = view.get(request)
     mock_model.SERIALIZER.assert_called_once_with(mock_model.objects.return_value,
                                                   multiple=True)
     mock_resp.assert_called_once_with(mock_model.SERIALIZER.return_value.data)
     self.assertTrue(response is mock_resp.return_value)
示例#6
0
 def test_get_users(self, mock_model, mock_resp):
     """
     Test users retrieval.
     """
     request = mock.MagicMock()
     view = UsersView()
     response = view.get(request)
     mock_model.serializer.assert_called_once_with(mock_model.objects.return_value,
                                                   multiple=True)
     mock_resp.assert_called_once_with(mock_model.serializer.return_value.data)
     self.assertTrue(response is mock_resp.return_value)
示例#7
0
文件: test_users.py 项目: kaos/pulp
 def test_create_invalid_param(self):
     """
     Test user creation with invalid param.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'login': '******', 'password': '******',
                                'invalid_param': 'invalid'})
     user = UsersView()
     try:
         response = user.post(request)
     except InvalidValue, response:
         pass
示例#8
0
 def test_create_invalid_param(self):
     """
     Test user creation with invalid param.
     """
     request = mock.MagicMock()
     request.body = json.dumps({'login': '******', 'password': '******',
                                'invalid_param': 'invalid'})
     user = UsersView()
     try:
         response = user.post(request)
     except InvalidValue, response:
         pass
示例#9
0
文件: test_users.py 项目: kaos/pulp
    def test_get_users(self, mock_factory, mock_resp):
        """
        Test users retrieval.
        """
        existing_users = [{'login': '******', 'name': 'test-user', 'id': '12345'}]
        mock_factory.user_query_manager.return_value.find_all.return_value = existing_users

        request = mock.MagicMock()
        view = UsersView()
        response = view.get(request)

        expected_cont = [{'_href': '/v2/users/test-user/', 'login': '******',
                          'name': 'test-user'}]
        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
示例#10
0
文件: test_users.py 项目: kaos/pulp
    def test_create_user(self, mock_factory, mock_resp, mock_redirect):
        """
        Test user creation.
        """
        resp = {'login': '******', 'name': 'test-user'}
        mock_factory.user_manager.return_value.create_user.return_value = resp

        request = mock.MagicMock()
        request.body = json.dumps({'login': '******', 'name': 'test-user', 'password': '******'})
        user = UsersView()
        response = user.post(request)

        expected_cont = {'_href': '/v2/users/test-user/', 'login': '******',
                         'name': 'test-user'}
        mock_resp.assert_called_once_with(expected_cont)
        mock_redirect.assert_called_once_with(mock_resp.return_value, expected_cont['_href'])
        self.assertTrue(response is mock_redirect.return_value)
示例#11
0
文件: test_users.py 项目: alanoe/pulp
    def test_create_user(self, mock_ctrl, mock_model, mock_factory, mock_resp, mock_redirect):
        """
        Test user creation.
        """
        request = mock.MagicMock()
        request.body = json.dumps({'login': '******', 'name': 'test-user', 'password': '******'})
        mock_model.SERIALIZER.return_value.data = {'_id': 'copy to id', '_href': 'mock/path'}
        user = UsersView()
        response = user.post(request)

        mock_ctrl.create_user.assert_called_once_with('test-user', password='******', name='test-user')
        mock_model.SERIALIZER.assert_called_once_with(mock_ctrl.create_user.return_value)
        mock_auto_perm = mock_factory.permission_manager().grant_automatic_permissions_for_resource
        mock_auto_perm.assert_called_once_with('mock/path')
        mock_resp.assert_called_once_with({'id': 'copy to id', '_href': 'mock/path',
                                           '_id': 'copy to id'})
        mock_redirect.assert_called_once_with(mock_resp.return_value, 'mock/path')
        self.assertTrue(response is mock_redirect.return_value)
示例#12
0
    def test_get_users(self, mock_factory, mock_resp):
        """
        Test users retrieval.
        """
        existing_users = [{
            'login': '******',
            'name': 'test-user',
            'id': '12345'
        }]
        mock_factory.user_query_manager.return_value.find_all.return_value = existing_users

        request = mock.MagicMock()
        view = UsersView()
        response = view.get(request)

        expected_cont = [{
            '_href': '/v2/users/test-user/',
            'login': '******',
            'name': 'test-user'
        }]
        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
示例#13
0
文件: urls.py 项目: hgschmie/pulp
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/distributors/(?P<distributor_id>[^/]+)/$',
        RepoDistributorResourceView.as_view(), name='repo_distributor_resource'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/distributors/(?P<distributor_id>[^/]+)/schedules/publish/$',
        RepoPublishSchedulesView.as_view(), name='repo_publish_schedules'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/distributors/(?P<distributor_id>[^/]+)/schedules/publish/(?P<schedule_id>[^/]+)/$',
        RepoPublishScheduleResourceView.as_view(), name='repo_publish_schedule_resource'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/history/sync/$', RepoSyncHistory.as_view(),
        name='repo_sync_history'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/history/publish/(?P<distributor_id>[^/]+)/$',
        RepoPublishHistory.as_view(), name='repo_publish_history'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/actions/sync/$', RepoSync.as_view(),
        name='repo_sync'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/actions/publish/$', RepoPublish.as_view(),
        name='repo_publish'),
    url(r'^v2/repositories/(?P<dest_repo_id>[^/]+)/actions/associate/$', RepoAssociate.as_view(),
        name='repo_associate'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/actions/unassociate/$', RepoUnassociate.as_view(),
        name='repo_unassociate'),
    url(r'^v2/repositories/(?P<repo_id>[^/]+)/actions/import_upload/$', RepoImportUpload.as_view(),
        name='repo_import_upload'),
    url(r'^v2/roles/$', RolesView.as_view(), name='roles'),
    url(r'^v2/roles/(?P<role_id>[^/]+)/$', RoleResourceView.as_view(), name='role_resource'),
    url(r'^v2/roles/(?P<role_id>[^/]+)/users/$', RoleUsersView.as_view(), name='role_users'),
    url(r'^v2/roles/(?P<role_id>[^/]+)/users/(?P<login>[^/]+)/$', RoleUserView.as_view(), name='role_user'),
    url(r'^v2/status/$', StatusView.as_view(), name='status'),
    url(r'^v2/tasks/$', TaskCollectionView.as_view(), name='task_collection'),
    url(r'^v2/tasks/(?P<task_id>[^/]+)/$', TaskResourceView.as_view(), name='task_resource'),
    url(r'^v2/users/$', UsersView.as_view(), name='users'),
    url(r'^v2/users/(?P<login>[^/]+)/$', UserResourceView.as_view(), name='user_resource')
)