diff --git a/common/tests.py b/common/tests.py new file mode 100644 index 0000000..64e20f4 --- /dev/null +++ b/common/tests.py @@ -0,0 +1,63 @@ +from decimal import Decimal + +from django.test import SimpleTestCase + +from utils.assets import get_css +from utils.colors import gamma_correction, get_percieved_lightness, is_bright_color +from utils.markdown import md_to_html +from utils.money import format_money + + +class ColorsTests(SimpleTestCase): + def test_gamma_correction(self): + r, g, b = 10, 120, 255 + self.assertEqual(gamma_correction(r), 0.003035269835488375) + self.assertEqual(gamma_correction(g), 0.18782077230067787) + self.assertEqual(gamma_correction(b), 1) + + def test_percieved_lightness(self): + self.assertLess(get_percieved_lightness((10, 120, 255)), 53) + self.assertGreater(get_percieved_lightness((10, 120, 255)), 52) + + def test_is_bright_color(self): + self.assertFalse(is_bright_color("#123321")) + self.assertTrue(is_bright_color("#58b783")) + self.assertTrue(is_bright_color("#af6bce")) + + +class MarkdownTests(SimpleTestCase): + def test_basic_markdown(self): + self.assertHTMLEqual( + md_to_html("**test** *it*"), + "

test it

" + ) + + def test_nb_md(self): + self.assertHTMLEqual( + md_to_html("This\nis\nTest"), + "

This
is
Test

" + ) + + def test_bleach(self): + self.assertEqual( + md_to_html( + " Hi"), + "<script>console.log()</script>\n

Hi</button>

" + ) + + +class MoneyTests(SimpleTestCase): + def test_money_conversion(self): + self.assertEqual(format_money(Decimal("0.1")), "1 SP") + self.assertEqual(format_money(Decimal("0.001")), "") + self.assertEqual(format_money(Decimal("0.01")), "1 CP") + self.assertEqual(format_money(Decimal("1.1")), "1 GP 1 SP") + self.assertEqual(format_money(Decimal("100")), "100 GP") + self.assertEqual(format_money(Decimal("0")), "") + + +class ScssTests(SimpleTestCase): + def test_scss(self): + css, sourcemap = get_css(debug=True) + self.assertIn("body", css) + self.assertIn(".scss", sourcemap) diff --git a/loot/tests.py b/loot/tests.py index 7ce503c..e997377 100644 --- a/loot/tests.py +++ b/loot/tests.py @@ -1,3 +1,13 @@ -from django.test import TestCase - +from django_tenants.test.cases import TenantTestCase # Create your tests here. +from loot.models import Loot + + +class LootTests(TenantTestCase): + + @classmethod + def setUpTestData(cls): + cls.some_loot = Loot.objects.create(name="Torches", quantity=2, value_gold=0.2) + + def test_loot(self): + self.assertEqual(self.some_loot.value_per_unit, 0.1) diff --git a/poetry.lock b/poetry.lock index 5e44b19..9c71aab 100644 --- a/poetry.lock +++ b/poetry.lock @@ -134,6 +134,17 @@ python-versions = "*" [package.extras] cli = ["click"] +[[package]] +name = "coverage" +version = "5.5" +description = "Code coverage measurement for Python" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" + +[package.extras] +toml = ["toml"] + [[package]] name = "curtsies" version = "0.3.5" @@ -580,7 +591,7 @@ watchdog = ["watchdog"] [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "d72809478da8c00f4c8dd808869031cdb36b502884eb53513ed8086dacd9fab8" +content-hash = "d0408de1ace04f3d442a1f38be03af848c46f2848dec3ff086a59e522f521bbd" [metadata.files] argon2-cffi = [ @@ -680,6 +691,60 @@ confusable-homoglyphs = [ {file = "confusable_homoglyphs-3.2.0-py2.py3-none-any.whl", hash = "sha256:e3ce611028d882b74a5faa69e3cbb5bd4dcd9f69936da6e73d33eda42c917944"}, {file = "confusable_homoglyphs-3.2.0.tar.gz", hash = "sha256:3b4a0d9fa510669498820c91a0bfc0c327568cecec90648cf3819d4a6fc6a751"}, ] +coverage = [ + {file = "coverage-5.5-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:b6d534e4b2ab35c9f93f46229363e17f63c53ad01330df9f2d6bd1187e5eaacf"}, + {file = "coverage-5.5-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:b7895207b4c843c76a25ab8c1e866261bcfe27bfaa20c192de5190121770672b"}, + {file = "coverage-5.5-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:c2723d347ab06e7ddad1a58b2a821218239249a9e4365eaff6649d31180c1669"}, + {file = "coverage-5.5-cp27-cp27m-manylinux2010_i686.whl", hash = "sha256:900fbf7759501bc7807fd6638c947d7a831fc9fdf742dc10f02956ff7220fa90"}, + {file = "coverage-5.5-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:004d1880bed2d97151facef49f08e255a20ceb6f9432df75f4eef018fdd5a78c"}, + {file = "coverage-5.5-cp27-cp27m-win32.whl", hash = "sha256:06191eb60f8d8a5bc046f3799f8a07a2d7aefb9504b0209aff0b47298333302a"}, + {file = "coverage-5.5-cp27-cp27m-win_amd64.whl", hash = "sha256:7501140f755b725495941b43347ba8a2777407fc7f250d4f5a7d2a1050ba8e82"}, + {file = "coverage-5.5-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:372da284cfd642d8e08ef606917846fa2ee350f64994bebfbd3afb0040436905"}, + {file = "coverage-5.5-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:8963a499849a1fc54b35b1c9f162f4108017b2e6db2c46c1bed93a72262ed083"}, + {file = "coverage-5.5-cp27-cp27mu-manylinux2010_i686.whl", hash = "sha256:869a64f53488f40fa5b5b9dcb9e9b2962a66a87dab37790f3fcfb5144b996ef5"}, + {file = "coverage-5.5-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:4a7697d8cb0f27399b0e393c0b90f0f1e40c82023ea4d45d22bce7032a5d7b81"}, + {file = "coverage-5.5-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:8d0a0725ad7c1a0bcd8d1b437e191107d457e2ec1084b9f190630a4fb1af78e6"}, + {file = "coverage-5.5-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:51cb9476a3987c8967ebab3f0fe144819781fca264f57f89760037a2ea191cb0"}, + {file = "coverage-5.5-cp310-cp310-win_amd64.whl", hash = "sha256:c0891a6a97b09c1f3e073a890514d5012eb256845c451bd48f7968ef939bf4ae"}, + {file = "coverage-5.5-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:3487286bc29a5aa4b93a072e9592f22254291ce96a9fbc5251f566b6b7343cdb"}, + {file = "coverage-5.5-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:deee1077aae10d8fa88cb02c845cfba9b62c55e1183f52f6ae6a2df6a2187160"}, + {file = "coverage-5.5-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6"}, + {file = "coverage-5.5-cp35-cp35m-manylinux2010_i686.whl", hash = "sha256:6c90e11318f0d3c436a42409f2749ee1a115cd8b067d7f14c148f1ce5574d701"}, + {file = "coverage-5.5-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:30c77c1dc9f253283e34c27935fded5015f7d1abe83bc7821680ac444eaf7793"}, + {file = "coverage-5.5-cp35-cp35m-win32.whl", hash = "sha256:9a1ef3b66e38ef8618ce5fdc7bea3d9f45f3624e2a66295eea5e57966c85909e"}, + {file = "coverage-5.5-cp35-cp35m-win_amd64.whl", hash = "sha256:972c85d205b51e30e59525694670de6a8a89691186012535f9d7dbaa230e42c3"}, + {file = "coverage-5.5-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:af0e781009aaf59e25c5a678122391cb0f345ac0ec272c7961dc5455e1c40066"}, + {file = "coverage-5.5-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:74d881fc777ebb11c63736622b60cb9e4aee5cace591ce274fb69e582a12a61a"}, + {file = "coverage-5.5-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:92b017ce34b68a7d67bd6d117e6d443a9bf63a2ecf8567bb3d8c6c7bc5014465"}, + {file = "coverage-5.5-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:d636598c8305e1f90b439dbf4f66437de4a5e3c31fdf47ad29542478c8508bbb"}, + {file = "coverage-5.5-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:41179b8a845742d1eb60449bdb2992196e211341818565abded11cfa90efb821"}, + {file = "coverage-5.5-cp36-cp36m-win32.whl", hash = "sha256:040af6c32813fa3eae5305d53f18875bedd079960822ef8ec067a66dd8afcd45"}, + {file = "coverage-5.5-cp36-cp36m-win_amd64.whl", hash = "sha256:5fec2d43a2cc6965edc0bb9e83e1e4b557f76f843a77a2496cbe719583ce8184"}, + {file = "coverage-5.5-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:18ba8bbede96a2c3dde7b868de9dcbd55670690af0988713f0603f037848418a"}, + {file = "coverage-5.5-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:2910f4d36a6a9b4214bb7038d537f015346f413a975d57ca6b43bf23d6563b53"}, + {file = "coverage-5.5-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d"}, + {file = "coverage-5.5-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:796c9c3c79747146ebd278dbe1e5c5c05dd6b10cc3bcb8389dfdf844f3ead638"}, + {file = "coverage-5.5-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:53194af30d5bad77fcba80e23a1441c71abfb3e01192034f8246e0d8f99528f3"}, + {file = "coverage-5.5-cp37-cp37m-win32.whl", hash = "sha256:184a47bbe0aa6400ed2d41d8e9ed868b8205046518c52464fde713ea06e3a74a"}, + {file = "coverage-5.5-cp37-cp37m-win_amd64.whl", hash = "sha256:2949cad1c5208b8298d5686d5a85b66aae46d73eec2c3e08c817dd3513e5848a"}, + {file = "coverage-5.5-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:217658ec7187497e3f3ebd901afdca1af062b42cfe3e0dafea4cced3983739f6"}, + {file = "coverage-5.5-cp38-cp38-manylinux1_i686.whl", hash = "sha256:1aa846f56c3d49205c952d8318e76ccc2ae23303351d9270ab220004c580cfe2"}, + {file = "coverage-5.5-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:24d4a7de75446be83244eabbff746d66b9240ae020ced65d060815fac3423759"}, + {file = "coverage-5.5-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:d1f8bf7b90ba55699b3a5e44930e93ff0189aa27186e96071fac7dd0d06a1873"}, + {file = "coverage-5.5-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:970284a88b99673ccb2e4e334cfb38a10aab7cd44f7457564d11898a74b62d0a"}, + {file = "coverage-5.5-cp38-cp38-win32.whl", hash = "sha256:01d84219b5cdbfc8122223b39a954820929497a1cb1422824bb86b07b74594b6"}, + {file = "coverage-5.5-cp38-cp38-win_amd64.whl", hash = "sha256:2e0d881ad471768bf6e6c2bf905d183543f10098e3b3640fc029509530091502"}, + {file = "coverage-5.5-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d1f9ce122f83b2305592c11d64f181b87153fc2c2bbd3bb4a3dde8303cfb1a6b"}, + {file = "coverage-5.5-cp39-cp39-manylinux1_i686.whl", hash = "sha256:13c4ee887eca0f4c5a247b75398d4114c37882658300e153113dafb1d76de529"}, + {file = "coverage-5.5-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:52596d3d0e8bdf3af43db3e9ba8dcdaac724ba7b5ca3f6358529d56f7a166f8b"}, + {file = "coverage-5.5-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:2cafbbb3af0733db200c9b5f798d18953b1a304d3f86a938367de1567f4b5bff"}, + {file = "coverage-5.5-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:44d654437b8ddd9eee7d1eaee28b7219bec228520ff809af170488fd2fed3e2b"}, + {file = "coverage-5.5-cp39-cp39-win32.whl", hash = "sha256:d314ed732c25d29775e84a960c3c60808b682c08d86602ec2c3008e1202e3bb6"}, + {file = "coverage-5.5-cp39-cp39-win_amd64.whl", hash = "sha256:13034c4409db851670bc9acd836243aeee299949bd5673e11844befcb0149f03"}, + {file = "coverage-5.5-pp36-none-any.whl", hash = "sha256:f030f8873312a16414c0d8e1a1ddff2d3235655a2174e3648b4fa66b3f2f1079"}, + {file = "coverage-5.5-pp37-none-any.whl", hash = "sha256:2a3859cb82dcbda1cfd3e6f71c27081d18aa251d20a17d87d26d4cd216fb0af4"}, + {file = "coverage-5.5.tar.gz", hash = "sha256:ebe78fe9a0e874362175b02371bdfbee64d8edc42a044253ddf4ee7d3c15212c"}, +] curtsies = [ {file = "curtsies-0.3.5.tar.gz", hash = "sha256:a587ff3335667a32be7afed163f60a1c82c5d9c848d8297534a06fd29de20dbd"}, ] diff --git a/pyproject.toml b/pyproject.toml index 7731a8e..e7c8087 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ bpython = "^0.21" django-extensions = "^3.1.3" sentry-sdk = "^1.3.1" django-tree-queries = "^0.6.0" +coverage = "^5.5" [tool.poetry.dev-dependencies] Werkzeug = "^2.0.1" diff --git a/utils/colors.py b/utils/colors.py index 3373c34..345b9b3 100644 --- a/utils/colors.py +++ b/utils/colors.py @@ -300,6 +300,4 @@ def get_percieved_lightness(rgb: Tuple[int, ...]) -> float: def is_bright_color(bg_color: str) -> bool: bg_color = bg_color[1:] rgb = tuple(int(bg_color[i:i + 2], 16) for i in (0, 2, 4)) - print(rgb) - print(get_percieved_lightness(rgb)) return get_percieved_lightness(rgb) > 50 diff --git a/utils/mixin.py b/utils/mixin.py deleted file mode 100644 index e793db8..0000000 --- a/utils/mixin.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.contrib.auth.mixins import AccessMixin -from django.core.exceptions import PermissionDenied - -from users.models import TenantUser - - -class PartOfTenantRequiredMixin(AccessMixin): - """Verify that the current user is authenticated.""" - - permission_denied_message = "You are not part of this campaign" - - def dispatch(self, request, *args, **kwargs): - current_user: TenantUser = self.request.user - - if not current_user.tenants.filter(pk=self.request.tenant.pk).exists(): - return self.handle_no_permission() - return super().dispatch(request, *args, **kwargs) diff --git a/utils/money.py b/utils/money.py index cee0256..2eaa4ca 100644 --- a/utils/money.py +++ b/utils/money.py @@ -17,13 +17,11 @@ use_platinum = False def digitize(n): - print("n", n) digits = [] i = 0 if n == 0: return [0] while n: - print(digits) i += 1 if i > (3 if use_platinum else 2): digits.append(n)