Beispiel #1
0
def test_delete_user_deletes_user(fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = MagicMock()

    views.delete_user(pyramid_request, user)

    assert user in pyramid_request.db.deleted
Beispiel #2
0
def test_delete_user_raises_when_group_creator(models, pyramid_request):
    user = Mock()

    models.Group.created_by.return_value.count.return_value = 10

    with pytest.raises(views.UserDeletionError):
        views.delete_user(pyramid_request, user)
Beispiel #3
0
def test_delete_user_disassociate_group_memberships(fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = Mock(groups=[Mock()])

    views.delete_user(pyramid_request, user)

    assert user.groups == []
Beispiel #4
0
def test_delete_user_disassociate_group_memberships(fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = Mock(groups=[Mock()])

    views.delete_user(pyramid_request, user)

    assert user.groups == []
Beispiel #5
0
def test_delete_user_deletes_user(fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = MagicMock()

    views.delete_user(pyramid_request, user)

    assert user in pyramid_request.db.deleted
Beispiel #6
0
def test_delete_user_raises_when_group_creator(models, pyramid_request):
    user = Mock()

    models.Group.created_by.return_value.count.return_value = 10

    with pytest.raises(views.UserDeletionError):
        views.delete_user(pyramid_request, user)
Beispiel #7
0
def test_delete_user_disassociate_group_memberships():
    request = Mock()
    user = Mock(groups=[Mock()])

    views.delete_user(request, user)

    assert user.groups == []
Beispiel #8
0
def test_delete_user_deletes_annotations(elasticsearch_helpers, api_storage):
    request, user = Mock(), MagicMock()
    annotation_1 = {'_id': 'annotation-1'}
    annotation_2 = {'_id': 'annotation-2'}

    elasticsearch_helpers.scan.return_value = [annotation_1, annotation_2]

    views.delete_user(request, user)

    assert api_storage.delete_annotation.mock_calls == [
        call(request.db, 'annotation-1'),
        call(request.db, 'annotation-2')
    ]
Beispiel #9
0
def test_delete_user_deletes_annotations(api_storage, elasticsearch_helpers, fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = MagicMock()
    annotation_1 = {'_id': 'annotation-1'}
    annotation_2 = {'_id': 'annotation-2'}

    elasticsearch_helpers.scan.return_value = [annotation_1, annotation_2]

    views.delete_user(pyramid_request, user)

    assert api_storage.delete_annotation.mock_calls == [
        call(pyramid_request.db, 'annotation-1'),
        call(pyramid_request.db, 'annotation-2')
    ]
Beispiel #10
0
def test_delete_user_deletes_annotations(api_storage, elasticsearch_helpers, fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = MagicMock()
    annotation_1 = {'_id': 'annotation-1'}
    annotation_2 = {'_id': 'annotation-2'}

    elasticsearch_helpers.scan.return_value = [annotation_1, annotation_2]

    views.delete_user(pyramid_request, user)

    assert api_storage.delete_annotation.mock_calls == [
        call(pyramid_request.db, 'annotation-1'),
        call(pyramid_request.db, 'annotation-2')
    ]
Beispiel #11
0
def test_delete_user_queries_annotations(elasticsearch_helpers, fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = MagicMock(username=u'bob')

    views.delete_user(pyramid_request, user)

    elasticsearch_helpers.scan.assert_called_once_with(
        client=pyramid_request.es.conn,
        query={
            'query': {
                'filtered': {
                    'filter': {'term': {'user': u'acct:[email protected]'}},
                    'query': {'match_all': {}}
                }
            }
        }
    )
Beispiel #12
0
def test_delete_user_queries_annotations(elasticsearch_helpers, factories, fake_db_session, pyramid_request):
    pyramid_request.db = fake_db_session
    user = factories.User(username=u'bob')

    views.delete_user(pyramid_request, user)

    elasticsearch_helpers.scan.assert_called_once_with(
        client=pyramid_request.es.conn,
        query={
            'query': {
                'filtered': {
                    'filter': {'term': {'user': u'acct:[email protected]'}},
                    'query': {'match_all': {}}
                }
            }
        }
    )
Beispiel #13
0
def test_delete_user_queries_annotations(elasticsearch_helpers):
    request = DummyRequest(es=Mock(), db=Mock())
    user = MagicMock(username=u'bob')

    views.delete_user(request, user)

    elasticsearch_helpers.scan.assert_called_once_with(
        client=request.es.conn,
        query={
            'query': {
                'filtered': {
                    'filter': {'term': {'user': u'acct:[email protected]'}},
                    'query': {'match_all': {}}
                }
            }
        }
    )
Beispiel #14
0
def test_delete_user_deletes_user():
    request, user = Mock(), MagicMock()

    views.delete_user(request, user)

    request.db.delete.assert_called_once_with(user)