Skip to content

Commit 830ee61

Browse files
authored
Tests (#182)
* Create new fixtures and fix current_user deprecation warning * Adds tests for the app and handlers * Test stores * Configures file_id_manager in tests * clean up test workflow * pre-commit
1 parent b9182a9 commit 830ee61

File tree

8 files changed

+479
-88
lines changed

8 files changed

+479
-88
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,26 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v3
19+
1920
- name: Set up Python
2021
uses: actions/setup-python@v4
2122
with:
2223
python-version: '3.11'
24+
25+
- name: Base Setup
26+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
27+
2328
- name: Install dependencies
2429
run: |
25-
pip install jupyterlab
30+
pip install "jupyterlab>=4.0.0,<5"
2631
pip install -e .
2732
jlpm
33+
2834
- name: Run pre-commit
2935
uses: pre-commit/[email protected]
3036
with:
3137
extra_args: --all-files --hook-stage=manual
38+
3239
- name: Help message if pre-commit fail
3340
if: ${{ failure() }}
3441
run: |
@@ -39,6 +46,7 @@ jobs:
3946
echo " pre-commit run"
4047
echo "or after-the-fact on already committed files with"
4148
echo " pre-commit run --all-files --hook-stage=manual"
49+
4250
- name: Lint frontend
4351
run: |
4452
jlpm run lint:check
@@ -49,15 +57,21 @@ jobs:
4957
steps:
5058
- name: Checkout
5159
uses: actions/checkout@v3
60+
5261
- name: Set up Python
5362
uses: actions/setup-python@v4
5463
with:
5564
python-version: '3.11'
65+
66+
- name: Base Setup
67+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
68+
5669
- name: Install dependencies
5770
run: |
58-
pip install jupyterlab
71+
pip install "jupyterlab>=4.0.0,<5"
5972
pip install -e .
6073
jlpm
74+
6175
- name: Run Tests
6276
run: |
6377
set -eux
@@ -72,34 +86,47 @@ jobs:
7286
matrix:
7387
os: [ubuntu-latest, windows-latest, macos-latest]
7488
python-version: ["3.8", "3.11"]
75-
include:
76-
- os: ubuntu-latest
77-
python-version: "pypy-3.8"
89+
# PyPy is not supported because we use the file_id_manager. See:
90+
# https://github.com/jupyter-server/jupyter_server_fileid/issues/44
91+
#include:
92+
# - os: ubuntu-latest
93+
# python-version: "pypy-3.8"
7894
steps:
7995
- name: Checkout
8096
uses: actions/checkout@v3
97+
8198
- name: Base Setup
8299
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
100+
83101
- name: Install the Python dependencies
84102
run: |
103+
python -m pip install "jupyterlab>=4.0.0,<5"
85104
pip install -e ".[test]" codecov
86-
python -m pip install jupyterlab
105+
87106
- name: List installed packages
88107
run: |
89108
pip freeze
90109
pip check
110+
91111
- name: Run the tests with Coverage
92112
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
93113
run: |
94114
python -m pytest -vv --cov jupyter_collaboration --cov-branch --cov-report term-missing:skip-covered
95-
- name: Run the tests on pypy and Windows
96-
if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(runner.os, 'Windows') }}
97-
run: |
98-
python -W ignore::ImportWarning -m pytest -vv
99-
- name: Coverage
100-
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
115+
116+
#- name: Run the tests on pypy
117+
# if: ${{ startsWith(matrix.python-version, 'pypy') }}
118+
# run: |
119+
# PyPy is not supported because we use the file_id_manager. See:
120+
# https://github.com/jupyter-server/jupyter_server_fileid/issues/44
121+
# python -W ignore::ImportWarning -m pytest -vv
122+
123+
- name: Run the tests on Windows
124+
if: ${{ startsWith(runner.os, 'Windows') }}
101125
run: |
102-
codecov
126+
python -W ignore::ImportWarning -m pytest -vv --cov jupyter_collaboration --cov-branch --cov-report term-missing:skip-covered
127+
128+
- uses: jupyterlab/maintainer-tools/.github/actions/upload-coverage@v1
129+
103130
- name: Build the extension
104131
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
105132
shell: bash
@@ -118,12 +145,15 @@ jobs:
118145
runs-on: ubuntu-latest
119146
steps:
120147
- uses: actions/checkout@v3
148+
121149
- name: Base Setup
122150
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
123151
with:
124152
python_version: "3.11"
153+
125154
- name: Install minimum versions
126155
uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1
156+
127157
- name: Run the unit tests
128158
run: |
129159
pytest -vv -W default || pytest -vv -W default --lf
@@ -136,15 +166,19 @@ jobs:
136166
steps:
137167
- name: Checkout
138168
uses: actions/checkout@v3
169+
139170
- name: Base Setup
140171
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
172+
141173
- name: Install the Python dependencies
142174
run: |
143175
pip install --pre -e ".[test]"
176+
144177
- name: List installed packages
145178
run: |
146179
pip freeze
147180
pip check
181+
148182
- name: Run the tests
149183
run: |
150184
pytest -vv -W default || pytest -vv --lf
@@ -166,8 +200,10 @@ jobs:
166200
timeout-minutes: 15
167201
steps:
168202
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
203+
169204
- name: Download sdist
170205
uses: actions/download-artifact@v3
206+
171207
- name: Install From SDist
172208
shell: bash
173209
run: |
@@ -177,9 +213,10 @@ jobs:
177213
mkdir test
178214
tar --strip-components=1 -zxvf *.tar.gz -C ./test
179215
cd test
216+
python -m pip install "jupyterlab>=4.0.0,<5"
180217
python -m pip install ".[test]"
181-
python -m pip install jupyterlab
182218
echo "::endgroup::"
219+
183220
- name: Run Test
184221
shell: bash
185222
run: |

jupyter_collaboration/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def get(self, *args, **kwargs):
155155
"""
156156
Overrides default behavior to check whether the client is authenticated or not.
157157
"""
158-
if self.get_current_user() is None:
158+
if self.current_user is None:
159159
self.log.warning("Couldn't authenticate WebSocket connection")
160160
raise web.HTTPError(403)
161161
return await super().get(*args, **kwargs)
@@ -258,7 +258,7 @@ async def on_message(self, message):
258258
if message_type == MessageType.CHAT:
259259
msg = message[2:].decode("utf-8")
260260

261-
user = self.get_current_user()
261+
user = self.current_user
262262
data = json.dumps(
263263
{"sender": user.username, "timestamp": time.time(), "content": json.loads(msg)}
264264
).encode("utf8")

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ dev = [
4545
test = [
4646
"coverage",
4747
"jupyter_server[test]>=2.0.0",
48+
"jupyter_server_fileid[test]",
4849
"pytest>=7.0",
4950
"pytest-cov",
50-
"pytest-asyncio"
51+
"pytest-asyncio",
52+
"websockets"
5153
]
5254
docs = [
5355
"jupyterlab>=4.0.0",

0 commit comments

Comments
 (0)