Skip to content

Commit 8bde8d6

Browse files
committed
All existing tests now removed, skipped or passing
1 parent 1fa32cc commit 8bde8d6

File tree

7 files changed

+87
-86
lines changed

7 files changed

+87
-86
lines changed

flowauth/backend/flowauth/token_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def list_my_servers():
2525
Produces a list of json objects with "id" and "server_name" fields.
2626
"""
2727
servers = db.session.execute(
28-
db.select(Server).join(current_user.roles.server)
28+
db.select(Server).join(current_user.roles).join(Role.server)
2929
).all()
3030

3131
for group in current_user.groups:

flowauth/backend/tests/conftest.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
from freezegun import freeze_time
45
from time import sleep
56

67
from functools import partial
@@ -28,32 +29,33 @@
2829
"TestTwoFactorUser", TestUser._fields + ("otp_generator", "backup_codes")
2930
)
3031

31-
32-
@pytest.fixture
33-
def test_date(monkeypatch):
34-
35-
# Adapted from https://stackoverflow.com/questions/20503373/how-to-monkeypatch-pythons-datetime-datetime-now-with-py-test /
36-
TEST_DATE = datetime.datetime(year=2020, month=12, day=31)
37-
38-
class test_datetime(datetime.datetime):
39-
@classmethod
40-
def now(cls, *args, **kwargs):
41-
return TEST_DATE
42-
43-
@classmethod
44-
def utcnow(cls, *args, **kwargs):
45-
return cls.now()
46-
47-
monkeypatch.setattr(datetime, "datetime", test_datetime)
48-
return TEST_DATE
49-
50-
51-
def test_test_date_fixture(test_date):
52-
assert datetime.datetime.now() == test_date
32+
#
33+
# @pytest.fixture
34+
# def test_date(monkeypatch):
35+
#
36+
# # Adapted from https://stackoverflow.com/questions/20503373/how-to-monkeypatch-pythons-datetime-datetime-now-with-py-test /
37+
# TEST_DATE = datetime.datetime(year=2020, month=12, day=31)
38+
#
39+
# class test_datetime(datetime.datetime):
40+
# @classmethod
41+
# def now(cls, *args, **kwargs):
42+
# return TEST_DATE
43+
#
44+
# @classmethod
45+
# def utcnow(cls, *args, **kwargs):
46+
# return cls.now()
47+
#
48+
# monkeypatch.setattr(datetime, "datetime", test_datetime)
49+
# return TEST_DATE
50+
#
51+
#
52+
# def test_test_date_fixture(test_date):
53+
# assert datetime.datetime.now() == test_date
54+
#
5355

5456

5557
@pytest.fixture
56-
def app(tmpdir, test_date):
58+
def app(tmpdir):
5759
"""Per test app"""
5860
db_path = tmpdir / "db.db"
5961
print(f"DB path: {db_path}")
@@ -156,10 +158,11 @@ def test_two_factor_auth_user(app, get_two_factor_code):
156158
def test_admin(app):
157159
with app.app_context():
158160
user = User.query.filter(User.username == app.config["ADMIN_USER"]).first()
159-
return TestUser(user.id, user.username, app.config["ADMIN_PASSWORD"])
161+
return TestUser(user.id, user.username, app.config["ADMIN_PASSWORD"])
160162

161163

162164
@pytest.fixture # (scope="session")
165+
@freeze_time("2020-12-31")
163166
def test_servers(app):
164167
with app.app_context():
165168
# Add some servers
@@ -173,7 +176,7 @@ def test_servers(app):
173176
name="DUMMY_SERVER_B",
174177
longest_token_life_minutes=2880,
175178
latest_token_expiry=datetime.datetime.now().date()
176-
+ datetime.timedelta(days=700),
179+
+ datetime.timedelta(days=365),
177180
)
178181
db.session.add(dummy_server_a)
179182
db.session.add(dummy_server_b)
@@ -202,6 +205,7 @@ def test_scopes(app, test_servers):
202205

203206

204207
@pytest.fixture # (scope="session")
208+
@freeze_time("2020-12-31")
205209
def test_roles(app, test_scopes, test_servers):
206210
read_a, read_b, run, dummy_query = test_scopes
207211
server_a, server_b = test_servers
@@ -237,7 +241,7 @@ def test_user_with_roles(app, test_user, test_roles):
237241
test_user_orm.roles += [role_a, role_b]
238242
db.session.add(test_user_orm)
239243
db.session.commit()
240-
return uid, uname, upass
244+
return uid, uname, upass
241245

242246

243247
@pytest.fixture

flowauth/backend/tests/test_auth.py

+28-26
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
from flask import g, session
77

88

9-
def test_login(client, auth, test_user):
10-
"""Test that we can log in by posting a username and password as json"""
11-
# test that signin route doesn't accept a get
12-
assert client.get("/signin").status_code == 405
13-
uid, username, password = test_user
14-
# test that successful login redirects to the index page
15-
response, _ = auth.login(username, password)
16-
assert {
17-
"logged_in": True,
18-
"is_admin": False,
19-
"require_two_factor_setup": False,
20-
} == response.get_json()
21-
22-
# login request set the user_id in the session
23-
# check that the user is loaded from the session
24-
with client:
25-
client.get("/")
26-
assert session["identity.id"] == uid
27-
assert g.user.username == username
9+
def test_login(app, client, auth, test_user):
10+
with app.app_context():
11+
"""Test that we can log in by posting a username and password as json"""
12+
# test that signin route doesn't accept a get
13+
assert client.get("/signin").status_code == 405
14+
uid, username, password = test_user
15+
# test that successful login redirects to the index page
16+
response, _ = auth.login(username, password)
17+
assert {
18+
"logged_in": True,
19+
"is_admin": False,
20+
"require_two_factor_setup": False,
21+
} == response.get_json()
22+
23+
# login request set the user_id in the session
24+
# check that the user is loaded from the session
25+
with client:
26+
client.get("/")
27+
assert session["identity.id"] == uid
28+
assert g.user.username == username
2829

2930

3031
@pytest.mark.parametrize(
@@ -52,11 +53,12 @@ def test_is_logged_in(client):
5253
assert client.get("/is_signed_in").status_code == 401
5354

5455

55-
def test_logout(client, auth, test_user):
56-
"""Test that we can log out"""
57-
uid, username, password = test_user
58-
auth.login(username, password)
56+
def test_logout(app, client, auth, test_user):
57+
with app.app_context():
58+
"""Test that we can log out"""
59+
uid, username, password = test_user
60+
auth.login(username, password)
5961

60-
with client:
61-
auth.logout()
62-
assert "user_id" not in session
62+
with client:
63+
auth.logout()
64+
assert "user_id" not in session

flowauth/backend/tests/test_role_admin.py

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
import pytest
2+
from freezegun import freeze_time
23

34

4-
@pytest.mark.usefixtures("test_data_with_access_rights")
5-
@pytest.fixture
6-
def logged_in_session(client, auth, app):
7-
response, csrf_cookie = auth.login("TEST_ADMIN", "DUMMY_PASSWORD")
8-
9-
5+
@freeze_time("2020-12-31")
106
def test_list_roles(client, auth, app, test_roles, test_scopes):
11-
response, csrf_cookie = auth.login("TEST_ADMIN", "DUMMY_PASSWORD")
12-
response = client.get(
13-
"/admin/servers/1/roles", headers={"X-CSRF-Token": csrf_cookie}
14-
)
15-
assert response.status_code == 200
16-
assert [
17-
{
18-
"id": 1,
19-
"name": "runner",
20-
"scopes": ["run", "get_result", "dummy_query:admin_level_1"],
21-
"latest_token_expiry": "2021-12-31T00:00:00.000000Z",
22-
"longest_token_life_minutes": 2880,
23-
},
24-
{
25-
"id": 2,
26-
"name": "reader",
27-
"scopes": ["get_result"],
28-
"latest_token_expiry": "2021-12-31T00:00:00.000000Z",
29-
"longest_token_life_minutes": 2880,
30-
},
31-
] == response.get_json()
7+
with app.app_context():
8+
response, csrf_cookie = auth.login("TEST_ADMIN", "DUMMY_PASSWORD")
9+
response = client.get(
10+
"/admin/servers/1/roles", headers={"X-CSRF-Token": csrf_cookie}
11+
)
12+
assert response.status_code == 200
13+
assert [
14+
{
15+
"id": 1,
16+
"name": "runner",
17+
"scopes": ["run", "get_result", "dummy_query:admin_level_1"],
18+
"latest_token_expiry": "2021-12-31T00:00:00.000000Z",
19+
"longest_token_life_minutes": 2880,
20+
},
21+
{
22+
"id": 2,
23+
"name": "reader",
24+
"scopes": ["get_result"],
25+
"latest_token_expiry": "2021-12-31T00:00:00.000000Z",
26+
"longest_token_life_minutes": 2880,
27+
},
28+
] == response.get_json()
3229

3330

3431
def test_add_role(client, auth, app, test_scopes):

flowauth/backend/tests/test_server_admin.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# file, You can obtain one at http.//mozilla.org/MPL/2.0/.
44
import datetime
55

6+
from freezegun import freeze_time
67
from werkzeug.http import http_date
78

89
import pytest
@@ -33,6 +34,7 @@ def test_get_server(client, auth, app):
3334
assert {"id": 1, "name": "DUMMY_SERVER_A"} == response.get_json()
3435

3536

37+
@freeze_time("2020-12-31")
3638
@pytest.mark.usefixtures("test_data_with_access_rights")
3739
def test_get_server_time_limits(client, auth, app):
3840

flowauth/backend/tests/test_user_views.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
import datetime
6-
75
import pytest
8-
from pytest import approx
9-
from werkzeug.http import http_date
106

117

8+
@pytest.mark.skip(reason="Users do not have direct access to servers anymore")
129
@pytest.mark.usefixtures("test_data")
1310
def test_server_access(client, auth, test_user):
1411
uid, uname, upass = test_user

flowauth/backend/tests/test_version_route.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import flowauth
66

77

8-
def test_version(client):
8+
def test_version(client, app):
99
"""Test the correct version is returned."""
10-
1110
response = client.get("/version")
1211
assert response.status_code == 200 # Should get an OK
1312

0 commit comments

Comments
 (0)