Skip to content
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
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ jobs:

- name: "Run tests"
run: |
cd src
coverage run --rcfile ../pyproject.toml manage.py test . --noinput --parallel=4
coverage xml --rcfile ../pyproject.toml
coverage run --rcfile ./pyproject.toml -m pytest -n auto
coverage xml --rcfile ./pyproject.toml
env:
POSTGRES_HOST: "localhost"
POSTGRES_PORT: 5432
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dev = [

test = [
"bornhack-website[bootstrap]",
"pytest==9.0.2",
"pytest-xdist==3.8.0",
"pytest-django==4.11.1",
"beautifulsoup4==4.14.3",
"coverage==7.13.0",
"hypothesis==6.150.3",
Expand Down Expand Up @@ -113,7 +116,6 @@ ignore = [
"ARG002", # Unused method argument
"EM101", # Exception must not use a string literal, assign to variable first
"EM102", # Exception must not use a f-string literal, assign to variable first
"PT", # We use django tests, not pytest
]

[tool.ruff.lint.per-file-ignores]
Expand Down Expand Up @@ -181,3 +183,5 @@ exclude_also = [
############ PYTEST ############
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "bornhack.settings"
python_files = "tests.py test_*.py"
pythonpath = ". src"
5 changes: 4 additions & 1 deletion src/bornhack/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,14 @@
"tasker": "Team Tasker - task management",
}

FIXTURE_DIRS = ["testdata"]
FIXTURE_DIR = BASE_DIR / "testdata"

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "tile-cache",
},
}

# Use pytest as test runner for integrating with `./manage.py test`
TEST_RUNNER = "pytest_django.runner.TestRunner"
39 changes: 20 additions & 19 deletions src/economy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.utils import timezone
from django.conf import settings

from .models import Bank
from .models import BankAccount
Expand All @@ -30,13 +31,13 @@ def test_bank_account_csv_import(self):
)

