Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9123390
D6372.id23210.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D6372.id23210.diff
View Options
diff --git a/requirements.txt b/requirements.txt
--- a/requirements.txt
+++ b/requirements.txt
@@ -22,4 +22,4 @@
requests
sentry-sdk
typing-extensions
-psycopg2
+psycopg2 == 2.8.6
diff --git a/swh/web/config.py b/swh/web/config.py
--- a/swh/web/config.py
+++ b/swh/web/config.py
@@ -90,7 +90,7 @@
"vault": ("dict", {"cls": "remote", "args": {"url": "http://127.0.0.1:5005/",}}),
"scheduler": ("dict", {"cls": "remote", "url": "http://127.0.0.1:5008/"}),
"development_db": ("string", os.path.join(SETTINGS_DIR, "db.sqlite3")),
- "test_db": ("string", os.path.join(SETTINGS_DIR, "testdb.sqlite3")),
+ "test_db": ("dict", {"name": "swh-web-test"}),
"production_db": ("dict", {"name": "swh-web"}),
"deposit": (
"dict",
diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py
--- a/swh/web/settings/tests.py
+++ b/swh/web/settings/tests.py
@@ -92,11 +92,10 @@
ALLOWED_HOSTS = ["*"]
-
DATABASES = {
"default": {
- "ENGINE": "django.db.backends.sqlite3",
- "NAME": swh_web_config["test_db"],
+ "ENGINE": "django.db.backends.postgresql",
+ "NAME": swh_web_config["test_db"]["name"],
}
}
diff --git a/swh/web/tests/auth/test_views.py b/swh/web/tests/auth/test_views.py
--- a/swh/web/tests/auth/test_views.py
+++ b/swh/web/tests/auth/test_views.py
@@ -118,7 +118,7 @@
# check token has been generated and saved encrypted to database
assert len(OIDCUserOfflineTokens.objects.all()) == nb_tokens + 1
- encrypted_token = OIDCUserOfflineTokens.objects.last().offline_token
+ encrypted_token = OIDCUserOfflineTokens.objects.last().offline_token.tobytes()
secret = get_config()["secret_key"].encode()
salt = request.user.sub.encode()
decrypted_token = decrypt_data(encrypted_token, secret, salt)
@@ -131,7 +131,7 @@
return decrypted_token
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_generate_bearer_token_authenticated_user_success(client, keycloak_oidc):
"""
Authenticated user should be able to generate a bearer token using OIDC
@@ -150,7 +150,7 @@
check_http_get_response(client, url, status_code=403)
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_list_bearer_tokens(client, keycloak_oidc):
"""
User with correct credentials should be allowed to list his tokens.
@@ -169,8 +169,8 @@
for oidc_token in OIDCUserOfflineTokens.objects.all():
assert (
- oidc_token.creation_date.isoformat()
- == tokens_data[oidc_token.id - 1]["creation_date"]
+ oidc_token.creation_date.isoformat()[:15]
+ == tokens_data[oidc_token.id - 2]["creation_date"][:15]
)
@@ -182,7 +182,7 @@
check_http_post_response(client, url, status_code=403)
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_get_bearer_token(client, keycloak_oidc):
"""
User with correct credentials should be allowed to display a token.
@@ -204,7 +204,7 @@
assert response.content == token
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_get_bearer_token_expired_token(client, keycloak_oidc):
"""
User with correct credentials should be allowed to display a token.
@@ -245,7 +245,7 @@
check_http_post_response(client, url, status_code=403)
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_revoke_bearer_tokens(client, keycloak_oidc):
"""
User with correct credentials should be allowed to revoke tokens.
@@ -279,7 +279,7 @@
assert resp["location"] == login_url
-@pytest.mark.django_db
+@pytest.mark.django_db(reset_sequences=True)
def test_oidc_profile_view(client, keycloak_oidc):
"""
Authenticated users should be able to request the profile page
diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py
--- a/swh/web/tests/conftest.py
+++ b/swh/web/tests/conftest.py
@@ -16,6 +16,7 @@
import pytest
from django.core.cache import cache
+from django.test.utils import setup_databases # type: ignore
from rest_framework.test import APIClient, APIRequestFactory
from swh.model.hashutil import ALGORITHMS, hash_to_bytes
@@ -495,3 +496,22 @@
yield swh_scheduler
config["scheduler"] = scheduler
get_scheduler_load_task_types.cache_clear()
+
+
+@pytest.fixture(scope="session")
+def django_db_setup(request, django_db_blocker, postgresql_proc):
+ from django.conf import settings
+
+ settings.DATABASES["default"].update(
+ {
+ ("ENGINE", "django.db.backends.postgresql"),
+ ("NAME", get_config()["test_db"]["name"]),
+ ("USER", postgresql_proc.user),
+ ("HOST", postgresql_proc.host),
+ ("PORT", postgresql_proc.port),
+ }
+ )
+ with django_db_blocker.unblock():
+ setup_databases(
+ verbosity=request.config.option.verbose, interactive=False, keepdb=False
+ )
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jun 20, 5:24 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218924
Attached To
D6372: Replace Sqlite with Postgres in unit tests
Event Timeline
Log In to Comment