Beispiel #1
0
    def test_get_single_user(self, mock_model, mock_resp):
        """
        Test single user retrieval.
        """
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        mock_model.objects.get_or_404.assert_called_once_with(login='******')
        mock_resp.assert_called_once_with(mock_model.SERIALIZER.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #2
0
    def test_get_single_user(self, mock_model, mock_resp):
        """
        Test single user retrieval.
        """
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        mock_model.objects.get_or_404.assert_called_once_with(login='******')
        mock_resp.assert_called_once_with(mock_model.serializer.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #3
0
    def test_get_invalid_user(self, mock_factory):
        """
        Test nonexistent user retrieval.
        """
        mock_factory.user_query_manager.return_value.find_by_login.return_value = None

        request = mock.MagicMock()
        user = UserResourceView()
        try:
            response = user.get(request, 'nonexistent_login')
        except MissingResource, response:
            pass
Beispiel #4
0
    def test_get_invalid_user(self, mock_factory):
        """
        Test nonexistent user retrieval.
        """
        mock_factory.user_query_manager.return_value.find_by_login.return_value = None

        request = mock.MagicMock()
        user = UserResourceView()
        try:
            response = user.get(request, 'nonexistent_login')
        except MissingResource, response:
            pass
Beispiel #5
0
    def test_update_user(self, mock_ctrl, mock_model, mock_resp):
        """
        Test user update
        """
        request = mock.MagicMock()
        request.body = json.dumps({'delta': {'name': 'some-user'}})
        user = UserResourceView()
        response = user.put(request, 'test-user')

        mock_ctrl.update_user.assert_called_once_with('test-user', {'name': 'some-user'})
        mock_model.SERIALIZER.assert_called_once_with(mock_ctrl.update_user.return_value)
        mock_resp.assert_called_once_with(mock_model.SERIALIZER.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #6
0
    def test_delete_single_user(self, mock_ctrl, mock_resp, mock_perm, mock_rev):
        """
        Test user deletion.
        """
        mock_perm().find_one.return_value = 'some'
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.delete(request, 'test-user')

        mock_ctrl.delete_user.assert_called_once_with('test-user')
        mock_resp.assert_called_once_with()
        mock_perm().remove.assert_called_once_with({'resource': mock_rev.return_value})
        self.assertTrue(response is mock_resp.return_value)
Beispiel #7
0
    def test_update_user(self, mock_ctrl, mock_model, mock_resp):
        """
        Test user update
        """
        request = mock.MagicMock()
        request.body = json.dumps({'delta': {'name': 'some-user'}})
        user = UserResourceView()
        response = user.put(request, 'test-user')

        mock_ctrl.update_user.assert_called_once_with('test-user', {'name': 'some-user'})
        mock_model.serializer.assert_called_once_with(mock_ctrl.update_user.return_value)
        mock_resp.assert_called_once_with(mock_model.serializer.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #8
0
    def test_delete_single_user(self, mock_ctrl, mock_resp, mock_perm, mock_rev):
        """
        Test user deletion.
        """
        mock_perm().find_one.return_value = 'some'
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.delete(request, 'test-user')

        mock_ctrl.delete_user.assert_called_once_with('test-user')
        mock_resp.assert_called_once_with()
        mock_perm().remove.assert_called_once_with({'resource': mock_rev.return_value})
        self.assertTrue(response is mock_resp.return_value)
Beispiel #9
0
    def test_delete_single_user(self, mock_factory, mock_resp, mock_perm):
        """
        Test user deletion.
        """
        mock_factory.user_manager.return_value.delete_user.return_value = None
        mock_perm.return_value.find_one.return_value = 'some'

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.delete(request, 'test-user')

        mock_factory.user_manager.return_value.delete_user.assert_called_once_with('test-user')
        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #10
0
    def test_get_single_user(self, mock_f, mock_resp):
        """
        Test single user retrieval.
        """
        user = {'login': '******', 'name': 'test-user', 'id': '12345'}
        mock_f.user_query_manager.return_value.find_by_login.return_value = user

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        expected_cont = {'login': '******', 'name': 'test-user', '_href': '/v2/users/test-user/'}
        mock_resp.assert_called_once_with(expected_cont)
        mock_f.user_query_manager.return_value.find_by_login.assert_called_once_with('test-user')
        self.assertTrue(response is mock_resp.return_value)
Beispiel #11
0
    def test_delete_single_user(self, mock_factory, mock_resp, mock_perm):
        """
        Test user deletion.
        """
        mock_factory.user_manager.return_value.delete_user.return_value = None
        mock_perm.return_value.find_one.return_value = 'some'

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.delete(request, 'test-user')

        mock_factory.user_manager.return_value.delete_user.assert_called_once_with(
            'test-user')
        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #12
0
    def test_update_user(self, mock_factory, mock_resp):
        """
        Test user update
        """
        resp = {'login': '******', 'name': 'some-user', 'id': '12345'}
        mock_factory.user_manager.return_value.update_user.return_value = resp

        request = mock.MagicMock()
        request.body = json.dumps({'delta': {'name': 'some-user'}})
        user = UserResourceView()
        response = user.put(request, 'test-user')

        expected_cont = {'login': '******', 'name': 'some-user'}

        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #13
0
    def test_update_user(self, mock_factory, mock_resp):
        """
        Test user update
        """
        resp = {'login': '******', 'name': 'some-user', 'id': '12345'}
        mock_factory.user_manager.return_value.update_user.return_value = resp

        request = mock.MagicMock()
        request.body = json.dumps({'delta': {'name': 'some-user'}})
        user = UserResourceView()
        response = user.put(request, 'test-user')

        expected_cont = {'login': '******', 'name': 'some-user'}

        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
Beispiel #14
0
    def test_get_single_user(self, mock_f, mock_resp):
        """
        Test single user retrieval.
        """
        user = {'login': '******', 'name': 'test-user', 'id': '12345'}
        mock_f.user_query_manager.return_value.find_by_login.return_value = user

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        expected_cont = {
            'login': '******',
            'name': 'test-user',
            '_href': '/v2/users/test-user/'
        }
        mock_resp.assert_called_once_with(expected_cont)
        mock_f.user_query_manager.return_value.find_by_login.assert_called_once_with(
            'test-user')
        self.assertTrue(response is mock_resp.return_value)
Beispiel #15
0
    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')
)