-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Logout22/master
Add CI for volunteers page
- Loading branch information
Showing
17 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[run] | ||
branch = True | ||
source = volunteers/ | ||
|
||
[report] | ||
exclude_lines = | ||
if self.debug: | ||
pragma: no cover | ||
raise NotImplementedError | ||
if __name__ == .__main__.: | ||
ignore_errors = True | ||
omit = | ||
volunteers/tests.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: [push] | ||
|
||
jobs: | ||
test_job: | ||
runs-on: ubuntu-latest | ||
env: | ||
OS: ubuntu-latest | ||
PYTHON: '3.7' | ||
name: Linting and Testing | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Test action step | ||
uses: ./ | ||
id: test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
files: ./coverage.xml | ||
flags: unittests | ||
env_vars: OS,PYTHON | ||
name: codecov-umbrella | ||
fail_ci_if_error: true | ||
path_to_write_report: ./coverage/codecov_report.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,9 @@ secret.txt | |
|
||
logs | ||
static/* | ||
|
||
public/ | ||
penta.db | ||
volunteers.db | ||
.coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: 'Test' | ||
description: 'Linting and Testing' | ||
runs: | ||
using: 'docker' | ||
image: 'ci/Dockerfile' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.7-bullseye | ||
|
||
RUN apt-get update -y && \ | ||
DEBIAN_FRONTEND="noninteractive" apt-get install -y sqlite3 | ||
|
||
COPY ./entrypoint.sh ./ | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
utils/create-venv.sh | ||
utils/install-dependencies.sh | ||
utils/setup-file-system.sh | ||
utils/setup-server.sh | ||
utils/run-linter.sh | ||
utils/run-tests.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
arabic-reshaper==2.1.1 | ||
astroid==2.5.6 | ||
coverage==5.5 | ||
dj-static==0.0.6 | ||
Django==2.2.18 | ||
django-guardian==2.3.0 | ||
django-userena-ce==6.0.1 | ||
easy-thumbnails==2.5 | ||
future==0.18.2 | ||
gunicorn==20.0.4 | ||
html2text==2014.12.29 | ||
html5lib==1.1 | ||
isort==5.8.0 | ||
lazy-object-proxy==1.6.0 | ||
mccabe==0.6.1 | ||
Pillow==8.1.0 | ||
psycopg2-binary==2.8.6 | ||
pylint==2.8.2 | ||
pylint-django==2.4.4 | ||
pylint-plugin-utils==0.6 | ||
PyPDF2==1.26.0 | ||
python-bidi==0.4.2 | ||
python-dateutil==2.8.1 | ||
pytz==2021.1 | ||
reportlab==3.5.59 | ||
six==1.15.0 | ||
sqlparse==0.4.1 | ||
static3==0.7.0 | ||
toml==0.10.2 | ||
typed-ast==1.4.3 | ||
vobject==0.9.6.1 | ||
webencodings==0.5.1 | ||
wrapt==1.12.1 | ||
xhtml2pdf==0.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
python3 -m venv venv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
pip install -r requirements-dev.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
show_help() { | ||
cat <<EOM | ||
Invocation: | ||
$0 [-h|-?] [-s] [-u USER] [-e EXECUTABLE] [--] [ARGS...] | ||
Options: | ||
-h|-? : Display this help text | ||
-s : Elevate this script to run Docker as root | ||
(default: false) | ||
-u USER : User parameter to pass on to docker run | ||
(default: current UID / GID) | ||
-e EXECUTABLE : Entrypoint to pass on to docker run | ||
(default: none) | ||
ARGS : Arguments for the dockerized process | ||
EOM | ||
} | ||
|
||
##### Option parsing ##### | ||
AS_ROOT=false | ||
USER=$(id -u):$(id -g) | ||
ENTRYPOINT= | ||
|
||
while getopts "h?su:e:" opt; do | ||
case "$opt" in | ||
h|\?) | ||
show_help | ||
exit 0 | ||
;; | ||
s) AS_ROOT=true | ||
;; | ||
u) USER=$OPTARG | ||
;; | ||
e) ENTRYPOINT=$OPTARG | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)) | ||
|
||
if [[ "${1:-}" = "--" ]]; then | ||
shift | ||
fi | ||
|
||
##### Elevate script ##### | ||
if [[ $AS_ROOT = true && $UID -ne 0 ]]; then | ||
sudo "$0" -u "$USER" -e "$ENTRYPOINT" "$@" | ||
exit | ||
fi | ||
|
||
##### Build container ##### | ||
CONTAINER_NAME=volunteers-test | ||
docker build --pull -t "$CONTAINER_NAME" ci | ||
|
||
##### Run container ##### | ||
ADDITIONAL_ARGS= | ||
EXEC_ARGS= | ||
if [[ -n "$ENTRYPOINT" ]]; then | ||
ADDITIONAL_ARGS="--entrypoint $ENTRYPOINT" | ||
fi | ||
if [[ $# -gt 0 ]]; then | ||
EXEC_ARGS="$*" | ||
fi | ||
docker run \ | ||
-v "$PWD:$PWD" \ | ||
--rm \ | ||
--name "$CONTAINER_NAME" \ | ||
--workdir "$PWD" \ | ||
--user "$USER" \ | ||
$ADDITIONAL_ARGS \ | ||
"$CONTAINER_NAME" \ | ||
$EXEC_ARGS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
echo " ##### Run linter #####" | ||
DJANGO_SETTINGS_MODULE=volunteer_mgmt.settings pylint --load-plugins pylint_django --fail-under=7 volunteers/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
. venv/bin/activate | ||
echo " ##### Run test #####" | ||
coverage run manage.py test | ||
coverage xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
mkdir -p logs tool/media/mugshots | ||
sqlite3 volunteers.db | ||
sqlite3 penta.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
set -o errexit | ||
set -o nounset | ||
|
||
sed "\ | ||
s/backends.postgresql_psycopg2/backends.sqlite3/; \ | ||
s/'NAME': '\([a-z]\+\)'/'NAME': '\1.db'/; \ | ||
" \ | ||
volunteer_mgmt/localsettings_example.py \ | ||
> volunteer_mgmt/localsettings.py | ||
|
||
. venv/bin/activate | ||
./manage.py migrate | ||
./manage.py collectstatic | ||
./manage.py createsuperuser --noinput --username test --email [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
Tests to be run via "manage.py test" | ||
""" | ||
|
||
from unittest.mock import patch | ||
from django.test import TestCase | ||
from volunteers.views import promo | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) | ||
class PromoTestCase(TestCase): | ||
@patch('volunteers.views.render') | ||
def test_promo_view_renders_static_page(self, render_mock): | ||
static_promo_page_content = 'Some promo page' | ||
render_mock.return_value = static_promo_page_content | ||
ret = promo(None) | ||
self.assertEqual(ret, static_promo_page_content) |