Skip to content

Commit

Permalink
feat: refactored tests (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Oct 5, 2024
1 parent 866b91b commit 8c53e8b
Show file tree
Hide file tree
Showing 8 changed files with 813 additions and 769 deletions.
729 changes: 383 additions & 346 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ python = ">=3.8"
django = ">=3.2"

[tool.poetry.group.test.dependencies]
pytest = "^7.3.1"
pytest-django = "^4.5.2"
tox = "^4.5.2"
pytest = "^8.3"
pytest-django = "^4.9"
tox = "^4.21"


[tool.poetry.group.dev.dependencies]
python-semantic-release = "^8.7.0"
python-semantic-release = "^8.7"

[tool.ruff]
fix = true
Expand Down
160 changes: 80 additions & 80 deletions tests/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
from django.contrib.auth.models import AnonymousUser
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings

from unfold.settings import CONFIG_DEFAULTS
from unfold.sites import UnfoldAdminSite


class ColorsTestCase(TestCase):
@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"COLORS": {
"primary": {
50: "#f0f9ff",
100: "#e0f2fe",
200: "#bae6fd",
300: "#7dd3fc",
400: "#38bdf8",
500: "#0ea5e9",
600: "#0284c7",
700: "#0369a1",
800: "#075985",
900: "#0c4a6e",
950: "#082f49",
}
},
@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"COLORS": {
"primary": {
50: "#f0f9ff",
100: "#e0f2fe",
200: "#bae6fd",
300: "#7dd3fc",
400: "#38bdf8",
500: "#0ea5e9",
600: "#0284c7",
700: "#0369a1",
800: "#075985",
900: "#0c4a6e",
950: "#082f49",
}
},
}
)
def test_colors_hex_to_rgb(self):
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
self.assertTrue("colors" in context)
self.assertTrue("primary" in context["colors"])
},
}
)
def test_colors_hex_to_rgb():
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)

self.assertEqual(context["colors"]["primary"][50], "240 249 255")
self.assertEqual(context["colors"]["primary"][100], "224 242 254")
self.assertEqual(context["colors"]["primary"][200], "186 230 253")
self.assertEqual(context["colors"]["primary"][300], "125 211 252")
self.assertEqual(context["colors"]["primary"][400], "56 189 248")
self.assertEqual(context["colors"]["primary"][500], "14 165 233")
self.assertEqual(context["colors"]["primary"][600], "2 132 199")
self.assertEqual(context["colors"]["primary"][700], "3 105 161")
self.assertEqual(context["colors"]["primary"][800], "7 89 133")
self.assertEqual(context["colors"]["primary"][900], "12 74 110")
self.assertEqual(context["colors"]["primary"][950], "8 47 73")
assert "colors" in context
assert "primary" in context["colors"]

@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"COLORS": {
"primary": {
50: "240 249 255",
100: "224 242 254",
200: "186 230 253",
300: "125 211 252",
400: "56 189 248",
500: "14 165 233",
600: "2 132 199",
700: "3 105 161",
800: "7 89 133",
900: "12 74 110",
950: "8 47 73",
}
},
assert context["colors"]["primary"][50] == "240 249 255"
assert context["colors"]["primary"][100] == "224 242 254"
assert context["colors"]["primary"][200] == "186 230 253"
assert context["colors"]["primary"][300] == "125 211 252"
assert context["colors"]["primary"][400] == "56 189 248"
assert context["colors"]["primary"][500] == "14 165 233"
assert context["colors"]["primary"][600] == "2 132 199"
assert context["colors"]["primary"][700] == "3 105 161"
assert context["colors"]["primary"][800] == "7 89 133"
assert context["colors"]["primary"][900] == "12 74 110"
assert context["colors"]["primary"][950] == "8 47 73"


@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"COLORS": {
"primary": {
50: "240 249 255",
100: "224 242 254",
200: "186 230 253",
300: "125 211 252",
400: "56 189 248",
500: "14 165 233",
600: "2 132 199",
700: "3 105 161",
800: "7 89 133",
900: "12 74 110",
950: "8 47 73",
}
},
}
)
def test_colors_rgb(self):
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
self.assertTrue("colors" in context)
self.assertTrue("primary" in context["colors"])
},
}
)
def test_colors_rgb():
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
assert "colors" in context
assert "primary" in context["colors"]

self.assertEqual(context["colors"]["primary"][50], "240 249 255")
self.assertEqual(context["colors"]["primary"][100], "224 242 254")
self.assertEqual(context["colors"]["primary"][200], "186 230 253")
self.assertEqual(context["colors"]["primary"][300], "125 211 252")
self.assertEqual(context["colors"]["primary"][400], "56 189 248")
self.assertEqual(context["colors"]["primary"][500], "14 165 233")
self.assertEqual(context["colors"]["primary"][600], "2 132 199")
self.assertEqual(context["colors"]["primary"][700], "3 105 161")
self.assertEqual(context["colors"]["primary"][800], "7 89 133")
self.assertEqual(context["colors"]["primary"][900], "12 74 110")
self.assertEqual(context["colors"]["primary"][950], "8 47 73")
assert context["colors"]["primary"][50] == "240 249 255"
assert context["colors"]["primary"][100] == "224 242 254"
assert context["colors"]["primary"][200] == "186 230 253"
assert context["colors"]["primary"][300] == "125 211 252"
assert context["colors"]["primary"][400] == "56 189 248"
assert context["colors"]["primary"][500] == "14 165 233"
assert context["colors"]["primary"][600] == "2 132 199"
assert context["colors"]["primary"][700] == "3 105 161"
assert context["colors"]["primary"][800] == "7 89 133"
assert context["colors"]["primary"][900] == "12 74 110"
assert context["colors"]["primary"][950] == "8 47 73"
80 changes: 40 additions & 40 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth.models import AnonymousUser
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings

Expand All @@ -11,42 +10,43 @@ def environment_callback(request):
return ["Testing Environment", "warning"]


class EnvironmentTestCase(TestCase):
@override_settings(UNFOLD={**CONFIG_DEFAULTS})
def test_empty_environment_callback(self):
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
self.assertTrue("environment" not in context)

@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"ENVIRONMENT": "tests.test_environment.non_existing_environment_callback",
},
}
)
def test_incorrect_environment_callback(self):
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
self.assertTrue("environment" not in context)

@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"ENVIRONMENT": "tests.test_environment.environment_callback",
},
}
)
def test_correct_environment_callback(self):
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
self.assertTrue("environment" in context)
self.assertEqual(context["environment"], ["Testing Environment", "warning"])
@override_settings(UNFOLD={**CONFIG_DEFAULTS})
def test_environment_empty_environment_callback():
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
assert "environment" not in context


@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"ENVIRONMENT": "tests.test_environment.non_existing_environment_callback",
},
}
)
def test_environment_incorrect_environment_callback():
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
assert "environment" not in context


@override_settings(
UNFOLD={
**CONFIG_DEFAULTS,
**{
"ENVIRONMENT": "tests.test_environment.environment_callback",
},
}
)
def test_environment_correct_environment_callback():
admin_site = UnfoldAdminSite()
request = RequestFactory().get("/rand")
request.user = AnonymousUser()
context = admin_site.each_context(request)
assert "environment" in context
assert context["environment"] == ["Testing Environment", "warning"]
Loading

0 comments on commit 8c53e8b

Please sign in to comment.