diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index be3240870..04d9d663f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -74,7 +74,7 @@ jobs: uses: ./.github/setup_python - name: Run MyPy - run: mypy -p evap + run: mypy linter: runs-on: ubuntu-22.04 @@ -89,7 +89,7 @@ jobs: uses: ./.github/setup_python - name: Run linter - run: pylint evap -j 0 + run: pylint evap tools formatter: diff --git a/evap/evaluation/management/commands/lint.py b/evap/evaluation/management/commands/lint.py index b7c4427ab..767637d61 100644 --- a/evap/evaluation/management/commands/lint.py +++ b/evap/evaluation/management/commands/lint.py @@ -9,4 +9,4 @@ class Command(BaseCommand): requires_migrations_checks = False def handle(self, *args, **options): - subprocess.run(["pylint", "evap"], check=False) # nosec + subprocess.run(["pylint", "evap", "tools"], check=False) # nosec diff --git a/evap/evaluation/management/commands/typecheck.py b/evap/evaluation/management/commands/typecheck.py index 080ad6b45..45a7670f1 100644 --- a/evap/evaluation/management/commands/typecheck.py +++ b/evap/evaluation/management/commands/typecheck.py @@ -9,4 +9,4 @@ class Command(BaseCommand): requires_migrations_checks = False def handle(self, *args, **options): - subprocess.run(["mypy", "-p", "evap"], check=True) # nosec + subprocess.run(["mypy"], check=True) # nosec diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index 1208b7005..85202a857 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -370,7 +370,7 @@ class TestLintCommand(TestCase): @patch("subprocess.run") def test_pylint_called(mock_subprocess_run): management.call_command("lint") - mock_subprocess_run.assert_called_once_with(["pylint", "evap"], check=False) + mock_subprocess_run.assert_called_once_with(["pylint", "evap", "tools"], check=False) class TestFormatCommand(TestCase): @@ -392,7 +392,7 @@ class TestTypecheckCommand(TestCase): def test_mypy_called(self, mock_subprocess_run): management.call_command("typecheck") self.assertEqual(len(mock_subprocess_run.mock_calls), 1) - mock_subprocess_run.assert_has_calls([call(["mypy", "-p", "evap"], check=True)]) + mock_subprocess_run.assert_has_calls([call(["mypy"], check=True)]) class TestPrecommitCommand(TestCase): diff --git a/evap/staff/fixtures/excel_files_test_data.py b/evap/staff/fixtures/excel_files_test_data.py index 64fbd90fc..71f33f9c1 100644 --- a/evap/staff/fixtures/excel_files_test_data.py +++ b/evap/staff/fixtures/excel_files_test_data.py @@ -1,4 +1,6 @@ +import csv import io +from typing import TextIO import openpyxl @@ -198,6 +200,14 @@ ] } +# user.title, user.last_name, user.first_name, user.email +valid_user_courses_import_users = [ + ['', 'Quid', 'Bastius', 'bastius.quid@external.example.com'], + ['', 'Sed', 'Diam', '345@external.institution.com'], + ['', 'Manilium', 'Lucilia', 'lucilia.manilium@student.institution.com'], + ['Prof. Dr.', 'Prorsus', 'Christoph', '123@external.com'] +] + random_file_content = b"Hallo Welt\n" @@ -221,3 +231,11 @@ def create_memory_excel_file(data): sheet.cell(row=row_num, column=column_num).value = cell_data workbook.save(memory_excel_file) return memory_excel_file.getvalue() + + +def create_memory_csv_file(data) -> TextIO: + memory_csv_file = io.StringIO() + writer = csv.writer(memory_csv_file, delimiter=";", lineterminator="\n") + writer.writerows(data) + memory_csv_file.seek(0) + return memory_csv_file diff --git a/evap/staff/templates/staff_index.html b/evap/staff/templates/staff_index.html index ac111241f..0ed2d8ccb 100644 --- a/evap/staff/templates/staff_index.html +++ b/evap/staff/templates/staff_index.html @@ -27,6 +27,7 @@

{% translate 'Users' %}

diff --git a/evap/staff/templates/staff_user_index.html b/evap/staff/templates/staff_user_index.html index fa93de9fb..315ec6511 100644 --- a/evap/staff/templates/staff_user_index.html +++ b/evap/staff/templates/staff_user_index.html @@ -17,6 +17,7 @@ diff --git a/evap/staff/tests/test_tools.py b/evap/staff/tests/test_tools.py index 306cfa89b..c8e057b6b 100644 --- a/evap/staff/tests/test_tools.py +++ b/evap/staff/tests/test_tools.py @@ -1,17 +1,31 @@ +from io import BytesIO +from itertools import cycle, repeat +from unittest.mock import MagicMock, patch + from django.contrib.auth.models import Group from django.test import TestCase from django.utils.html import escape +from django_webtest import WebTest from model_bakery import baker +from openpyxl import load_workbook from evap.evaluation.models import Contribution, Course, Evaluation, UserProfile from evap.evaluation.tests.tools import assert_no_database_modifications +from evap.evaluation.tools import assert_not_none from evap.rewards.models import RewardPointGranting, RewardPointRedemption +from evap.staff.fixtures.excel_files_test_data import ( + create_memory_csv_file, + create_memory_excel_file, + valid_user_courses_import_filedata, + valid_user_courses_import_users, +) from evap.staff.tools import ( conditional_escape, merge_users, remove_user_from_represented_and_ccing_users, user_edit_link, ) +from tools.enrollment_preprocessor import run_preprocessor class MergeUsersTest(TestCase): @@ -216,3 +230,76 @@ def test_conditional_escape(self): self.assertEqual(conditional_escape("