From 659c786736ea3d3a4d2028f65df165895c238ef1 Mon Sep 17 00:00:00 2001 From: Mohammad Ahtasham ul Hassan Date: Thu, 30 Dec 2021 14:54:30 +0500 Subject: [PATCH] fix: fix ci workflow to run tests --- .github/workflows/bok-choy-tests.yml | 54 ++++++++++++++++++++++++++++ .github/workflows/ci.yml | 49 ++++++++++++++----------- .github/workflows/js-tests.yml | 29 +++++++++++++++ .gitignore | 2 ++ Makefile | 6 ++-- requirements/constraints.txt | 12 +++++++ requirements/pip.in | 5 +++ requirements/pip.txt | 14 ++++++++ requirements/pip_tools.in | 4 +++ requirements/pip_tools.txt | 20 +++++++++++ testserver/settings.py | 23 ++++++++++-- 11 files changed, 193 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/bok-choy-tests.yml create mode 100644 .github/workflows/js-tests.yml create mode 100644 requirements/constraints.txt create mode 100644 requirements/pip.in create mode 100644 requirements/pip.txt create mode 100644 requirements/pip_tools.in create mode 100644 requirements/pip_tools.txt diff --git a/.github/workflows/bok-choy-tests.yml b/.github/workflows/bok-choy-tests.yml new file mode 100644 index 00000000..06e21d3f --- /dev/null +++ b/.github/workflows/bok-choy-tests.yml @@ -0,0 +1,54 @@ +name: Bok Choy Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + run_tests: + name: Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + python-version: [3.8] + + steps: + - uses: actions/checkout@v2 + - name: setup python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Set display to virtual frame buffer + run: export DISPLAY=:99.0 + + - name: Set up test environment + run: | + sudo apt-get update + sudo apt-get install xvfb gettext + wget https://github.com/mozilla/geckodriver/releases/download/v0.25.0/geckodriver-v0.25.0-linux64.tar.gz + mkdir geckodriver + tar -xzf geckodriver-v0.25.0-linux64.tar.gz -C geckodriver + export PATH=$PATH:$PWD/geckodriver + export BOKCHOY_HEADLESS=true + + - name: Install dependencies + run: | + pip install -r requirements/base.txt + pip install -r requirements/testing.txt + + - name: Install Firefox 61.0 + run: | + sudo apt-get purge firefox + wget "https://ftp.mozilla.org/pub/firefox/releases/46.0/linux-x86_64/en-US/firefox-46.0.tar.bz2" + tar -xjf firefox-46.0.tar.bz2 + sudo mv firefox /opt/firefox + sudo ln -s /opt/firefox/firefox /usr/bin/firefox + + - name: Run Acceptance tests + run: xvfb-run --server-args=-ac -- make test-bokchoy + env: + BOKCHOY_HEADLESS: true \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2115479c..9fe1eca1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,6 @@ on: branches: - master pull_request: - branches: - - '**' jobs: run_tests: @@ -14,14 +12,12 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: - - ubuntu-20.04 - python-version: - - 3.8 - toxenv: [ django22,quality ] + os: [ubuntu-20.04] + python-version: [3.8] + toxenv: [ django22, quality ] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: setup python uses: actions/setup-python@v2 with: @@ -30,29 +26,42 @@ jobs: - name: Set display to virtual frame buffer run: export DISPLAY=:99.0 - - - - name: Install npm dependencies - run: npm install + - name: Set up test environment + run: | + sudo apt-get update + sudo apt-get install xvfb gettext + wget https://github.com/mozilla/geckodriver/releases/download/v0.25.0/geckodriver-v0.25.0-linux64.tar.gz + mkdir geckodriver + tar -xzf geckodriver-v0.25.0-linux64.tar.gz -C geckodriver + export PATH=$PATH:$PWD/geckodriver + export BOKCHOY_HEADLESS=true - name: Install dependencies run: | pip install -r requirements/base.txt pip install -r requirements/testing.txt - - name: Run Python and Quality Tests + - name: Install Firefox 61.0 + run: | + sudo apt-get purge firefox + wget "https://ftp.mozilla.org/pub/firefox/releases/46.0/linux-x86_64/en-US/firefox-46.0.tar.bz2" + tar -xjf firefox-46.0.tar.bz2 + sudo mv firefox /opt/firefox + sudo ln -s /opt/firefox/firefox /usr/bin/firefox + + - name: Run Pytest + if: matrix.python-version == '3.8' && matrix.toxenv=='django22' + run: make test-python + + - name: Run Quality Tests + if: matrix.python-version == '3.8' && matrix.toxenv=='quality' env: TOXENV: ${{ matrix.toxenv }} run: tox - - name: Run Js/Bokchoy tests - uses: browser-actions/setup-firefox@latest - with: - firefox-version: '46.0' - run: make test - - name: Run Coverage - if: matrix.python-version == '3.8' && matrix.toxenv=='django22' + if: matrix.python-version == '3.8' && matrix.toxenv=='quality' uses: codecov/codecov-action@v2 with: fail_ci_if_error: true + diff --git a/.github/workflows/js-tests.yml b/.github/workflows/js-tests.yml new file mode 100644 index 00000000..ff495eed --- /dev/null +++ b/.github/workflows/js-tests.yml @@ -0,0 +1,29 @@ +name: Node CI + +on: + push: + branches: + - master + pull_request: + +jobs: + run_tests: + name: Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + + steps: + - uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Install npm dependencies + run: npm install + + - name: Run Js tests + run: make test-js diff --git a/.gitignore b/.gitignore index 94690b8c..08ed94f0 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ acceptance_tests/*.png node_modules/ testserver/local_settings.py + +venv diff --git a/Makefile b/Makefile index 8a7de14d..dfe9a0f7 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,9 @@ clean: ## delete generated byte code and coverage reports upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in - pip install -q pip-tools + pip install -q -r requirements/pip_tools.txt + pip-compile --rebuild --upgrade --allow-unsafe -o requirements/pip.txt requirements/pip.in + pip-compile --upgrade -o requirements/pip_tools.txt requirements/pip_tools.in pip-compile --upgrade -o requirements/base.txt requirements/base.in pip-compile --upgrade -o requirements/testing.txt requirements/testing.in # Let tox control the Django version for tests @@ -45,7 +47,7 @@ test-js: ## run tests using npm -./node_modules/gulp/bin/gulp.js test test-python: clean ## run tests using pytest and generate coverage report - $(TOX)pytest + $(TOX)pytest --ignore=testserver/test/acceptance test-bokchoy: ## run tests using bokchoy bash ./run_bokchoy_tests.sh diff --git a/requirements/constraints.txt b/requirements/constraints.txt new file mode 100644 index 00000000..f9ea41a8 --- /dev/null +++ b/requirements/constraints.txt @@ -0,0 +1,12 @@ +# Version constraints for pip-installation. +# +# This file doesn't install any packages. It specifies version constraints +# that will be applied if a package is needed. +# +# When pinning something here, please provide an explanation of why. Ideally, +# link to other information that will help people in the future to remove the +# 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 diff --git a/requirements/pip.in b/requirements/pip.in new file mode 100644 index 00000000..21ce8e9d --- /dev/null +++ b/requirements/pip.in @@ -0,0 +1,5 @@ +# Core dependencies for installing other packages + +pip +setuptools +wheel diff --git a/requirements/pip.txt b/requirements/pip.txt new file mode 100644 index 00000000..e7b6273d --- /dev/null +++ b/requirements/pip.txt @@ -0,0 +1,14 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# make upgrade +# +wheel==0.37.1 + # via -r requirements/pip.in + +# The following packages are considered to be unsafe in a requirements file: +pip==21.3.1 + # via -r requirements/pip.in +setuptools==60.2.0 + # via -r requirements/pip.in diff --git a/requirements/pip_tools.in b/requirements/pip_tools.in new file mode 100644 index 00000000..caf45a91 --- /dev/null +++ b/requirements/pip_tools.in @@ -0,0 +1,4 @@ + # Dependencies to run compile tools +-c constraints.txt + +pip-tools # Contains pip-compile, used to generate pip requirements files diff --git a/requirements/pip_tools.txt b/requirements/pip_tools.txt new file mode 100644 index 00000000..18e0bc78 --- /dev/null +++ b/requirements/pip_tools.txt @@ -0,0 +1,20 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# make upgrade +# +click==8.0.3 + # via pip-tools +pep517==0.12.0 + # via pip-tools +pip-tools==6.4.0 + # via -r requirements/pip_tools.in +tomli==2.0.0 + # via pep517 +wheel==0.37.1 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/testserver/settings.py b/testserver/settings.py index 114f4062..fe9c3694 100644 --- a/testserver/settings.py +++ b/testserver/settings.py @@ -85,7 +85,7 @@ 'rest_framework.throttling.UserRateThrottle', ), 'DEFAULT_THROTTLE_RATES': { - 'user': '10/sec', + 'user': '100/sec', } } @@ -175,7 +175,9 @@ # msg type 'open-edx.edx_notifications.lib.tests.test_publisher' # to /path/to/{param1}/url/{param2} with param subsitutations # that are passed in with the message - 'testserver.*': '/resolved_path/{param1}/url/{param2}', + 'open-edx.edx_notifications.lib.tests.test_publisher': '/path/to/{param1}/url/{param2}', + 'open-edx.edx_notifications.lib.tests.*': '/alternate/path/to/{param1}/url/{param2}', + 'open-edx-edx_notifications.lib.*': '/third/way/to/get/to/{param1}/url/{param2}', } # list all known channel providers @@ -217,7 +219,18 @@ 'null': { 'class': 'edx_notifications.channels.null.NullNotificationChannel', 'options': {} - } + }, + 'parse-push': { + 'class': 'edx_notifications.channels.parse_push.ParsePushNotificationChannelProvider', + 'options': { + 'application_id': 'test_id', + 'rest_api_key': 'test_rest_api_key', + } + }, + 'urban-airship': { + 'class': 'edx_notifications.channels.urban_airship.UrbanAirshipNotificationChannelProvider', + 'options': {} + }, } TEMPLATE_CONTEXT_PROCESSORS = ( @@ -259,6 +272,10 @@ NOTIFICATION_SITE_NAME = "http://localhost:8000/" +# Constants to set how long (in days) old READ and UNREAD notifications can remain in the system before being purged. +NOTIFICATION_PURGE_READ_OLDER_THAN_DAYS = 30 +NOTIFICATION_PURGE_UNREAD_OLDER_THAN_DAYS = 60 + try: from local_settings import * except Exception: