Exemplo n.º 1
0
    def test_get_single_role(self, mock_f, mock_resp):
        """
        Test single role retrieval.
        """
        resp = {
            'id': 'test_role',
            'users': [{
                'login': '******'
            }],
            'permissions': [{
                'resource': '/',
                'permission': [0]
            }]
        }
        users = [{'login': '******'}]
        mock_f.role_query_manager.return_value.find_by_id.return_value = resp
        mock_f.user_query_manager.return_value.find_users_belonging_to_role.return_value = users
        mock_f.permission_manager.return_value.operation_value_to_name.return_value = 'READ'

        request = mock.MagicMock()
        role = RoleResourceView()
        response = role.get(request, 'test_role')
        expected_cont = {
            'id': 'test_role',
            'permissions': {
                '/': ['READ']
            },
            'users': ['test'],
            '_href': '/v2/roles/test_role/'
        }

        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 2
0
    def test_get_nonexistent_role(self, mock_factory):
        """
        Test invalid role retrieval.
        """
        mock_factory.role_query_manager.return_value.find_by_id.return_value = None

        request = mock.MagicMock()
        role = RoleResourceView()

        try:
            response = role.get(request, 'nonexistent_id')
        except MissingResource, response:
            pass
Exemplo n.º 3
0
    def test_get_nonexistent_role(self, mock_factory):
        """
        Test invalid role retrieval.
        """
        mock_factory.role_query_manager.return_value.find_by_id.return_value = None

        request = mock.MagicMock()
        role = RoleResourceView()

        try:
            response = role.get(request, 'nonexistent_id')
        except MissingResource, response:
            pass
Exemplo n.º 4
0
    def test_role_deletion(self, mock_factory, mock_resp):
        """
        Test role deletion.
        """
        mock_factory.role_manager.return_value.delete_role.return_value = None

        request = mock.MagicMock()
        role_resource = RoleResourceView()
        response = role_resource.delete(request, 'test-role')

        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
        mock_factory.role_manager.return_value.delete_role.assert_called_once_with('test-role')
Exemplo n.º 5
0
    def test_update_role(self, mock_factory, mock_resp):
        """
        Test role update.
        """
        resp = {'id': 'foo', 'display_name': 'bar'}
        expected_cont = {'id': 'foo', 'display_name': 'bar', '_href': '/v2/roles/foo/'}

        request = mock.MagicMock()
        request.body = json.dumps({'display_name': 'bar'})
        mock_factory.role_manager.return_value.update_role.return_value = resp
        role_resource = RoleResourceView()
        response = role_resource.put(request, 'foo')

        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 6
0
    def test_get_single_role(self, mock_ctrl, mock_f, mock_resp):
        """
        Test single role retrieval.
        """
        resp = {'id': 'test_role', 'users': [{'login': '******'}],
                'permissions': [{'resource': '/', 'permission': [0]}]}
        user = mock.MagicMock()
        mock_f.role_query_manager.return_value.find_by_id.return_value = resp
        mock_ctrl.find_users_belonging_to_role.return_value = [user]
        mock_f.permission_manager.return_value.operation_value_to_name.return_value = 'READ'

        request = mock.MagicMock()
        role = RoleResourceView()
        response = role.get(request, 'test_role')
        expected_cont = {'id': 'test_role', 'permissions': {'/': ['READ']}, 'users': [user.login],
                         '_href': '/v2/roles/test_role/'}

        mock_resp.assert_called_once_with(expected_cont)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 7
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')
)
Exemplo n.º 8
0
     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/$',
     tasks.TaskCollectionView.as_view(),
     name='task_collection'),
 url(r'^v2/tasks/search/$',
     tasks.TaskSearchView.as_view(),
     name='task_search'),
 url(r'^v2/tasks/(?P<task_id>[^/]+)/$',
Exemplo n.º 9
0
        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/$', tasks.TaskCollectionView.as_view(), name='task_collection'),
    url(r'^v2/tasks/search/$', tasks.TaskSearchView.as_view(), name='task_search'),
    url(r'^v2/tasks/(?P<task_id>[^/]+)/$', tasks.TaskResourceView.as_view(), name='task_resource'),
    url(r'^v2/users/$', users.UsersView.as_view(), name='users'),
    url(r'^v2/users/search/$', users.UserSearchView.as_view(),
        name='user_search'),
    url(r'^v2/users/(?P<login>[^/]+)/$', users.UserResourceView.as_view(), name='user_resource')
)