diff --git a/Makefile b/Makefile index 324455b2..32186470 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,9 @@ compile-requirements: ## Re-compile *.in requirements to *.txt sed '/^[dD]jango==/d' requirements/test.txt > requirements/test.tmp mv requirements/test.tmp requirements/test.txt +format: + black ${SRC_FILES} + upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in $(MAKE) compile-requirements COMPILE_OPTS="--upgrade" @@ -69,7 +72,7 @@ test-all: clean test test-quality test-pii selfcheck ## run all tests test: ## run unit tests pytest -test-quality: test-lint test-codestyle test-isort test-mypy ## run static coverage tests +test-quality: test-lint test-codestyle test-mypy test-format ## run static coverage tests test-lint: ## run pylint pylint ${SRC_FILES} @@ -84,6 +87,9 @@ test-isort: ## run isort checks test-mypy: ## run type tests mypy ${SRC_FILES_PROD} +test-format: ## Run code formatting tests + black --check ${SRC_FILES} + test-pii: export DJANGO_SETTINGS_MODULE=test_settings test-pii: ## # check for PII annotations on all Django models code_annotations django_find_annotations --config_file .pii_annotations.yml --lint --report --coverage diff --git a/forum/__init__.py b/forum/__init__.py index 3d9a1877..dd159e42 100644 --- a/forum/__init__.py +++ b/forum/__init__.py @@ -2,4 +2,4 @@ Openedx forum app. """ -__version__ = '0.1.0' +__version__ = "0.1.0" diff --git a/forum/models/contents.py b/forum/models/contents.py index 07056ea0..fdc00938 100644 --- a/forum/models/contents.py +++ b/forum/models/contents.py @@ -30,7 +30,9 @@ def __init__( """ super().__init__(collection_name, client) - def get(self, _id: str) -> Optional[Dict[str, Any]]: # pylint: disable=arguments-differ + def get( + self, _id: str + ) -> Optional[Dict[str, Any]]: # pylint: disable=arguments-differ """ Retrieves a contents document from the database based on the provided _id. Args: @@ -85,7 +87,9 @@ def insert( # pylint: disable=arguments-differ result = self._collection.insert_one(content_data) return str(result.inserted_id) - def update(self, _id: str, **kwargs: Any) -> int: # pylint: disable=arguments-differ + def update( + self, _id: str, **kwargs: Any + ) -> int: # pylint: disable=arguments-differ """ Updates a contents document in the database based on the provided _id. diff --git a/forum/models/model_utils.py b/forum/models/model_utils.py index 7d4d13ad..b3ace174 100644 --- a/forum/models/model_utils.py +++ b/forum/models/model_utils.py @@ -45,7 +45,9 @@ def flag_as_abuse( return Contents().get(entity["_id"]) -def un_flag_as_abuse(user: Dict[str, Any], entity: Dict[str, Any]) -> Union[Dict[str, Any], None]: +def un_flag_as_abuse( + user: Dict[str, Any], entity: Dict[str, Any] +) -> Union[Dict[str, Any], None]: """ Unflag an entity as abuse. diff --git a/forum/serializers/comment.py b/forum/serializers/comment.py index 6b9afb65..2e1558fb 100644 --- a/forum/serializers/comment.py +++ b/forum/serializers/comment.py @@ -1,6 +1,7 @@ """ Serializer for the comment data. """ + from typing import Any, Dict from rest_framework import serializers diff --git a/forum/serializers/thread.py b/forum/serializers/thread.py index c838b41d..b40e42a7 100644 --- a/forum/serializers/thread.py +++ b/forum/serializers/thread.py @@ -1,6 +1,7 @@ """ Serializer for the thread data. """ + from typing import Any, Dict from rest_framework import serializers diff --git a/forum/views/flags.py b/forum/views/flags.py index f5e5f11a..f8799ae8 100644 --- a/forum/views/flags.py +++ b/forum/views/flags.py @@ -7,7 +7,11 @@ from rest_framework.views import APIView from forum.models import Contents, Users -from forum.models.model_utils import flag_as_abuse, un_flag_all_as_abuse, un_flag_as_abuse +from forum.models.model_utils import ( + flag_as_abuse, + un_flag_all_as_abuse, + un_flag_as_abuse, +) from forum.serializers.contents import ContentSerializer @@ -38,7 +42,7 @@ def put(self, request: Request, comment_id: str, action: str) -> Response: if not (user and content): return Response( {"error": "User / Comment doesn't exist"}, - status=status.HTTP_400_BAD_REQUEST + status=status.HTTP_400_BAD_REQUEST, ) if action == "flag": comment = flag_as_abuse(user, content) @@ -49,8 +53,7 @@ def put(self, request: Request, comment_id: str, action: str) -> Response: comment = un_flag_as_abuse(user, content) else: return Response( - {"error": "Invalid action"}, - status=status.HTTP_400_BAD_REQUEST + {"error": "Invalid action"}, status=status.HTTP_400_BAD_REQUEST ) serializer = ContentSerializer(comment) return Response(serializer.data, status=status.HTTP_200_OK) @@ -83,7 +86,7 @@ def put(self, request: Request, thread_id: str, action: str) -> Response: if not (user and content): return Response( {"error": "User / Comment doesn't exist"}, - status=status.HTTP_400_BAD_REQUEST + status=status.HTTP_400_BAD_REQUEST, ) if action == "flag": thread = flag_as_abuse(user, content) diff --git a/manage.py b/manage.py index 4afa5aa0..aba008e4 100644 --- a/manage.py +++ b/manage.py @@ -8,8 +8,8 @@ PWD = os.path.abspath(os.path.dirname(__file__)) -if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings') +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") sys.path.append(PWD) try: from django.core.management import execute_from_command_line diff --git a/requirements/base.txt b/requirements/base.txt index 3eff6827..3232beae 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -29,7 +29,5 @@ requests==2.32.3 # via -r requirements/base.in sqlparse==0.5.1 # via django -typing-extensions==4.12.2 - # via asgiref urllib3==2.2.2 # via requests diff --git a/requirements/ci.in b/requirements/ci.in index 631638b2..ac57c6a8 100644 --- a/requirements/ci.in +++ b/requirements/ci.in @@ -3,3 +3,5 @@ -c constraints.txt -r quality.txt # Core and quality check dependencies + +black # code formatter diff --git a/requirements/ci.txt b/requirements/ci.txt index 45e2fd93..e67ab7da 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -14,6 +14,8 @@ astroid==3.2.4 # -r requirements/quality.txt # pylint # pylint-celery +black==24.8.0 + # via -r requirements/ci.in cachetools==5.4.0 # via # -r requirements/quality.txt @@ -33,6 +35,7 @@ charset-normalizer==3.3.2 click==8.1.7 # via # -r requirements/quality.txt + # black # click-log # code-annotations # edx-lint @@ -85,10 +88,6 @@ dnspython==2.6.1 # pymongo edx-lint==5.3.7 # via -r requirements/quality.txt -exceptiongroup==1.2.2 - # via - # -r requirements/quality.txt - # pytest filelock==3.15.4 # via # -r requirements/quality.txt @@ -125,16 +124,20 @@ mypy==1.11.1 mypy-extensions==1.0.0 # via # -r requirements/quality.txt + # black # mypy openedx-atlas==0.6.1 # via -r requirements/quality.txt packaging==24.1 # via # -r requirements/quality.txt + # black # mongomock # pyproject-api # pytest # tox +pathspec==0.12.1 + # via black pbr==6.0.0 # via # -r requirements/quality.txt @@ -142,6 +145,7 @@ pbr==6.0.0 platformdirs==4.2.2 # via # -r requirements/quality.txt + # black # pylint # tox # virtualenv @@ -225,21 +229,11 @@ text-unidecode==1.3 # via # -r requirements/quality.txt # python-slugify -tomli==2.0.1 - # via - # -r requirements/quality.txt - # coverage - # django-stubs - # mypy - # pylint - # pyproject-api - # pytest - # tox -tomlkit==0.13.0 +tomlkit==0.13.2 # via # -r requirements/quality.txt # pylint -tox==4.17.1 +tox==4.18.0 # via -r requirements/quality.txt types-pyyaml==6.0.12.20240808 # via @@ -253,8 +247,6 @@ types-requests==2.32.0.20240712 typing-extensions==4.12.2 # via # -r requirements/quality.txt - # asgiref - # astroid # django-stubs # django-stubs-ext # djangorestframework-stubs diff --git a/requirements/dev.txt b/requirements/dev.txt index f183b652..d4e967dc 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -16,6 +16,8 @@ astroid==3.2.4 # -r requirements/quality.txt # pylint # pylint-celery +black==24.8.0 + # via -r requirements/ci.txt build==1.2.1 # via # -r requirements/pip-tools.txt @@ -46,6 +48,7 @@ click==8.1.7 # -r requirements/ci.txt # -r requirements/pip-tools.txt # -r requirements/quality.txt + # black # click-log # code-annotations # edx-lint @@ -120,11 +123,6 @@ edx-lint==5.3.7 # via # -r requirements/ci.txt # -r requirements/quality.txt -exceptiongroup==1.2.2 - # via - # -r requirements/ci.txt - # -r requirements/quality.txt - # pytest filelock==3.15.4 # via # -r requirements/ci.txt @@ -176,6 +174,7 @@ mypy-extensions==1.0.0 # via # -r requirements/ci.txt # -r requirements/quality.txt + # black # mypy openedx-atlas==0.6.1 # via @@ -186,6 +185,7 @@ packaging==24.1 # -r requirements/ci.txt # -r requirements/pip-tools.txt # -r requirements/quality.txt + # black # build # mongomock # pyproject-api @@ -193,6 +193,10 @@ packaging==24.1 # tox path==16.16.0 # via edx-i18n-tools +pathspec==0.12.1 + # via + # -r requirements/ci.txt + # black pbr==6.0.0 # via # -r requirements/ci.txt @@ -204,6 +208,7 @@ platformdirs==4.2.2 # via # -r requirements/ci.txt # -r requirements/quality.txt + # black # pylint # tox # virtualenv @@ -324,26 +329,12 @@ text-unidecode==1.3 # -r requirements/ci.txt # -r requirements/quality.txt # python-slugify -tomli==2.0.1 - # via - # -r requirements/ci.txt - # -r requirements/pip-tools.txt - # -r requirements/quality.txt - # build - # coverage - # django-stubs - # mypy - # pip-tools - # pylint - # pyproject-api - # pytest - # tox -tomlkit==0.13.0 +tomlkit==0.13.2 # via # -r requirements/ci.txt # -r requirements/quality.txt # pylint -tox==4.17.1 +tox==4.18.0 # via # -r requirements/ci.txt # -r requirements/quality.txt @@ -362,8 +353,6 @@ typing-extensions==4.12.2 # via # -r requirements/ci.txt # -r requirements/quality.txt - # asgiref - # astroid # django-stubs # django-stubs-ext # djangorestframework-stubs diff --git a/requirements/doc.txt b/requirements/doc.txt index fd2084dc..f9116a7b 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -1,12 +1,12 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade # -accessible-pygments==0.0.4 +accessible-pygments==0.0.5 # via pydata-sphinx-theme -alabaster==0.7.13 +alabaster==1.0.0 # via sphinx asgiref==3.8.1 # via @@ -30,8 +30,6 @@ certifi==2024.7.4 # via # -r requirements/test.txt # requests -cffi==1.17.0 - # via cryptography chardet==5.2.0 # via # -r requirements/test.txt @@ -54,8 +52,6 @@ coverage[toml]==7.6.1 # via # -r requirements/test.txt # pytest-cov -cryptography==43.0.0 - # via secretstorage distlib==0.3.8 # via # -r requirements/test.txt @@ -73,17 +69,13 @@ dnspython==2.6.1 # pymongo doc8==1.1.1 # via -r requirements/doc.in -docutils==0.19 +docutils==0.20.1 # via # doc8 # pydata-sphinx-theme # readme-renderer # restructuredtext-lint # sphinx -exceptiongroup==1.2.2 - # via - # -r requirements/test.txt - # pytest filelock==3.15.4 # via # -r requirements/test.txt @@ -109,10 +101,6 @@ jaraco-context==5.3.0 # via keyring jaraco-functools==4.0.2 # via keyring -jeepney==0.8.0 - # via - # keyring - # secretstorage jinja2==3.1.4 # via # -r requirements/test.txt @@ -164,9 +152,7 @@ pluggy==1.5.0 # -r requirements/test.txt # pytest # tox -pycparser==2.22 - # via cffi -pydata-sphinx-theme==0.14.4 +pydata-sphinx-theme==0.15.4 # via sphinx-book-theme pygments==2.18.0 # via @@ -217,34 +203,32 @@ rfc3986==2.0.0 # via twine rich==13.7.1 # via twine -secretstorage==3.3.3 - # via keyring sentinels==1.0.0 # via # -r requirements/test.txt # mongomock snowballstemmer==2.2.0 # via sphinx -soupsieve==2.5 +soupsieve==2.6 # via beautifulsoup4 -sphinx==6.2.1 +sphinx==8.0.2 # via # -r requirements/doc.in # pydata-sphinx-theme # sphinx-book-theme -sphinx-book-theme==1.0.1 +sphinx-book-theme==1.1.3 # via -r requirements/doc.in -sphinxcontrib-applehelp==1.0.4 +sphinxcontrib-applehelp==2.0.0 # via sphinx -sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-devhelp==2.0.0 # via sphinx -sphinxcontrib-htmlhelp==2.0.1 +sphinxcontrib-htmlhelp==2.1.0 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx -sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-qthelp==2.0.0 # via sphinx -sphinxcontrib-serializinghtml==1.1.5 +sphinxcontrib-serializinghtml==2.0.0 # via sphinx sqlparse==0.5.1 # via @@ -259,24 +243,12 @@ text-unidecode==1.3 # via # -r requirements/test.txt # python-slugify -tomli==2.0.1 - # via - # -r requirements/test.txt - # build - # coverage - # doc8 - # pyproject-api - # pytest - # tox -tox==4.17.1 +tox==4.18.0 # via -r requirements/test.txt twine==5.1.1 # via -r requirements/doc.in typing-extensions==4.12.2 - # via - # -r requirements/test.txt - # asgiref - # pydata-sphinx-theme + # via pydata-sphinx-theme urllib3==2.2.2 # via # -r requirements/test.txt diff --git a/requirements/pip-tools.txt b/requirements/pip-tools.txt index 1e415c91..fedf88df 100644 --- a/requirements/pip-tools.txt +++ b/requirements/pip-tools.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -16,10 +16,6 @@ pyproject-hooks==1.1.0 # via # build # pip-tools -tomli==2.0.1 - # via - # build - # pip-tools wheel==0.44.0 # via pip-tools diff --git a/requirements/pip.txt b/requirements/pip.txt index 387a56cf..5f8b9c04 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -10,5 +10,5 @@ wheel==0.44.0 # The following packages are considered to be unsafe in a requirements file: pip==24.2 # via -r requirements/pip.in -setuptools==72.1.0 +setuptools==72.2.0 # via -r requirements/pip.in diff --git a/requirements/quality.txt b/requirements/quality.txt index fb73a98c..c4fce160 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -76,10 +76,6 @@ dnspython==2.6.1 # pymongo edx-lint==5.3.7 # via -r requirements/quality.in -exceptiongroup==1.2.2 - # via - # -r requirements/test.txt - # pytest filelock==3.15.4 # via # -r requirements/test.txt @@ -202,19 +198,9 @@ text-unidecode==1.3 # via # -r requirements/test.txt # python-slugify -tomli==2.0.1 - # via - # -r requirements/test.txt - # coverage - # django-stubs - # mypy - # pylint - # pyproject-api - # pytest - # tox -tomlkit==0.13.0 +tomlkit==0.13.2 # via pylint -tox==4.17.1 +tox==4.18.0 # via -r requirements/test.txt types-pyyaml==6.0.12.20240808 # via @@ -226,9 +212,6 @@ types-requests==2.32.0.20240712 # djangorestframework-stubs typing-extensions==4.12.2 # via - # -r requirements/test.txt - # asgiref - # astroid # django-stubs # django-stubs-ext # djangorestframework-stubs diff --git a/requirements/test.txt b/requirements/test.txt index 7cb32d1f..b25702ef 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # make upgrade @@ -30,7 +30,6 @@ coverage[toml]==7.6.1 # via pytest-cov distlib==0.3.8 # via virtualenv -django==4.2.15 # via # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt # -r requirements/base.txt @@ -41,8 +40,6 @@ dnspython==2.6.1 # via # -r requirements/base.txt # pymongo -exceptiongroup==1.2.2 - # via pytest filelock==3.15.4 # via # tox @@ -105,18 +102,8 @@ stevedore==5.2.0 # via code-annotations text-unidecode==1.3 # via python-slugify -tomli==2.0.1 - # via - # coverage - # pyproject-api - # pytest - # tox -tox==4.17.1 +tox==4.18.0 # via -r requirements/test.in -typing-extensions==4.12.2 - # via - # -r requirements/base.txt - # asgiref urllib3==2.2.2 # via # -r requirements/base.txt diff --git a/setup.py b/setup.py index 87b181da..39c5f4af 100755 --- a/setup.py +++ b/setup.py @@ -19,11 +19,10 @@ def get_version(*file_paths): """ filename = os.path.join(os.path.dirname(__file__), *file_paths) version_file = open(filename, encoding="utf8").read() - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", - version_file, re.M) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) - raise RuntimeError('Unable to find version string.') + raise RuntimeError("Unable to find version string.") def load_requirements(*requirements_paths): @@ -46,14 +45,14 @@ def check_name_consistent(package): with extras we don't constrain it without mentioning the extras (since that too would interfere with matching constraints.) """ - canonical = package.lower().replace('_', '-').split('[')[0] + canonical = package.lower().replace("_", "-").split("[")[0] seen_spelling = by_canonical_name.get(canonical) if seen_spelling is None: by_canonical_name[canonical] = package elif seen_spelling != package: raise Exception( f'Encountered both "{seen_spelling}" and "{package}" in requirements ' - 'and constraints files; please use just one or the other.' + "and constraints files; please use just one or the other." ) requirements = {} @@ -67,7 +66,9 @@ def check_name_consistent(package): % (re_package_name_base_chars, re_package_name_base_chars) ) - def add_version_constraint_or_raise(current_line, current_requirements, add_if_not_present): + def add_version_constraint_or_raise( + current_line, current_requirements, add_if_not_present + ): regex_match = requirement_line_regex.match(current_line) if regex_match: package = regex_match.group(1) @@ -76,11 +77,16 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n existing_version_constraints = current_requirements.get(package, None) # It's fine to add constraints to an unconstrained package, # but raise an error if there are already constraints in place. - if existing_version_constraints and existing_version_constraints != version_constraints: - raise BaseException(f'Multiple constraint definitions found for {package}:' - f' "{existing_version_constraints}" and "{version_constraints}".' - f'Combine constraints into one location with {package}' - f'{existing_version_constraints},{version_constraints}.') + if ( + existing_version_constraints + and existing_version_constraints != version_constraints + ): + raise BaseException( + f"Multiple constraint definitions found for {package}:" + f' "{existing_version_constraints}" and "{version_constraints}".' + f"Combine constraints into one location with {package}" + f"{existing_version_constraints},{version_constraints}." + ) if add_if_not_present or package in current_requirements: current_requirements[package] = version_constraints @@ -91,8 +97,12 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n for line in reqs: if is_requirement(line): add_version_constraint_or_raise(line, requirements, True) - if line and line.startswith('-c') and not line.startswith('-c http'): - constraint_files.add(os.path.dirname(path) + '/' + line.split('#')[0].replace('-c', '').strip()) + if line and line.startswith("-c") and not line.startswith("-c http"): + constraint_files.add( + os.path.dirname(path) + + "/" + + line.split("#")[0].replace("-c", "").strip() + ) # process constraint files: add constraints to existing requirements for constraint_file in constraint_files: @@ -102,7 +112,9 @@ def add_version_constraint_or_raise(current_line, current_requirements, add_if_n add_version_constraint_or_raise(line, requirements, False) # process back into list of pkg><=constraints strings - constrained_requirements = [f'{pkg}{version or ""}' for (pkg, version) in sorted(requirements.items())] + constrained_requirements = [ + f'{pkg}{version or ""}' for (pkg, version) in sorted(requirements.items()) + ] return constrained_requirements @@ -114,52 +126,57 @@ def is_requirement(line): bool: True if the line is not blank, a comment, a URL, or an included file """ - return line and line.strip() and not line.startswith(("-r", "#", "-e", "git+", "-c")) + return ( + line and line.strip() and not line.startswith(("-r", "#", "-e", "git+", "-c")) + ) -VERSION = get_version('forum', '__init__.py') +VERSION = get_version("forum", "__init__.py") -if sys.argv[-1] == 'tag': +if sys.argv[-1] == "tag": print("Tagging the version on github:") os.system("git tag -a %s -m 'version %s'" % (VERSION, VERSION)) os.system("git push --tags") sys.exit() -README = open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding="utf8").read() -CHANGELOG = open(os.path.join(os.path.dirname(__file__), 'CHANGELOG.rst'), encoding="utf8").read() +README = open( + os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf8" +).read() +CHANGELOG = open( + os.path.join(os.path.dirname(__file__), "CHANGELOG.rst"), encoding="utf8" +).read() setup( - name='forum', + name="forum", version=VERSION, description="""openedx forum app""", - long_description=README + '\n\n' + CHANGELOG, - author='Open edX Project', - author_email='oscm@openedx.org', - url='https://github.com/openedx/forum', + long_description=README + "\n\n" + CHANGELOG, + author="Open edX Project", + author_email="oscm@openedx.org", + url="https://github.com/openedx/forum", packages=find_packages( - include=['forum', 'forum.*'], + include=["forum", "forum.*"], exclude=["*tests"], ), - include_package_data=True, - install_requires=load_requirements('requirements/base.in'), + install_requires=load_requirements("requirements/base.in"), python_requires=">=3.8", license="AGPL 3.0", zip_safe=False, - keywords='Python edx', + keywords="Python edx", classifiers=[ - 'Development Status :: 3 - Alpha', - 'Framework :: Django', - 'Framework :: Django :: 3.2', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', - 'Natural Language :: English', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', + "Development Status :: 3 - Alpha", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", ], entry_points={ - 'lms.djangoapp': [ - 'forum = forum.apps:ForumConfig', + "lms.djangoapp": [ + "forum = forum.apps:ForumConfig", ], }, ) diff --git a/test_settings.py b/test_settings.py index d3be842d..32aa5da2 100644 --- a/test_settings.py +++ b/test_settings.py @@ -16,49 +16,51 @@ def root(*args): DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'default.db', - 'USER': '', - 'PASSWORD': '', - 'HOST': '', - 'PORT': '', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "default.db", + "USER": "", + "PASSWORD": "", + "HOST": "", + "PORT": "", } } INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.messages', - 'django.contrib.sessions', - 'forum', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.messages", + "django.contrib.sessions", + "forum", ) LOCALE_PATHS = [ - root('forum', 'conf', 'locale'), + root("forum", "conf", "locale"), ] -ROOT_URLCONF = 'forum.urls' +ROOT_URLCONF = "forum.urls" -SECRET_KEY = 'insecure-secret-key' +SECRET_KEY = "insecure-secret-key" MIDDLEWARE = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', + "django.contrib.sessions.middleware.SessionMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", ) -TEMPLATES = [{ - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': False, - 'OPTIONS': { - 'context_processors': [ - 'django.contrib.auth.context_processors.auth', # this is required for admin - 'django.contrib.messages.context_processors.messages', # this is required for admin - ], - }, -}] +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": False, + "OPTIONS": { + "context_processors": [ + "django.contrib.auth.context_processors.auth", # this is required for admin + "django.contrib.messages.context_processors.messages", # this is required for admin + ], + }, + } +] FORUM_PORT = "4567" MONGO_HOST = "mongo-test-url" diff --git a/tests/test_models/test_threads.py b/tests/test_models/test_threads.py index 69780e26..56f562fe 100644 --- a/tests/test_models/test_threads.py +++ b/tests/test_models/test_threads.py @@ -42,13 +42,28 @@ def test_delete(comment_thread_model: CommentThread) -> None: def test_list(comment_thread_model: CommentThread) -> None: """Test list all comment threads from MongoDB.""" comment_thread_model.insert( - "Thread 1", "Body 1", "_type", "CommentThread", "1", "user1", + "Thread 1", + "Body 1", + "_type", + "CommentThread", + "1", + "user1", ) comment_thread_model.insert( - "Thread 2", "Body 2", "_type", "CommentThread", "1", "user1", + "Thread 2", + "Body 2", + "_type", + "CommentThread", + "1", + "user1", ) comment_thread_model.insert( - "Thread 3", "Body 3", "_type", "CommentThread", "1", "user1", + "Thread 3", + "Body 3", + "_type", + "CommentThread", + "1", + "user1", ) threads_list = comment_thread_model.list() assert len(list(threads_list)) == 3 diff --git a/tests/test_models/test_users.py b/tests/test_models/test_users.py index 7142ca21..ffa475af 100644 --- a/tests/test_models/test_users.py +++ b/tests/test_models/test_users.py @@ -84,11 +84,7 @@ def test_update(users_model: Users) -> None: new_username = "new_username" new_email = "new_email" - result = users_model.update( - external_id, - username=new_username, - email=new_email - ) + result = users_model.update(external_id, username=new_username, email=new_email) assert result is not None assert result == 1 diff --git a/tests/test_views/test_flags.py b/tests/test_views/test_flags.py index 2e2eee31..7a8023b3 100644 --- a/tests/test_views/test_flags.py +++ b/tests/test_views/test_flags.py @@ -7,7 +7,9 @@ from forum.models import Contents, Users -def test_comment_thread_api(api_client: Client, users_model: Users, content_model: Contents) -> None: +def test_comment_thread_api( + api_client: Client, users_model: Users, content_model: Contents +) -> None: """ Test the comment thread flag API. @@ -45,7 +47,9 @@ def test_comment_thread_api(api_client: Client, users_model: Users, content_mode assert comment["abuse_flaggers"] == [] -def test_comment_flag_api(api_client: Client, users_model: Users, content_model: Contents) -> None: +def test_comment_flag_api( + api_client: Client, users_model: Users, content_model: Contents +) -> None: """ Test the comment flag API. @@ -92,7 +96,9 @@ def test_comment_flag_api(api_client: Client, users_model: Users, content_model: assert comment["abuse_flaggers"] == [] -def test_comment_flag_api_invalid_data(api_client: Client, users_model: Users, content_model: Contents) -> None: +def test_comment_flag_api_invalid_data( + api_client: Client, users_model: Users, content_model: Contents +) -> None: """ Test the comment flag API with invalid data.