Skip to content

Commit

Permalink
👌 [#28] add unittests for is_local function
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Apr 5, 2024
1 parent 4d4063f commit 11e73b0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_is_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Test django_loose_fk.utils.is_local function with various
combinations of settings
"""

from django.test import override_settings

from django_loose_fk.utils import is_local


@override_settings(
LOOSE_FK_LOCAL_BASE_URLS=["http://api.example.nl/ozgv-t/zaken"],
)
def test_with_setting_same_host_same_prefix():
assert (
is_local(host="api.example.nl", url="http://api.example.nl/ozgv-t/zaken/1")
is True
)


@override_settings(
LOOSE_FK_LOCAL_BASE_URLS=["http://api.example.nl/ozgv-t/zaken"],
)
def test_with_setting_same_host_diff_prefix():
assert (
is_local(host="api.example.nl", url="http://api.example.nl/ozgv-t/documenten/1")
is False
)


@override_settings(
LOOSE_FK_LOCAL_BASE_URLS=["http://otherapi.example.nl/ozgv-t/zaken"],
)
def test_with_setting_diff_host():
assert (
is_local(host="api.example.nl", url="http://otherapi.example.nl/ozgv-t/zaken/1")
is True
)


def test_no_setting_same_host_with_prefix():
assert (
is_local(host="api.example.nl", url="http://api.example.nl/ozgv-t/zaken/1")
is True
)


def test_no_setting_same_host_no_prefix():
assert is_local(host="api.example.nl", url="http://api.example.nl/zaken/1") is True


def test_no_setting_diff_host():
assert (
is_local(host="api.example.nl", url="http://otherapi.example.nl/ozgv-t/zaken/1")
is False
)

0 comments on commit 11e73b0

Please sign in to comment.