Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Add tests to fix coverage #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Keep in sync with setup.cfg in the root of the project
ignore:
- "src/manage.py"
- "src/objecttypes/wsgi.py"
- "src/objecttypes/conf/local_example.py"
- "**/tests/*"
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ exclude = migrations,static,media
branch = True
source = src
omit =
*/test_*.py
# files processed at entrypoint time
src/manage.py
src/objecttypes/wsgi.py
src/openforms/conf/local_example.py
# generic test patterns
*/tests/*
31 changes: 31 additions & 0 deletions src/objecttypes/token/tests/test_generate_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from io import StringIO

from django.core.management import call_command
from django.test import TestCase

from objecttypes.token.models import TokenAuth


class GenerateTokenCommandTests(TestCase):
def test_generate_token(self):
out = StringIO()

call_command(
"generate_token",
"john doe",
"john@example.com",
organization="ACME",
application="Foo",
administration="Bar",
stdout=out,
)

token = TokenAuth.objects.get()

self.assertIsNotNone(token.token)
self.assertEqual(token.contact_person, "john doe")
self.assertEqual(token.email, "john@example.com")
self.assertEqual(token.organization, "ACME")
self.assertEqual(token.application, "Foo")
self.assertEqual(token.administration, "Bar")
self.assertEqual(out.getvalue(), f"Token {token.token} was generated\n")
62 changes: 62 additions & 0 deletions src/objecttypes/token/tests/test_migrations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from django.core.management import call_command
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
Expand Down Expand Up @@ -50,6 +52,66 @@ def tearDownClass(cls) -> None:
call_command("migrate", verbosity=0, database=connection._alias)


class SwitchToNewTokenAuthModelTestCase(BaseMigrationTest):
app = "token"
migrate_from = "0005_tokenauth"
migrate_to = "0006_copy_token_auth"

def test_migrate_to_new_model(self):
OldTokenAuth = self.old_app_state.get_model("token", "OldTokenAuth")

token = OldTokenAuth.objects.create(
token="foo",
contact_person="john doe",
email="john@example.com",
organization="ACME",
last_modified=datetime(2024, 1, 1),
created=datetime(2024, 1, 1),
application="Foo",
administration="Bar",
)

self.assertEqual(token.pk, "foo")

self._perform_migration()

TokenAuth = self.apps.get_model("token", "TokenAuth")
token = TokenAuth.objects.get()

self.assertTrue(isinstance(token.pk, int))
self.assertEqual(token.token, "foo")


class SwitchToOldTokenAuthModelTestCase(BaseMigrationTest):
app = "token"
migrate_from = "0006_copy_token_auth"
migrate_to = "0005_tokenauth"

def test_migrate_to_old_model(self):
TokenAuth = self.old_app_state.get_model("token", "TokenAuth")

token = TokenAuth.objects.create(
token="foo",
contact_person="john doe",
email="john@example.com",
organization="ACME",
last_modified=datetime(2024, 1, 1),
created=datetime(2024, 1, 1),
application="Foo",
administration="Bar",
)

self.assertTrue(isinstance(token.pk, int))

self._perform_migration()

OldTokenAuth = self.apps.get_model("token", "OldTokenAuth")
token = OldTokenAuth.objects.get()

self.assertEqual(token.pk, "foo")
self.assertEqual(token.token, "foo")


class TestTokenAuthUniqueness(BaseMigrationTest):
app = "token"
migrate_from = "0008_alter_tokenauth_token"
Expand Down
29 changes: 0 additions & 29 deletions src/objecttypes/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +0,0 @@
from django.conf import settings
from django.http import HttpRequest

from furl import furl


def get_domain() -> str:
"""
Obtain the domain/netloc according to settings or configuration.
"""
from django.contrib.sites.models import Site

if settings.OBJECTTYPES_DOMAIN:
return settings.OBJECTTYPES_DOMAIN

return Site.objects.get_current().domain


def build_absolute_url(path: str, request: HttpRequest | None = None) -> str:
if request is not None:
return request.build_absolute_uri(path)

domain = get_domain()
_furl = furl(
scheme="https" if settings.IS_HTTPS else "http",
netloc=domain,
path=path,
)
return _furl.url
Empty file.
64 changes: 0 additions & 64 deletions src/objecttypes/utils/templatetags/utils.py

This file was deleted.