Пример #1
0
def test_users_index_looks_up_users_by_username(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"}, es=es)

    views.users_index(request)

    User.get_by_username.assert_called_with("bob")
Пример #2
0
def test_users_index_queries_annotation_count_by_userid(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"}, es=es)

    User.get_by_username.return_value.username = '******'

    views.users_index(request)

    expected_query = {
        'query': {
            'filtered': {
                'filter': {
                    'term': {
                        'user': u'acct:[email protected]'
                    }
                },
                'query': {
                    'match_all': {}
                }
            }
        }
    }
    es.conn.count.assert_called_with(index=es.index,
                                     doc_type=es.t.annotation,
                                     body=expected_query)
Пример #3
0
def test_users_index_looks_up_users_by_username(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"},
                           es=es)

    views.users_index(request)

    User.get_by_username.assert_called_with("bob")
Пример #4
0
def test_users_index_looks_up_users_by_email(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    views.users_index(pyramid_request)

    models.User.get_by_email.assert_called_with(pyramid_request.db, "*****@*****.**", "foo.org")
Пример #5
0
def test_users_index_strips_spaces(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "   foo.org    "}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    views.users_index(pyramid_request)

    models.User.get_by_username.assert_called_with(pyramid_request.db, "bob", "foo.org")
Пример #6
0
def test_users_index_strips_spaces(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "   foo.org    "}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    views.users_index(pyramid_request)

    models.User.get_by_username.assert_called_with(pyramid_request.db, "bob", "foo.org")
Пример #7
0
def test_users_index_looks_up_users_by_email(User, pyramid_request):
    pyramid_request.params = {"username": "******"}

    User.get_by_username.return_value = None

    views.users_index(pyramid_request)

    User.get_by_email.assert_called_with(pyramid_request.db, "*****@*****.**")
Пример #8
0
def test_users_index_looks_up_users_by_email(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    views.users_index(pyramid_request)

    models.User.get_by_email.assert_called_with(pyramid_request.db, "*****@*****.**", "foo.org")
Пример #9
0
def test_users_index_looks_up_users_by_email(User, pyramid_request):
    pyramid_request.params = {"username": "******"}
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    views.users_index(pyramid_request)

    User.get_by_email.assert_called_with(pyramid_request.db, "*****@*****.**")
Пример #10
0
def test_users_index_looks_up_users_by_email(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"}, es=es)

    User.get_by_username.return_value = None

    views.users_index(request)

    User.get_by_email.assert_called_with("*****@*****.**")
Пример #11
0
def test_users_index_looks_up_users_by_email(User):
    request = DummyRequest(db=mock.sentinel.db_session,
                           es=MagicMock(),
                           params={"username": "******"})

    User.get_by_username.return_value = None

    views.users_index(request)

    User.get_by_email.assert_called_with(mock.sentinel.db_session, "*****@*****.**")
Пример #12
0
def test_users_index_looks_up_users_by_email(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"},
                           es=es)

    User.get_by_username.return_value = None

    views.users_index(request)

    User.get_by_email.assert_called_with("*****@*****.**")
Пример #13
0
def test_users_index_queries_annotation_count_by_userid(models, factories, pyramid_request, annotation_stats_service):
    user = factories.User.build(username='******')
    models.User.get_by_username.return_value = user
    annotation_stats_service.user_annotation_counts.return_value = {'total': 8}

    pyramid_request.params = {"username": "******", "authority": user.authority}
    result = views.users_index(pyramid_request)
    assert result['user_meta']['annotations_count'] == 8
Пример #14
0
def test_users_index_no_user_found(User, pyramid_request):
    pyramid_request.params = {"username": "******"}
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    result = views.users_index(pyramid_request)

    assert result == {'username': "******", 'user': None, 'user_meta': {}}
Пример #15
0
def test_users_index_no_user_found(User, pyramid_request):
    pyramid_request.params = {"username": "******"}
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    result = views.users_index(pyramid_request)

    assert result == {'username': "******", 'user': None, 'user_meta': {}}
Пример #16
0
def test_users_index_no_user_found(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"}, es=es)
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    result = views.users_index(request)

    assert result == {'username': "******", 'user': None, 'user_meta': {}}
Пример #17
0
def test_users_index_no_user_found(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"},
                           es=es)
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    result = views.users_index(request)

    assert result == {'username': "******", 'user': None, 'user_meta': {}}
Пример #18
0
def test_users_index_queries_annotation_count_by_userid(User, db_session, factories, pyramid_request):
    User.get_by_username.return_value = factories.User(username='******')
    userid = "acct:bob@{}".format(pyramid_request.auth_domain)
    for _ in xrange(8):
        db_session.add(factories.Annotation(userid=userid))
    db_session.flush()

    pyramid_request.params = {"username": "******"}
    result = views.users_index(pyramid_request)
    assert result['user_meta']['annotations_count'] == 8
Пример #19
0
def test_users_index(pyramid_request):
    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': pyramid_request.auth_domain,
        'username': None,
        'authority': None,
        'user': None,
        'user_meta': {},
    }
Пример #20
0
def test_users_index(pyramid_request):
    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': pyramid_request.auth_domain,
        'username': None,
        'authority': None,
        'user': None,
        'user_meta': {},
    }
Пример #21
0
def test_users_index_queries_annotation_count_by_userid(User, pyramid_request):
    pyramid_request.params = {"username": "******"}
    es = pyramid_request.es

    User.get_by_username.return_value.username = '******'

    views.users_index(pyramid_request)

    expected_query = {
        'query': {
            'filtered': {
                'filter': {'term': {'user': u'acct:[email protected]'}},
                'query': {'match_all': {}}
            }
        }
    }
    es.conn.count.assert_called_with(index=es.index,
                                     doc_type=es.t.annotation,
                                     body=expected_query)
Пример #22
0
def test_users_index_no_user_found(User):
    request = DummyRequest(db=mock.sentinel.db_session,
                           es=MagicMock(),
                           params={"username": "******"})
    User.get_by_username.return_value = None
    User.get_by_email.return_value = None

    result = views.users_index(request)

    assert result == {'username': "******", 'user': None, 'user_meta': {}}
Пример #23
0
def test_users_index_user_found(User, pyramid_request, db_session, factories):
    pyramid_request.params = {"username": "******"}
    user = User.get_by_username.return_value = factories.User(username='******')

    result = views.users_index(pyramid_request)

    assert result == {
        'username': "******",
        'user': user,
        'user_meta': {'annotations_count': 0},
    }
Пример #24
0
def test_users_index_queries_annotation_count_by_userid(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"},
                           es=es)

    User.get_by_username.return_value.username = '******'

    views.users_index(request)

    expected_query = {
        'query': {
            'filtered': {
                'filter': {'term': {'user': u'acct:[email protected]'}},
                'query': {'match_all': {}}
            }
        }
    }
    es.conn.count.assert_called_with(index=es.index,
                                     doc_type=es.t.annotation,
                                     body=expected_query)
Пример #25
0
def test_users_index_queries_annotation_count_by_userid(
        User, db_session, factories, pyramid_request):
    User.get_by_username.return_value = factories.User(username='******')
    userid = "acct:bob@{}".format(pyramid_request.auth_domain)
    for _ in xrange(8):
        db_session.add(factories.Annotation(userid=userid))
    db_session.flush()

    pyramid_request.params = {"username": "******"}
    result = views.users_index(pyramid_request)
    assert result['user_meta']['annotations_count'] == 8
Пример #26
0
def test_users_index_user_found(User, pyramid_request):
    pyramid_request.params = {"username": "******"}
    pyramid_request.es.conn.count.return_value = {'count': 43}

    result = views.users_index(pyramid_request)

    assert result == {
        'username': "******",
        'user': User.get_by_username.return_value,
        'user_meta': {'annotations_count': 43},
    }
Пример #27
0
def test_users_index_user_found(User, pyramid_request, db_session, factories):
    pyramid_request.params = {"username": "******"}
    user = User.get_by_username.return_value = factories.User(username='******')

    result = views.users_index(pyramid_request)

    assert result == {
        'username': "******",
        'user': user,
        'user_meta': {
            'annotations_count': 0
        },
    }
Пример #28
0
def test_users_index_user_found(User):
    es = MagicMock()
    request = DummyRequest(params={"username": "******"},
                           es=es)
    es.conn.count.return_value = {'count': 43}

    result = views.users_index(request)

    assert result == {
        'username': "******",
        'user': User.get_by_username.return_value,
        'user_meta': {'annotations_count': 43},
    }
Пример #29
0
def test_users_index_no_user_found(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': "example.com",
        'username': "******",
        'authority': "foo.org",
        'user': None,
        'user_meta': {}
    }
Пример #30
0
def test_users_index_user_found(models, pyramid_request, db_session, factories):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    user = factories.User.build(username='******', authority='foo.org')
    models.User.get_by_username.return_value = user

    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': "example.com",
        'username': "******",
        'authority': "foo.org",
        'user': user,
        'user_meta': {'annotations_count': 0},
    }
Пример #31
0
def test_users_index_no_user_found(models, pyramid_request):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    models.User.get_by_username.return_value = None
    models.User.get_by_email.return_value = None

    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': "example.com",
        'username': "******",
        'authority': "foo.org",
        'user': None,
        'user_meta': {}
    }
Пример #32
0
def test_users_index_user_found(models, pyramid_request, db_session, factories):
    pyramid_request.params = {"username": "******", "authority": "foo.org"}
    user = models.User.get_by_username.return_value = factories.User(username='******',
                                                                     authority='foo.org')

    result = views.users_index(pyramid_request)

    assert result == {
        'default_authority': "example.com",
        'username': "******",
        'authority': "foo.org",
        'user': user,
        'user_meta': {'annotations_count': 0},
    }
Пример #33
0
def test_users_index():
    request = DummyRequest()

    result = views.users_index(request)

    assert result == {'username': None, 'user': None, 'user_meta': {}}
Пример #34
0
def test_users_index(pyramid_request):
    result = views.users_index(pyramid_request)

    assert result == {'username': None, 'user': None, 'user_meta': {}}
Пример #35
0
def test_users_index_looks_up_users_by_username(User, pyramid_request):
    pyramid_request.params = {"username": "******"}

    views.users_index(pyramid_request)

    User.get_by_username.assert_called_with(pyramid_request.db, "bob")
Пример #36
0
def test_users_index(pyramid_request):
    result = views.users_index(pyramid_request)

    assert result == {'username': None, 'user': None, 'user_meta': {}}