# make sure we create 6 transactions
with open("testdata/bank.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "bank.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
created = account.import_csv(reader)
self.assertEqual(created, 6)

# make sure we create 0 if we load the same file again
with open("testdata/bank.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "bank.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
created = account.import_csv(reader)
self.assertEqual(created, 0)
Expand All @@ -49,7 +50,7 @@ def test_bank_account_csv_import(self):
ValidationError,
msg="Transaction on 2021-09-01 is before the bank accounts start_date. Transaction text is 'c051c94d-0762-422b-a453-e14402' and amount is -250.00",
):
with open("testdata/bank.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "bank.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
created = account.import_csv(reader)

Expand All @@ -58,7 +59,7 @@ class CoinifyCSVImportTest(TestCase):
def test_coinify_invoice_csv_import(self):
# make sure we create 4 invoices
with open(
"testdata/coinify-invoices-20200101-20200630.csv",
settings.FIXTURE_DIR / "coinify-invoices-20200101-20200630.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -67,7 +68,7 @@ def test_coinify_invoice_csv_import(self):

# make sure we create 0 invoices if the same csv is imported again
with open(
"testdata/coinify-invoices-20200101-20200630.csv",
settings.FIXTURE_DIR / "coinify-invoices-20200101-20200630.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -77,7 +78,7 @@ def test_coinify_invoice_csv_import(self):
def test_coinify_payout_csv_import(self):
# make sure we create 2 payouts
with open(
"testdata/coinify-payouts-20210701-20210904.csv",
settings.FIXTURE_DIR / "coinify-payouts-20210701-20210904.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -86,7 +87,7 @@ def test_coinify_payout_csv_import(self):

# make sure we create 0 payouts if the same csv is imported again
with open(
"testdata/coinify-payouts-20210701-20210904.csv",
settings.FIXTURE_DIR / "coinify-payouts-20210701-20210904.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -96,7 +97,7 @@ def test_coinify_payout_csv_import(self):
def test_coinify_balance_csv_import(self):
# make sure we create 66 balances
with open(
"testdata/coinify-account-balances-20210701-20210904.csv",
settings.FIXTURE_DIR / "coinify-account-balances-20210701-20210904.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -105,7 +106,7 @@ def test_coinify_balance_csv_import(self):

# make sure we create 0 balances if the same csv is imported again
with open(
"testdata/coinify-account-balances-20210701-20210904.csv",
settings.FIXTURE_DIR / "coinify-account-balances-20210701-20210904.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
Expand All @@ -116,13 +117,13 @@ def test_coinify_balance_csv_import(self):
class EpayCSVImportTest(TestCase):
def test_epay_csv_import(self):
# make sure we create 4 epay transactions
with open("testdata/epay_test.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "epay_test.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
created = import_epay_csv(reader)
self.assertEqual(created, 3)

# make sure we create 0 if the same csv is imported again
with open("testdata/epay_test.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "epay_test.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
created = import_epay_csv(reader)
self.assertEqual(created, 0)
Expand All @@ -131,21 +132,21 @@ def test_epay_csv_import(self):
class ClearhausCSVImportTest(TestCase):
def test_clearhaus_csv_import(self):
# make sure we create 10 clearhaus settlements
with open("testdata/clearhaus_settlements.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "clearhaus_settlements.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
created = import_clearhaus_csv(reader)
self.assertEqual(created, 9)

# make sure we create 0 if the same csv is imported again
with open("testdata/clearhaus_settlements.csv", encoding="utf-8-sig") as f:
with open(settings.FIXTURE_DIR / "clearhaus_settlements.csv", encoding="utf-8-sig") as f:
reader = csv.reader(f, delimiter=",", quotechar='"')
created = import_clearhaus_csv(reader)
self.assertEqual(created, 0)


class ZettleImportTest(TestCase):
def test_zettle_receipts_import(self):
with open("testdata/Zettle-Receipts-Report-20210101-20210910.xlsx", "rb") as f:
with open(settings.FIXTURE_DIR / "Zettle-Receipts-Report-20210101-20210910.xlsx", "rb") as f:
df = ZettleExcelImporter.load_zettle_receipts_excel(f)
created = ZettleExcelImporter.import_zettle_receipts_df(df)
self.assertEqual(created, 6)
Expand All @@ -154,7 +155,7 @@ def test_zettle_receipts_import(self):
self.assertEqual(created, 0)

def test_zettle_balances_import(self):
with open("testdata/Zettle-Account-Statement-Report-20230901-20250903.xlsx", "rb") as f:
with open(settings.FIXTURE_DIR / "Zettle-Account-Statement-Report-20230901-20250903.xlsx", "rb") as f:
df = ZettleExcelImporter.load_zettle_balances_excel(f)
created = ZettleExcelImporter.import_zettle_balances_df(df)
self.assertEqual(created, 4059)
Expand All @@ -166,7 +167,7 @@ def test_zettle_balances_import(self):
class MobilePayImportTest(TestCase):
def test_mobilepay_import(self):
with open(
"testdata/MobilePay_Transfer_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
settings.FIXTURE_DIR / "MobilePay_Transfer_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
Expand All @@ -175,7 +176,7 @@ def test_mobilepay_import(self):

# make sure we create 0 if the same csv is imported again
with open(
"testdata/MobilePay_Transfer_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
settings.FIXTURE_DIR / "MobilePay_Transfer_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
Expand All @@ -184,7 +185,7 @@ def test_mobilepay_import(self):

# now test importing sales CSV, 3 out of 4 lines are already in from above import
with open(
"testdata/MobilePay_Sales_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
settings.FIXTURE_DIR / "MobilePay_Sales_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
Expand All @@ -197,7 +198,7 @@ def test_mobilepay_import(self):
)
# make sure we create 0 if the same csv is imported again
with open(
"testdata/MobilePay_Sales_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
settings.FIXTURE_DIR / "MobilePay_Sales_overview_csv_MyShop_25-08-2021_14-09-2021.csv",
encoding="utf-8-sig",
) as f:
reader = csv.reader(f, delimiter=";", quotechar='"')
Expand Down
15 changes: 9 additions & 6 deletions src/maps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def setUp(self):

self.allowed_endpoints = [
"/GeoDanmarkOrto/orto_foraar_wmts/1.0.0/WMTS",
"/GeoDanmarkOrto/orto_foraar/1.0.0/WMS",
"/Dkskaermkort/topo_skaermkort/1.0.0/wms",
"/DHMNedboer/dhm/1.0.0/wms",
]
Expand All @@ -53,12 +54,14 @@ def test_all_allowed_endpoints(self):
"""Test allowed endpoints."""
for endpoint in self.allowed_endpoints:
fix_request = self.rf.get("/maps/kfproxy" + endpoint)
with self.subTest(request=fix_request):
with mock.patch("maps.views.requests") as mock_req:
mock_req.get.return_value.status_code = 200
result = MapProxyView.as_view()(fix_request)

self.assertEqual(result.status_code, 200)
# Bug: pytest with pytest-xdist can't serialize objects, fixed in pytest v9.1
# https://github.com/pytest-dev/pytest-xdist/issues/1273#issuecomment-3677708056
# with self.subTest(request=fix_request):
with mock.patch("maps.views.requests") as mock_req:
mock_req.get.return_value.status_code = 200
result = MapProxyView.as_view()(fix_request)

self.assertEqual(result.status_code, 200)

def test_sanitizing_path(self):
"""Test sanitization of paths."""
Expand Down
Loading