mirror of
https://github.com/Findus23/RPGnotes.git
synced 2024-09-18 14:33:44 +02:00
fix tests
This commit is contained in:
parent
968187534e
commit
ddddf6775c
4 changed files with 66 additions and 3 deletions
|
@ -1,11 +1,36 @@
|
|||
from decimal import Decimal
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from django_tenants.test.cases import FastTenantTestCase
|
||||
|
||||
from loot.models import Loot
|
||||
from users.models import TenantUser
|
||||
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.markdown import md_to_html, autolink
|
||||
from utils.money import format_money
|
||||
from utils.urls import name2url
|
||||
|
||||
|
||||
class BaseTest(FastTenantTestCase):
|
||||
@classmethod
|
||||
def setup_tenant(cls, tenant):
|
||||
# Creates the tenant user needed to set up tenant.owner_id
|
||||
|
||||
tenant_user = TenantUser.objects.get_or_create(email="test@example.com")
|
||||
tenant.name = "public"
|
||||
tenant.email = "test2@example.com"
|
||||
|
||||
# For django-tenant-users
|
||||
|
||||
tenant.owner_id = 1
|
||||
tenant.tenants = [1]
|
||||
return tenant
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.setUpTestData()
|
||||
|
||||
|
||||
class ColorsTests(SimpleTestCase):
|
||||
|
@ -46,6 +71,30 @@ class MarkdownTests(SimpleTestCase):
|
|||
)
|
||||
|
||||
|
||||
class AutoLinkTests(BaseTest):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.some_loot = Loot.objects.create(name="Torches", quantity=2, value_gold=0.2)
|
||||
|
||||
def test_name2url(self):
|
||||
self.assertEqual(
|
||||
name2url(),
|
||||
{'Torches': ('/loot/1/edit', self.some_loot)}
|
||||
)
|
||||
|
||||
def test_autolink(self):
|
||||
self.assertEqual(
|
||||
autolink("these Torches"),
|
||||
("these [Torches](/loot/1/edit)", {"loo1"})
|
||||
)
|
||||
|
||||
def test_basic_markdown(self):
|
||||
self.assertHTMLEqual(
|
||||
md_to_html("most Torches we found")[0],
|
||||
'<p>most<a href="/loot/1/edit">Torches</a>we found</p>'
|
||||
)
|
||||
|
||||
|
||||
class MoneyTests(SimpleTestCase):
|
||||
def test_money_conversion(self):
|
||||
self.assertEqual(format_money(Decimal("0.1")), "1 SP")
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
from django_tenants.test.cases import TenantTestCase
|
||||
|
||||
from common.tests import BaseTest
|
||||
# Create your tests here.
|
||||
from loot.models import Loot
|
||||
|
||||
|
||||
class LootTests(TenantTestCase):
|
||||
class LootTests(BaseTest):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
|
|
@ -38,3 +38,11 @@ class TenantUser(UserProfile):
|
|||
@property
|
||||
def graphkey(self):
|
||||
return f"use{self.pk}"
|
||||
|
||||
@property
|
||||
def groups(self):
|
||||
return self.tenant_perms.groups
|
||||
|
||||
@property
|
||||
def user_permissions(self):
|
||||
return self.tenant_perms.user_permissions
|
||||
|
|
|
@ -12,7 +12,11 @@ def print_diff_call(str1: str, str2: str, title: str) -> None:
|
|||
tmp1.flush()
|
||||
tmp2.write(str2)
|
||||
tmp2.flush()
|
||||
subprocess.run(["git", "--no-pager", "diff", "--color-words=.", tmp1.name, tmp2.name])
|
||||
out = subprocess.run(
|
||||
["git", "--no-pager", "diff", "--color-words=.", tmp1.name, tmp2.name],
|
||||
capture_output=True
|
||||
)
|
||||
print(out.stdout.decode())
|
||||
|
||||
|
||||
def print_diff(str1: str, str2: str) -> None:
|
||||
|
|
Loading…
Reference in a new issue