From 74446e6175ad9a12637ff1019a2fea88a8b238c2 Mon Sep 17 00:00:00 2001 From: edX requirements bot Date: Thu, 24 Dec 2020 06:47:43 -0500 Subject: [PATCH 1/2] Python code cleanup by the cleanup-python-code Jenkins job. This pull request was generated by the cleanup-python-code Jenkins job, which ran ``` modernize_travis;modernize_tox;make upgrade;find . -type f -name '*.py' | while read fname; do pyupgrade --exit-zero-even-if-changed --keep-percent-format --py3-plus --py36-plus --py38-plus "$fname"; done ``` The following packages were installed: `pyupgrade,git+https://github.com/edx/repo-tools.git@5ed136448729ac3bd962bdb5d8fda417dc63efaa` --- .travis.yml | 14 +- requirements/base.txt | 63 +++- requirements/constraints.txt | 8 +- requirements/dev.txt | 330 ++++++++++++++++--- requirements/pip-tools.txt | 7 +- requirements/quality.txt | 205 +++++++++--- requirements/testing.txt | 135 ++++++-- requirements/travis.txt | 68 ++-- search/elastic.py | 8 +- search/result_processor.py | 2 +- search/tests/mock_search_engine.py | 10 +- search/tests/test_course_discovery.py | 5 +- search/tests/test_course_discovery_views.py | 2 +- search/tests/test_engines.py | 9 +- search/tests/test_search_result_processor.py | 73 ++-- search/tests/test_views.py | 16 +- search/tests/tests.py | 7 +- search/tests/utils.py | 4 +- search/urls.py | 2 +- setup.py | 2 +- tox.ini | 37 ++- 21 files changed, 758 insertions(+), 249 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7fce146f..66534295 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ language: python python: -- 3.5 -- 3.8 - + - '3.8' envs: -- TOXENV=django22 -- TOXENV=quality + - TOXENV=django22 + - TOXENV=quality services: - docker @@ -14,7 +12,7 @@ services: # Cache the pip directory. "cache: pip" doesn't work due to install override. See https://github.com/travis-ci/travis-ci/issues/3239. cache: - directories: - - $HOME/.cache/pip + - $HOME/.cache/pip before_install: make test.start_elasticsearch @@ -34,5 +32,5 @@ deploy: distributions: sdist bdist_wheel on: tags: true - python: 3.5 - condition: '$TOXENV = django22' + python: 3.8 + condition: $TOXENV = django22 diff --git a/requirements/base.txt b/requirements/base.txt index c8b8cc1e..f8157f0f 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -4,12 +4,57 @@ # # make upgrade # -certifi==2020.6.20 # via elasticsearch -django==2.2.15 # via -r requirements/base.in, event-tracking -elasticsearch==7.8.1 # via -r requirements/base.in -event-tracking==0.3.3 # via -r requirements/base.in -pymongo==3.11.0 # via event-tracking -pytz==2020.1 # via django, event-tracking -six==1.15.0 # via event-tracking -sqlparse==0.3.1 # via django -urllib3==1.25.10 # via elasticsearch +amqp==5.0.2 + # via kombu +billiard==3.6.3.0 + # via celery +celery==5.0.5 + # via event-tracking +certifi==2020.12.5 + # via elasticsearch +click-didyoumean==0.0.3 + # via celery +click-plugins==1.1.1 + # via celery +click-repl==0.1.6 + # via celery +click==7.1.2 + # via + # celery + # click-didyoumean + # click-plugins + # click-repl +django==2.2.17 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/base.in + # event-tracking +elasticsearch==7.10.1 + # via -r requirements/base.in +event-tracking==1.0.3 + # via -r requirements/base.in +kombu==5.0.2 + # via celery +prompt-toolkit==3.0.10 + # via click-repl +pymongo==3.11.2 + # via event-tracking +pytz==2020.5 + # via + # celery + # django + # event-tracking +six==1.15.0 + # via + # click-repl + # event-tracking +sqlparse==0.4.1 + # via django +urllib3==1.26.2 + # via elasticsearch +vine==5.0.0 + # via + # amqp + # celery +wcwidth==0.2.5 + # via prompt-toolkit diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 232a5ae8..3f7f0870 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -8,11 +8,13 @@ # pin when possible. Writing an issue against the offending project and # linking to it here is good. + +# This file contains all common constraints for edx-repos +-c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + + # ddt >= 1.4.0 causing test failures ddt < 1.4.0 # newer version is causing failure tox-battery==0.6.1 - - -coverage<5.1 \ No newline at end of file diff --git a/requirements/dev.txt b/requirements/dev.txt index 578eb852..d997c019 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,57 +4,285 @@ # # make upgrade # -appdirs==1.4.4 # via -r requirements/travis.txt, virtualenv -astroid==2.3.3 # via -r requirements/quality.txt, pylint, pylint-celery -attrs==19.3.0 # via -r requirements/quality.txt, -r requirements/testing.txt, pytest -certifi==2020.6.20 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, elasticsearch, requests -chardet==3.0.4 # via -r requirements/travis.txt, requests -click-log==0.3.2 # via -r requirements/quality.txt, edx-lint -click==7.1.2 # via -r requirements/pip-tools.txt, -r requirements/quality.txt, click-log, edx-lint, pip-tools -codecov==2.1.8 # via -r requirements/travis.txt -coverage==5.0.4 # via -c requirements/constraints.txt, -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, codecov, pytest-cov -ddt==1.3.1 # via -c requirements/constraints.txt, -r requirements/quality.txt, -r requirements/testing.txt -distlib==0.3.1 # via -r requirements/travis.txt, virtualenv -django==2.2.15 # via -r requirements/quality.txt, -r requirements/testing.txt, event-tracking -edx-lint==1.5.0 # via -r requirements/quality.txt -elasticsearch==7.8.1 # via -r requirements/quality.txt, -r requirements/testing.txt -event-tracking==0.3.3 # via -r requirements/quality.txt, -r requirements/testing.txt -filelock==3.0.12 # via -r requirements/travis.txt, tox, virtualenv -idna==2.10 # via -r requirements/travis.txt, requests -importlib-metadata==1.7.0 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, pluggy, pytest, tox, virtualenv -importlib-resources==3.0.0 # via -r requirements/travis.txt, virtualenv -iniconfig==1.0.1 # via -r requirements/quality.txt, -r requirements/testing.txt, pytest -isort==4.3.21 # via -r requirements/quality.txt, pylint -lazy-object-proxy==1.4.3 # via -r requirements/quality.txt, astroid -mccabe==0.6.1 # via -r requirements/quality.txt, pylint -mock==3.0.5 # via -r requirements/quality.txt, -r requirements/testing.txt -more-itertools==8.4.0 # via -r requirements/quality.txt, -r requirements/testing.txt, pytest -packaging==20.4 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, pytest, tox -pathlib2==2.3.5 # via -r requirements/quality.txt, -r requirements/testing.txt, pytest -pip-tools==5.3.1 # via -r requirements/pip-tools.txt -pluggy==0.13.1 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, pytest, tox -py==1.9.0 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, pytest, tox -pycodestyle==2.6.0 # via -r requirements/quality.txt -pylint-celery==0.3 # via -r requirements/quality.txt, edx-lint -pylint-django==2.0.11 # via -r requirements/quality.txt, edx-lint -pylint-plugin-utils==0.6 # via -r requirements/quality.txt, pylint-celery, pylint-django -pylint==2.4.4 # via -r requirements/quality.txt, edx-lint, pylint-celery, pylint-django, pylint-plugin-utils -pymongo==3.11.0 # via -r requirements/quality.txt, -r requirements/testing.txt, event-tracking -pyparsing==2.4.7 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, packaging -pytest-cov==2.10.0 # via -r requirements/quality.txt, -r requirements/testing.txt -pytest==6.0.1 # via -r requirements/quality.txt, -r requirements/testing.txt, pytest-cov -pytz==2020.1 # via -r requirements/quality.txt, -r requirements/testing.txt, django, event-tracking -requests==2.24.0 # via -r requirements/travis.txt, codecov -six==1.15.0 # via -r requirements/pip-tools.txt, -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, astroid, edx-lint, event-tracking, mock, packaging, pathlib2, pip-tools, tox, virtualenv -sqlparse==0.3.1 # via -r requirements/quality.txt, -r requirements/testing.txt, django -toml==0.10.1 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, pytest, tox -tox-battery==0.6.1 # via -c requirements/constraints.txt, -r requirements/travis.txt -tox==3.18.1 # via -r requirements/travis.txt, tox-battery -typed-ast==1.4.1 # via -r requirements/quality.txt, astroid -urllib3==1.25.10 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, elasticsearch, requests -virtualenv==20.0.29 # via -r requirements/travis.txt, tox -wrapt==1.11.2 # via -r requirements/quality.txt, astroid -zipp==1.2.0 # via -r requirements/quality.txt, -r requirements/testing.txt, -r requirements/travis.txt, importlib-metadata, importlib-resources +amqp==5.0.2 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # kombu +appdirs==1.4.4 + # via + # -r requirements/travis.txt + # virtualenv +astroid==2.4.2 + # via + # -r requirements/quality.txt + # pylint + # pylint-celery +attrs==20.3.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # pytest +billiard==3.6.3.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery +celery==5.0.5 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # event-tracking +certifi==2020.12.5 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # elasticsearch + # requests +chardet==4.0.0 + # via + # -r requirements/travis.txt + # requests +click-didyoumean==0.0.3 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery +click-log==0.3.2 + # via + # -r requirements/quality.txt + # edx-lint +click-plugins==1.1.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery +click-repl==0.1.6 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery +click==7.1.2 + # via + # -r requirements/pip-tools.txt + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery + # click-didyoumean + # click-log + # click-plugins + # click-repl + # edx-lint + # pip-tools +codecov==2.1.11 + # via -r requirements/travis.txt +coverage==5.3.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # codecov + # pytest-cov +ddt==1.3.1 + # via + # -c requirements/constraints.txt + # -r requirements/quality.txt + # -r requirements/testing.txt +distlib==0.3.1 + # via + # -r requirements/travis.txt + # virtualenv +django==2.2.17 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/quality.txt + # -r requirements/testing.txt + # event-tracking +edx-lint==1.6 + # via -r requirements/quality.txt +elasticsearch==7.10.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt +event-tracking==1.0.3 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt +filelock==3.0.12 + # via + # -r requirements/travis.txt + # tox + # virtualenv +idna==2.10 + # via + # -r requirements/travis.txt + # requests +iniconfig==1.1.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # pytest +isort==5.7.0 + # via + # -r requirements/quality.txt + # pylint +kombu==5.0.2 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery +lazy-object-proxy==1.4.3 + # via + # -r requirements/quality.txt + # astroid +mccabe==0.6.1 + # via + # -r requirements/quality.txt + # pylint +mock==4.0.3 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt +packaging==20.8 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # pytest + # tox +pip-tools==5.5.0 + # via -r requirements/pip-tools.txt +pluggy==0.13.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # pytest + # tox +prompt-toolkit==3.0.10 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # click-repl +py==1.10.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # pytest + # tox +pycodestyle==2.6.0 + # via -r requirements/quality.txt +pylint-celery==0.3 + # via + # -r requirements/quality.txt + # edx-lint +pylint-django==2.3.0 + # via + # -r requirements/quality.txt + # edx-lint +pylint-plugin-utils==0.6 + # via + # -r requirements/quality.txt + # pylint-celery + # pylint-django +pylint==2.6.0 + # via + # -r requirements/quality.txt + # edx-lint + # pylint-celery + # pylint-django + # pylint-plugin-utils +pymongo==3.11.2 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # event-tracking +pyparsing==2.4.7 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # packaging +pytest-cov==2.11.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt +pytest==6.2.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # pytest-cov +pytz==2020.5 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # celery + # django + # event-tracking +requests==2.25.1 + # via + # -r requirements/travis.txt + # codecov +six==1.15.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # astroid + # click-repl + # edx-lint + # event-tracking + # tox + # virtualenv +sqlparse==0.4.1 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # django +toml==0.10.2 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # pylint + # pytest + # tox +tox-battery==0.6.1 + # via + # -c requirements/constraints.txt + # -r requirements/travis.txt +tox==3.21.2 + # via + # -r requirements/travis.txt + # tox-battery +urllib3==1.26.2 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # -r requirements/travis.txt + # elasticsearch + # requests +vine==5.0.0 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # amqp + # celery +virtualenv==20.4.0 + # via + # -r requirements/travis.txt + # tox +wcwidth==0.2.5 + # via + # -r requirements/quality.txt + # -r requirements/testing.txt + # prompt-toolkit +wrapt==1.12.1 + # via + # -r requirements/quality.txt + # astroid # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/pip-tools.txt b/requirements/pip-tools.txt index 4b50eae7..aa6ffb82 100644 --- a/requirements/pip-tools.txt +++ b/requirements/pip-tools.txt @@ -4,9 +4,10 @@ # # make upgrade # -click==7.1.2 # via pip-tools -pip-tools==5.3.1 # via -r requirements/pip-tools.in -six==1.15.0 # via pip-tools +click==7.1.2 + # via pip-tools +pip-tools==5.5.0 + # via -r requirements/pip-tools.in # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/requirements/quality.txt b/requirements/quality.txt index b34cd254..81b08a9f 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -4,42 +4,169 @@ # # make upgrade # -astroid==2.3.3 # via pylint, pylint-celery -attrs==19.3.0 # via -r requirements/testing.txt, pytest -certifi==2020.6.20 # via -r requirements/testing.txt, elasticsearch -click-log==0.3.2 # via edx-lint -click==7.1.2 # via click-log, edx-lint -coverage==5.0.4 # via -c requirements/constraints.txt, -r requirements/quality.in, -r requirements/testing.txt, pytest-cov -ddt==1.3.1 # via -c requirements/constraints.txt, -r requirements/testing.txt -django==2.2.15 # via -r requirements/testing.txt, event-tracking -edx-lint==1.5.0 # via -r requirements/quality.in -elasticsearch==7.8.1 # via -r requirements/testing.txt -event-tracking==0.3.3 # via -r requirements/testing.txt -importlib-metadata==1.7.0 # via -r requirements/testing.txt, pluggy, pytest -iniconfig==1.0.1 # via -r requirements/testing.txt, pytest -isort==4.3.21 # via pylint -lazy-object-proxy==1.4.3 # via astroid -mccabe==0.6.1 # via pylint -mock==3.0.5 # via -r requirements/testing.txt -more-itertools==8.4.0 # via -r requirements/testing.txt, pytest -packaging==20.4 # via -r requirements/testing.txt, pytest -pathlib2==2.3.5 # via -r requirements/testing.txt, pytest -pluggy==0.13.1 # via -r requirements/testing.txt, pytest -py==1.9.0 # via -r requirements/testing.txt, pytest -pycodestyle==2.6.0 # via -r requirements/quality.in -pylint-celery==0.3 # via edx-lint -pylint-django==2.0.11 # via edx-lint -pylint-plugin-utils==0.6 # via pylint-celery, pylint-django -pylint==2.4.4 # via edx-lint, pylint-celery, pylint-django, pylint-plugin-utils -pymongo==3.11.0 # via -r requirements/testing.txt, event-tracking -pyparsing==2.4.7 # via -r requirements/testing.txt, packaging -pytest-cov==2.10.0 # via -r requirements/testing.txt -pytest==6.0.1 # via -r requirements/testing.txt, pytest-cov -pytz==2020.1 # via -r requirements/testing.txt, django, event-tracking -six==1.15.0 # via -r requirements/testing.txt, astroid, edx-lint, event-tracking, mock, packaging, pathlib2 -sqlparse==0.3.1 # via -r requirements/testing.txt, django -toml==0.10.1 # via -r requirements/testing.txt, pytest -typed-ast==1.4.1 # via astroid -urllib3==1.25.10 # via -r requirements/testing.txt, elasticsearch -wrapt==1.11.2 # via astroid -zipp==1.2.0 # via -r requirements/testing.txt, importlib-metadata +amqp==5.0.2 + # via + # -r requirements/testing.txt + # kombu +astroid==2.4.2 + # via + # pylint + # pylint-celery +attrs==20.3.0 + # via + # -r requirements/testing.txt + # pytest +billiard==3.6.3.0 + # via + # -r requirements/testing.txt + # celery +celery==5.0.5 + # via + # -r requirements/testing.txt + # event-tracking +certifi==2020.12.5 + # via + # -r requirements/testing.txt + # elasticsearch +click-didyoumean==0.0.3 + # via + # -r requirements/testing.txt + # celery +click-log==0.3.2 + # via edx-lint +click-plugins==1.1.1 + # via + # -r requirements/testing.txt + # celery +click-repl==0.1.6 + # via + # -r requirements/testing.txt + # celery +click==7.1.2 + # via + # -r requirements/testing.txt + # celery + # click-didyoumean + # click-log + # click-plugins + # click-repl + # edx-lint +coverage==5.3.1 + # via + # -r requirements/quality.in + # -r requirements/testing.txt + # pytest-cov +ddt==1.3.1 + # via + # -c requirements/constraints.txt + # -r requirements/testing.txt +django==2.2.17 + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/testing.txt + # event-tracking +edx-lint==1.6 + # via -r requirements/quality.in +elasticsearch==7.10.1 + # via -r requirements/testing.txt +event-tracking==1.0.3 + # via -r requirements/testing.txt +iniconfig==1.1.1 + # via + # -r requirements/testing.txt + # pytest +isort==5.7.0 + # via pylint +kombu==5.0.2 + # via + # -r requirements/testing.txt + # celery +lazy-object-proxy==1.4.3 + # via astroid +mccabe==0.6.1 + # via pylint +mock==4.0.3 + # via -r requirements/testing.txt +packaging==20.8 + # via + # -r requirements/testing.txt + # pytest +pluggy==0.13.1 + # via + # -r requirements/testing.txt + # pytest +prompt-toolkit==3.0.10 + # via + # -r requirements/testing.txt + # click-repl +py==1.10.0 + # via + # -r requirements/testing.txt + # pytest +pycodestyle==2.6.0 + # via -r requirements/quality.in +pylint-celery==0.3 + # via edx-lint +pylint-django==2.3.0 + # via edx-lint +pylint-plugin-utils==0.6 + # via + # pylint-celery + # pylint-django +pylint==2.6.0 + # via + # edx-lint + # pylint-celery + # pylint-django + # pylint-plugin-utils +pymongo==3.11.2 + # via + # -r requirements/testing.txt + # event-tracking +pyparsing==2.4.7 + # via + # -r requirements/testing.txt + # packaging +pytest-cov==2.11.0 + # via -r requirements/testing.txt +pytest==6.2.1 + # via + # -r requirements/testing.txt + # pytest-cov +pytz==2020.5 + # via + # -r requirements/testing.txt + # celery + # django + # event-tracking +six==1.15.0 + # via + # -r requirements/testing.txt + # astroid + # click-repl + # edx-lint + # event-tracking +sqlparse==0.4.1 + # via + # -r requirements/testing.txt + # django +toml==0.10.2 + # via + # -r requirements/testing.txt + # pylint + # pytest +urllib3==1.26.2 + # via + # -r requirements/testing.txt + # elasticsearch +vine==5.0.0 + # via + # -r requirements/testing.txt + # amqp + # celery +wcwidth==0.2.5 + # via + # -r requirements/testing.txt + # prompt-toolkit +wrapt==1.12.1 + # via astroid diff --git a/requirements/testing.txt b/requirements/testing.txt index d34b454b..4ee4eb99 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -4,27 +4,114 @@ # # make upgrade # -attrs==19.3.0 # via pytest -certifi==2020.6.20 # via -r requirements/base.txt, elasticsearch -coverage==5.0.4 # via -c requirements/constraints.txt, -r requirements/testing.in, pytest-cov -ddt==1.3.1 # via -c requirements/constraints.txt, -r requirements/testing.in -elasticsearch==7.8.1 # via -r requirements/base.txt -event-tracking==0.3.3 # via -r requirements/base.txt -importlib-metadata==1.7.0 # via pluggy, pytest -iniconfig==1.0.1 # via pytest -mock==3.0.5 # via -r requirements/testing.in -more-itertools==8.4.0 # via pytest -packaging==20.4 # via pytest -pathlib2==2.3.5 # via pytest -pluggy==0.13.1 # via pytest -py==1.9.0 # via pytest -pymongo==3.11.0 # via -r requirements/base.txt, event-tracking -pyparsing==2.4.7 # via packaging -pytest-cov==2.10.0 # via -r requirements/testing.in -pytest==6.0.1 # via pytest-cov -pytz==2020.1 # via -r requirements/base.txt, django, event-tracking -six==1.15.0 # via -r requirements/base.txt, event-tracking, mock, packaging, pathlib2 -sqlparse==0.3.1 # via -r requirements/base.txt, django -toml==0.10.1 # via pytest -urllib3==1.25.10 # via -r requirements/base.txt, elasticsearch -zipp==1.2.0 # via importlib-metadata +amqp==5.0.2 + # via + # -r requirements/base.txt + # kombu +attrs==20.3.0 + # via pytest +billiard==3.6.3.0 + # via + # -r requirements/base.txt + # celery +celery==5.0.5 + # via + # -r requirements/base.txt + # event-tracking +certifi==2020.12.5 + # via + # -r requirements/base.txt + # elasticsearch +click-didyoumean==0.0.3 + # via + # -r requirements/base.txt + # celery +click-plugins==1.1.1 + # via + # -r requirements/base.txt + # celery +click-repl==0.1.6 + # via + # -r requirements/base.txt + # celery +click==7.1.2 + # via + # -r requirements/base.txt + # celery + # click-didyoumean + # click-plugins + # click-repl +coverage==5.3.1 + # via + # -r requirements/testing.in + # pytest-cov +ddt==1.3.1 + # via + # -c requirements/constraints.txt + # -r requirements/testing.in + # via + # -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt + # -r requirements/base.txt + # event-tracking +elasticsearch==7.10.1 + # via -r requirements/base.txt +event-tracking==1.0.3 + # via -r requirements/base.txt +iniconfig==1.1.1 + # via pytest +kombu==5.0.2 + # via + # -r requirements/base.txt + # celery +mock==4.0.3 + # via -r requirements/testing.in +packaging==20.8 + # via pytest +pluggy==0.13.1 + # via pytest +prompt-toolkit==3.0.10 + # via + # -r requirements/base.txt + # click-repl +py==1.10.0 + # via pytest +pymongo==3.11.2 + # via + # -r requirements/base.txt + # event-tracking +pyparsing==2.4.7 + # via packaging +pytest-cov==2.11.0 + # via -r requirements/testing.in +pytest==6.2.1 + # via pytest-cov +pytz==2020.5 + # via + # -r requirements/base.txt + # celery + # django + # event-tracking +six==1.15.0 + # via + # -r requirements/base.txt + # click-repl + # event-tracking +sqlparse==0.4.1 + # via + # -r requirements/base.txt + # django +toml==0.10.2 + # via pytest +urllib3==1.26.2 + # via + # -r requirements/base.txt + # elasticsearch +vine==5.0.0 + # via + # -r requirements/base.txt + # amqp + # celery +wcwidth==0.2.5 + # via + # -r requirements/base.txt + # prompt-toolkit diff --git a/requirements/travis.txt b/requirements/travis.txt index 4414a120..715648ed 100644 --- a/requirements/travis.txt +++ b/requirements/travis.txt @@ -4,25 +4,49 @@ # # make upgrade # -appdirs==1.4.4 # via virtualenv -certifi==2020.6.20 # via requests -chardet==3.0.4 # via requests -codecov==2.1.8 # via -r requirements/travis.in -coverage==5.0.4 # via -c requirements/constraints.txt, codecov -distlib==0.3.1 # via virtualenv -filelock==3.0.12 # via tox, virtualenv -idna==2.10 # via requests -importlib-metadata==1.7.0 # via pluggy, tox, virtualenv -importlib-resources==3.0.0 # via virtualenv -packaging==20.4 # via tox -pluggy==0.13.1 # via tox -py==1.9.0 # via tox -pyparsing==2.4.7 # via packaging -requests==2.24.0 # via codecov -six==1.15.0 # via packaging, tox, virtualenv -toml==0.10.1 # via tox -tox-battery==0.6.1 # via -c requirements/constraints.txt, -r requirements/travis.in -tox==3.18.1 # via -r requirements/travis.in, tox-battery -urllib3==1.25.10 # via requests -virtualenv==20.0.29 # via tox -zipp==1.2.0 # via importlib-metadata, importlib-resources +appdirs==1.4.4 + # via virtualenv +certifi==2020.12.5 + # via requests +chardet==4.0.0 + # via requests +codecov==2.1.11 + # via -r requirements/travis.in +coverage==5.3.1 + # via codecov +distlib==0.3.1 + # via virtualenv +filelock==3.0.12 + # via + # tox + # virtualenv +idna==2.10 + # via requests +packaging==20.8 + # via tox +pluggy==0.13.1 + # via tox +py==1.10.0 + # via tox +pyparsing==2.4.7 + # via packaging +requests==2.25.1 + # via codecov +six==1.15.0 + # via + # tox + # virtualenv +toml==0.10.2 + # via tox +tox-battery==0.6.1 + # via + # -c requirements/constraints.txt + # -r requirements/travis.in +tox==3.21.2 + # via + # -r requirements/travis.in + # tox-battery +urllib3==1.26.2 + # via requests +virtualenv==20.4.0 + # via tox diff --git a/search/elastic.py b/search/elastic.py index 87b4e474..701378cd 100644 --- a/search/elastic.py +++ b/search/elastic.py @@ -215,7 +215,7 @@ def _get_total_doc_key(bucket_name): :param bucket_name: string :return: string """ - return "total_{}_docs".format(bucket_name) + return f"total_{bucket_name}_docs" def _process_aggregation_terms(aggregation_terms): @@ -250,7 +250,7 @@ def get_cache_item_name(index_name): """ Name-formatter for cache_item_name """ - return "elastic_search_mappings_{}".format(index_name) + return f"elastic_search_mappings_{index_name}" @classmethod def get_mappings(cls, index_name): @@ -326,7 +326,7 @@ def _clear_mapping(self): ElasticSearchEngine.set_mappings(self.index_name, {}) def __init__(self, index=None): - super(ElasticSearchEngine, self).__init__(index) + super().__init__(index) es_config = getattr(settings, "ELASTIC_SEARCH_CONFIG", [{}]) self._es = getattr(settings, "ELASTIC_SEARCH_IMPL", Elasticsearch)(es_config) if not self._es.indices.exists(index=self.index_name): @@ -429,7 +429,7 @@ def index(self, sources, **kwargs): if indexing_errors: ElasticSearchEngine.log_indexing_error(indexing_errors) # Broad exception handler to protect around bulk call - except exceptions.ElasticsearchException as ex: + except exceptions.ElasticsearchException: log.exception("Error during ES bulk operation.") raise diff --git a/search/result_processor.py b/search/result_processor.py index a0109904..8e0fcec5 100644 --- a/search/result_processor.py +++ b/search/result_processor.py @@ -83,7 +83,7 @@ def decorate_matches(match_in, match_word): for matched_string in {match.group() for match in matches}: match_in = match_in.replace( matched_string, - getattr(settings, "SEARCH_MATCH_DECORATION", u"{}").format(matched_string) + getattr(settings, "SEARCH_MATCH_DECORATION", "{}").format(matched_string) ) return match_in diff --git a/search/tests/mock_search_engine.py b/search/tests/mock_search_engine.py index 750c38ea..e7074e3f 100644 --- a/search/tests/mock_search_engine.py +++ b/search/tests/mock_search_engine.py @@ -92,13 +92,13 @@ def value_matches(doc, field_name, field_value): and (field_value.upper is None or compare_value <= field_value.upper) ) if _is_iterable(compare_value) and not _is_iterable(field_value): - return any((item == field_value for item in compare_value)) + return any(item == field_value for item in compare_value) if _is_iterable(field_value) and not _is_iterable(compare_value): - return any((item == compare_value for item in field_value)) + return any(item == compare_value for item in field_value) if _is_iterable(compare_value) and _is_iterable(field_value): - return any((str(item) in field_value for item in compare_value)) + return any(str(item) in field_value for item in compare_value) return compare_value == field_value @@ -266,7 +266,7 @@ def _load_from_file(cls): """ load the index dict from the contents of the backing file """ file_name = cls._backing_file() if file_name and os.path.exists(file_name): - with open(file_name, "r") as dict_file: + with open(file_name) as dict_file: cls._mock_elastic = json.load(dict_file) @staticmethod @@ -315,7 +315,7 @@ def destroy(cls): cls._write_to_file() def __init__(self, index=None): - super(MockSearchEngine, self).__init__(index) + super().__init__(index) MockSearchEngine.load_index(self.index_name) def index(self, sources, **kwargs): diff --git a/search/tests/test_course_discovery.py b/search/tests/test_course_discovery.py index c87ac931..cad33b4a 100644 --- a/search/tests/test_course_discovery.py +++ b/search/tests/test_course_discovery.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Some of the subclasses that get used as settings-overrides will yield this pylint # error, but they do get used when included as part of the override_settings # pylint: disable=too-few-public-methods @@ -96,7 +95,7 @@ def _is_elastic(self): return isinstance(self.searcher, ElasticSearchEngine) def setUp(self): - super(TestMockCourseDiscoverySearch, self).setUp() + super().setUp() # ignore unexpected-keyword-arg; ES python client documents that it can be used # pylint: disable=unexpected-keyword-arg if self._is_elastic: @@ -125,7 +124,7 @@ def tearDown(self): MockSearchEngine.destroy() self._searcher = None - super(TestMockCourseDiscoverySearch, self).tearDown() + super().tearDown() def test_course_list(self): """ No arguments to course_discovery_search should show all available courses""" diff --git a/search/tests/test_course_discovery_views.py b/search/tests/test_course_discovery_views.py index b773b7cd..918b6ccf 100644 --- a/search/tests/test_course_discovery_views.py +++ b/search/tests/test_course_discovery_views.py @@ -25,7 +25,7 @@ class DiscoveryUrlTest(MockSearchUrlTest): """ def setUp(self): - super(DiscoveryUrlTest, self).setUp() + super().setUp() DemoCourse.reset_count() DemoCourse.get_and_index( self.searcher, {"org": "OrgA", "content": {"short_description": "Find this one with the right parameter"}} diff --git a/search/tests/test_engines.py b/search/tests/test_engines.py index 9bad1373..957863c0 100644 --- a/search/tests/test_engines.py +++ b/search/tests/test_engines.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Some of the subclasses that get used as settings-overrides will yield this pylint # error, but they do get used when included as part of the override_settings # pylint: disable=too-few-public-methods @@ -9,11 +8,11 @@ import os from datetime import datetime +from unittest.mock import patch from django.test import TestCase from django.test.utils import override_settings from elasticsearch import exceptions from elasticsearch.helpers import BulkIndexError -from mock import patch from search.api import perform_search, NoSearchEngineError from search.elastic import RESERVED_CHARACTERS @@ -84,14 +83,14 @@ class FileBackedMockSearchTests(MockSearchTests): """ Override that runs the same tests with file-backed MockSearchEngine """ def setUp(self): - super(FileBackedMockSearchTests, self).setUp() + super().setUp() MockSearchEngine.create_test_file() self._searcher = None def tearDown(self): MockSearchEngine.destroy_test_file() self._searcher = None - super(FileBackedMockSearchTests, self).tearDown() + super().tearDown() def test_file_value_formats(self): """ test the format of values that write/read from the file """ @@ -150,7 +149,7 @@ def test_disabled_index(self): # copy content, and then erase file so that backed file is not present and work is disabled initial_file_content = None - with open("testfile.pkl", "r") as dict_file: + with open("testfile.pkl") as dict_file: initial_file_content = json.load(dict_file) os.remove("testfile.pkl") diff --git a/search/tests/test_search_result_processor.py b/search/tests/test_search_result_processor.py index 3d6040df..cb3994fb 100644 --- a/search/tests/test_search_result_processor.py +++ b/search/tests/test_search_result_processor.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Tests for result processors """ import ddt @@ -123,52 +122,52 @@ def test_excerpt(self): """ test that we return an excerpt """ test_result = { "content": { - "notes": u"Here is a الاستحسان about edx", + "notes": "Here is a الاستحسان about edx", "name": "edX search a lot", } } - srp = SearchResultProcessor(test_result, u"الاستحسان") - self.assertEqual(srp.excerpt, u"Here is a الاستحسان about edx") + srp = SearchResultProcessor(test_result, "الاستحسان") + self.assertEqual(srp.excerpt, "Here is a الاستحسان about edx") - srp = SearchResultProcessor(test_result, u"edx") + srp = SearchResultProcessor(test_result, "edx") self.assertIn( - u"Here is a الاستحسان about edx", + "Here is a الاستحسان about edx", srp.excerpt ) def test_too_long_excerpt(self): """ test that we shorten an excerpt that is too long appropriately """ test_string = ( - u"Here is a note about الاستحسان and it is very long - more than the desirable length of 100" - u" characters - indeed this should show up but it should trim the characters around in" - u" order to show the selected text in bold" + "Here is a note about الاستحسان and it is very long - more than the desirable length of 100" + " characters - indeed this should show up but it should trim the characters around in" + " order to show the selected text in bold" ) test_result = { "content": { "notes": test_string, } } - srp = SearchResultProcessor(test_result, u"الاستحسان") - test_string_compare = SearchResultProcessor.decorate_matches(test_string, u"الاستحسان") + srp = SearchResultProcessor(test_result, "الاستحسان") + test_string_compare = SearchResultProcessor.decorate_matches(test_string, "الاستحسان") excerpt = srp.excerpt self.assertNotEqual(excerpt, test_string_compare) - self.assertIn(u"note about الاستحسان and it is", excerpt) + self.assertIn("note about الاستحسان and it is", excerpt) test_string = ( - u"Here is a note about stuff and it is very long - more than the desirable length of 100" - u" characters - indeed this should show up but it should trim the الاستحسان characters around in" - u" order to show the selected text in bold" + "Here is a note about stuff and it is very long - more than the desirable length of 100" + " characters - indeed this should show up but it should trim the الاستحسان characters around in" + " order to show the selected text in bold" ) test_result = { "content": { "notes": test_string, } } - srp = SearchResultProcessor(test_result, u"الاستحسان") - test_string_compare = SearchResultProcessor.decorate_matches(test_string, u"الاستحسان") + srp = SearchResultProcessor(test_result, "الاستحسان") + test_string_compare = SearchResultProcessor.decorate_matches(test_string, "الاستحسان") excerpt = srp.excerpt self.assertNotEqual(excerpt, test_string_compare) - self.assertIn(u"should trim the الاستحسان characters around", excerpt) + self.assertIn("should trim the الاستحسان characters around", excerpt) def test_excerpt_front(self): """ test that we process correctly when match is at the front of the excerpt """ @@ -217,34 +216,34 @@ def test_excerpt_back(self): self.assertEqual(srp.excerpt[-33:], "Match upon last word - Dog") @ddt.data( - (u'"never disappear"', u"leads to your door Will never disappear"), - (u'"I\'ve seen"', u"I've seen that road before It always"), + ('"never disappear"', "leads to your door Will never disappear"), + ('"I\'ve seen"', "I've seen that road before It always"), ( - u'"long and winding" leads', - u'The long and winding road That leads to your door' + '"long and winding" leads', + 'The long and winding road That leads to your door' ), - (u'"search"', u"इसको search करें| Lead"), - (u'"हिंदी में"', u"It always leads me here यह एक हिंदी में"), - (u'"इसको search"', u"वाक्य है| इसको search करें| Lead me"), + ('"search"', "इसको search करें| Lead"), + ('"हिंदी में"', "It always leads me here यह एक हिंदी में"), + ('"इसको search"', "वाक्य है| इसको search करें| Lead me"), # Match at the beginning - (u'"The long"', u'The long and winding road That'), + ('"The long"', 'The long and winding road That'), # Match at the end - (u'"rain washed away"', u'windy night That the rain washed away'), + ('"rain washed away"', 'windy night That the rain washed away'), ) @ddt.unpack def test_excerpt_quoted(self, search_phrase, expected_excerpt): test_result = { "content": { "notes": ( - u"The long and winding road " - u"That leads to your door " - u"Will never disappear " - u"I've seen that road before " - u"It always leads me here " - u"यह एक हिंदी में लिखा हुआ वाक्य है| इसको search करें| " - u"Lead me to you door " - u"The wild and windy night " - u"That the rain washed away " + "The long and winding road " + "That leads to your door " + "Will never disappear " + "I've seen that road before " + "It always leads me here " + "यह एक हिंदी में लिखा हुआ वाक्य है| इसको search करें| " + "Lead me to you door " + "The wild and windy night " + "That the rain washed away " ), } } @@ -271,7 +270,7 @@ def url(self): if "course" not in self._results_fields or "id" not in self._results_fields: raise ValueError("expect this error when not providing a course and/or id") - return u"/courses/{course_id}/jump_to/{location}".format( + return "/courses/{course_id}/jump_to/{location}".format( course_id=self._results_fields["course"], location=self._results_fields["id"], ) diff --git a/search/tests/test_views.py b/search/tests/test_views.py index 27ce8be2..e86e9e7f 100644 --- a/search/tests/test_views.py +++ b/search/tests/test_views.py @@ -1,12 +1,12 @@ """ High-level view tests""" from datetime import datetime +from unittest.mock import patch, call import ddt from django.urls import Resolver404, resolve from django.test import TestCase from django.test.utils import override_settings -from mock import patch, call from search.search_engine_base import SearchEngine from search.tests.mock_search_engine import MockSearchEngine @@ -30,7 +30,7 @@ def _reset_mocked_tracker(self): self.mock_tracker.reset_mock() def setUp(self): - super(MockSearchUrlTest, self).setUp() + super().setUp() MockSearchEngine.destroy() self._searcher = None patcher = patch('search.views.track') @@ -40,7 +40,7 @@ def setUp(self): def tearDown(self): MockSearchEngine.destroy() self._searcher = None - super(MockSearchUrlTest, self).tearDown() + super().tearDown() def assert_no_events_were_emitted(self): """Ensures no events were emitted since the last event related assertion""" @@ -360,12 +360,12 @@ class BadSearchTest(TestCase, SearcherMixin): """ Make sure that we can error message when there is a problem """ def setUp(self): - super(BadSearchTest, self).setUp() + super().setUp() MockSearchEngine.destroy() def tearDown(self): MockSearchEngine.destroy() - super(BadSearchTest, self).tearDown() + super().tearDown() def test_search_from_url(self): """ ensure that we get the error back when the backend fails """ @@ -404,12 +404,12 @@ class BadIndexTest(TestCase, SearcherMixin): """ Make sure that we can error message when there is a problem """ def setUp(self): - super(BadIndexTest, self).setUp() + super().setUp() MockSearchEngine.destroy() def tearDown(self): MockSearchEngine.destroy() - super(BadIndexTest, self).tearDown() + super().tearDown() def test_search_from_url(self): """ ensure that we get the error back when the backend fails """ @@ -429,7 +429,7 @@ class ElasticSearchUrlTest(TestCase, SearcherMixin): """ def setUp(self): - super(ElasticSearchUrlTest, self).setUp() + super().setUp() patcher = patch('search.views.track') self.mock_tracker = patcher.start() self.addCleanup(patcher.stop) diff --git a/search/tests/tests.py b/search/tests/tests.py index aaed817b..bf7a7259 100644 --- a/search/tests/tests.py +++ b/search/tests/tests.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Some of the subclasses that get used as settings-overrides will yield this pylint # error, but they do get used when included as part of the override_settings # pylint: disable=too-few-public-methods @@ -34,7 +33,7 @@ def _is_elastic(self): return isinstance(self.searcher, ElasticSearchEngine) def setUp(self): - super(MockSearchTests, self).setUp() + super().setUp() # ignore unexpected-keyword-arg; ES python client documents that it can be used # pylint: disable=unexpected-keyword-arg if self._is_elastic: @@ -61,7 +60,7 @@ def tearDown(self): MockSearchEngine.destroy() self._searcher = None - super(MockSearchTests, self).tearDown() + super().tearDown() def test_factory_creator(self): """ Make sure that search object implements SearchEngine interface """ @@ -296,7 +295,7 @@ def test_search_any(self): def test_extended_characters(self): """ Make sure that extended character searches work """ - test_string = u"قضايـا هامـة" + test_string = "قضايـا هامـة" self.searcher.index([{"content": {"name": test_string}}]) # search string diff --git a/search/tests/utils.py b/search/tests/utils.py index a8feb102..d8c5e074 100644 --- a/search/tests/utils.py +++ b/search/tests/utils.py @@ -52,11 +52,11 @@ class ForceRefreshElasticSearchEngine(ElasticSearchEngine): def index(self, sources, **kwargs): kwargs["refresh"] = True - super(ForceRefreshElasticSearchEngine, self).index(sources, **kwargs) + super().index(sources, **kwargs) def remove(self, doc_ids, **kwargs): kwargs["refresh"] = True - super(ForceRefreshElasticSearchEngine, self).remove(doc_ids, **kwargs) + super().remove(doc_ids, **kwargs) class ErroringSearchEngine(MockSearchEngine): diff --git a/search/urls.py b/search/urls.py index a3b49f68..7041b7b8 100644 --- a/search/urls.py +++ b/search/urls.py @@ -11,6 +11,6 @@ # pylint: disable=invalid-name urlpatterns = [ url(r'^$', views.do_search, name='do_search'), - url(r'^{}$'.format(COURSE_ID_PATTERN), views.do_search, name='do_search'), + url(fr'^{COURSE_ID_PATTERN}$', views.do_search, name='do_search'), url(r'^course_discovery/$', views.course_discovery, name='course_discovery'), ] diff --git a/setup.py b/setup.py index 2d0f26fe..40c24ec9 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def is_requirement(line): setup( name='edx-search', - version='2.0.1', + version='3.0.0', description='Search and index routines for index access', author='edX', author_email='oscm@edx.org', diff --git a/tox.ini b/tox.ini index d7c083bc..b6979f87 100644 --- a/tox.ini +++ b/tox.ini @@ -1,23 +1,24 @@ [tox] -envlist = py35-django22,py38-django{22,30},quality +envlist = py38-django{22,30,31},quality [testenv] -setenv = - DJANGO_SETTINGS_MODULE = edxsearch.settings - # This allows us to reference settings.py - PYTHONPATH = {toxinidir} -deps = - django22: Django>=2.2,<2.3 - django30: Django>=3.0,<3.1 - -r {toxinidir}/requirements/testing.txt -commands = - python -Wd -m coverage run manage.py test --settings=settings {posargs} - coverage report +setenv = + DJANGO_SETTINGS_MODULE = edxsearch.settings + PYTHONPATH = {toxinidir} +deps = + django22: Django>=2.2,<2.3 + django30: Django>=3.0,<3.1 + django31: Django>=3.1,<3.2 + -r {toxinidir}/requirements/testing.txt +commands = + python -Wd -m coverage run manage.py test --settings=settings {posargs} + coverage report [testenv:quality] -whitelist_externals = - make -deps = - -r{toxinidir}/requirements/quality.txt -commands = - make quality +whitelist_externals = + make +deps = + -r{toxinidir}/requirements/quality.txt +commands = + make quality + From 045a657299386a1b67e5718d7801834887959eb6 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 19 Jan 2021 20:50:50 +0500 Subject: [PATCH 2/2] Fixing url. --- search/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/urls.py b/search/urls.py index 7041b7b8..a3b49f68 100644 --- a/search/urls.py +++ b/search/urls.py @@ -11,6 +11,6 @@ # pylint: disable=invalid-name urlpatterns = [ url(r'^$', views.do_search, name='do_search'), - url(fr'^{COURSE_ID_PATTERN}$', views.do_search, name='do_search'), + url(r'^{}$'.format(COURSE_ID_PATTERN), views.do_search, name='do_search'), url(r'^course_discovery/$', views.course_discovery, name='course_discovery'), ]