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")
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)
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")
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")
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, "*****@*****.**")
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, "*****@*****.**")
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("*****@*****.**")
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, "*****@*****.**")
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
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': {}}
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': {}}
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
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': {}, }
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)
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': {}}
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}, }
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)
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
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}, }
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 }, }
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}, }
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': {} }
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}, }
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}, }
def test_users_index(): request = DummyRequest() result = views.users_index(request) assert result == {'username': None, 'user': None, 'user_meta': {}}
def test_users_index(pyramid_request): result = views.users_index(pyramid_request) assert result == {'username': None, 'user': None, 'user_meta': {}}
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")