Repository: jupyterhub/jupyterhub

Issue:
Tests are failing on main branch
I've run the tests on the main branch and conclude they are currently failing. See https://github.com/jupyterhub/jupyterhub/actions/runs/1609109514.

It seems that while #3722 was merged with succeeded tests, the PRs listed below had been merged in between #3722 was tested and #3722 was merged - and consistent test failures followed.

- #3720
- #3705
- #3708
- #3727

### Failure

```
________________________________ test_get_users ________________________________

app = <jupyterhub.tests.mocking.MockHub object at 0x7f9a3c845f60>

    @mark.user
    @mark.role
    async def test_get_users(app):
        db = app.db
    
        r = await api_request(app, 'users', headers=auth_header(db, 'admin'))
        assert r.status_code == 200
    
        users = sorted(r.json(), key=lambda d: d['name'])
        users = [normalize_user(u) for u in users]
        user_model = {
            'name': 'user',
            'admin': False,
            'roles': ['user'],
            'auth_state': None,
        }
>       assert users == [
            fill_user(
                {'name': 'admin', 'admin': True, 'roles': ['admin'], 'auth_state': None}
            ),
            fill_user(user_model),
        ]
E       AssertionError: assert [{'admin': Tr...ps': [], ...}] == [{'admin': Tr...ps': [], ...}]
E         At index 0 diff: {'server': None, 'admin': True, 'created': '0000-00-00T00:00:00Z', 'groups': [], 'auth_state': None, 'roles': ['admin', 'user'], 'last_activity': '0000-00-00T00:00:00Z', 'pending': None, 'kind': 'user', 'name': 'admin', 'servers': {}} != {'name': 'admin', 'admin': True, 'roles': ['admin'], 'auth_state': None, 'server': None, 'kind': 'user', 'groups': [], 'pending': None, 'created': '0000-00-00T00:00:00Z', 'last_activity': '0000-00-00T00:00:00Z', 'servers': {}}
E         Full diff:
E           [
E            {'admin': True,
E             'auth_state': None,
E             'created': '0000-00-00T00:00:00Z',
E             'groups': [],
E             'kind': 'user',
E             'last_activity': '0000-00-00T00:00:00Z',
E             'name': 'admin',
E             'pending': None,
E         -   'roles': ['admin'],
E         +   'roles': ['admin', 'user'],
E         ?                    ++++++++
E             'server': None,
E             'servers': {}},
E            {'admin': False,
E             'auth_state': None,
E             'created': '0000-00-00T00:00:00Z',
E             'groups': [],
E             'kind': 'user',
E             'last_activity': '0000-00-00T00:00:00Z',
E             'name': 'user',
E             'pending': None,
E             'roles': ['user'],
E             'server': None,
E             'servers': {}},
E           ]

jupyterhub/tests/test_api.py:241: AssertionError
```


Discussion:
Ping @manics btw who experienced a test failure in unrelated #3733.

Resolving patch:
diff --git a/jupyterhub/app.py b/jupyterhub/app.py
--- a/jupyterhub/app.py
+++ b/jupyterhub/app.py
@@ -1903,6 +1903,7 @@ async def init_users(self):
             user = orm.User.find(db, name)
             if user is None:
                 user = orm.User(name=name, admin=True)
+                roles.assign_default_roles(self.db, entity=user)
                 new_users.append(user)
                 db.add(user)
             else:


Test patch:
diff --git a/jupyterhub/tests/test_api.py b/jupyterhub/tests/test_api.py
--- a/jupyterhub/tests/test_api.py
+++ b/jupyterhub/tests/test_api.py
@@ -188,6 +188,8 @@ def normalize_user(user):
     """
     for key in ('created', 'last_activity'):
         user[key] = normalize_timestamp(user[key])
+    if 'roles' in user:
+        user['roles'] = sorted(user['roles'])
     if 'servers' in user:
         for server in user['servers'].values():
             for key in ('started', 'last_activity'):
@@ -240,7 +242,12 @@ async def test_get_users(app):
     }
     assert users == [
         fill_user(
-            {'name': 'admin', 'admin': True, 'roles': ['admin'], 'auth_state': None}
+            {
+                'name': 'admin',
+                'admin': True,
+                'roles': ['admin', 'user'],
+                'auth_state': None,
+            }
         ),
         fill_user(user_model),
     ]