Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zharktas py3 to qld gov au wip #4

Open
wants to merge 55 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a5f992e
Add travis templates
Zharktas Feb 26, 2020
8a071d4
fix line endings
Zharktas Feb 26, 2020
72cc26c
Add test configuration files
Zharktas Feb 26, 2020
5567a17
add empty requirements files
Zharktas Feb 26, 2020
0a08df1
add dev-requirements
Zharktas Feb 26, 2020
de0a5d9
add conftest.py
Zharktas Feb 26, 2020
b157901
Add test templates
Zharktas Feb 26, 2020
cd9d238
Fix import of OrderedDict
Zharktas Feb 26, 2020
926785e
Add blueprint and convert paste and pylons imports to toolkit
Zharktas Feb 27, 2020
20ca68a
Add compatiblity table
Zharktas Feb 27, 2020
691f2a3
Fix table syntax
Zharktas Feb 27, 2020
d0c9725
Add route tests
Zharktas Feb 27, 2020
fcb34ed
Check if plugin is already loaded
Zharktas Feb 27, 2020
1050779
Init nosetest classes
Zharktas Feb 27, 2020
1c467e2
fix parameter name
Zharktas Feb 27, 2020
3bbc640
Fix travis core setup
Zharktas Mar 5, 2020
fc9d1bf
Fix nose test
Zharktas Mar 5, 2020
fe49285
fix import
Zharktas Mar 5, 2020
1ff3c9b
Test assert
Zharktas Mar 5, 2020
56d888d
Add pylons/flask mixin
Zharktas Mar 5, 2020
a9a6cba
Fix syntax
Zharktas Mar 5, 2020
4d3413a
move rule inside the view
Zharktas Mar 5, 2020
c457caa
Fix typo
Zharktas Mar 5, 2020
70ccdbb
return blueprints
Zharktas Mar 5, 2020
d0e710f
remove extra parameters
Zharktas Mar 5, 2020
96052e6
Fix nav links
Zharktas Mar 5, 2020
fb7bff8
futurize stage1
Zharktas Mar 5, 2020
453cce2
Move common functions to lib
Zharktas Mar 5, 2020
7b31f77
fix imports
Zharktas Mar 5, 2020
3300665
Add named_route parameter
Zharktas Mar 23, 2020
bce783a
Add tagless_report to tests
Zharktas Mar 23, 2020
86adffd
Fix syntax
Zharktas Mar 23, 2020
5eaf420
Fix test
Zharktas Mar 23, 2020
d26745f
Fix import
Zharktas Mar 23, 2020
faee014
Fix report route
Zharktas Mar 23, 2020
5621b61
Fix pytest plugin configuration
Zharktas Mar 23, 2020
35def6c
futurize stage2
Zharktas Mar 23, 2020
2d7a417
initdb in travis
Zharktas Mar 23, 2020
99b592b
add future to requirements
Zharktas Mar 23, 2020
9f4ef87
Add initdb to new cli interface
Zharktas Mar 23, 2020
05ebddb
Add tagless report test
Zharktas Mar 23, 2020
f7e1180
Use flask in 2.9
Zharktas Mar 23, 2020
d1763b0
unicode
Zharktas Mar 23, 2020
4e50430
dont concat
Zharktas Mar 23, 2020
6d62ec3
fix typo
Zharktas Mar 23, 2020
d94a216
Revert "fix typo"
Zharktas Mar 23, 2020
409f22c
use assert_in
Zharktas Mar 23, 2020
22a11b8
use correct dataset name
Zharktas Mar 23, 2020
0992665
import config from pylons in ckan 2.5
Zharktas Mar 23, 2020
47efda6
Modernize travis
Zharktas Apr 25, 2020
6abc1a4
add github actions to py3 branch of Zharktas
duttonw Feb 12, 2021
8d96bf6
add pytest ckan_setup and fixtures patch so 2.8 and 2.9 work without …
duttonw Feb 12, 2021
41cd318
remove nost tests
duttonw Feb 12, 2021
0b874da
[QOL-7906] clean up
ThrawnCA Apr 8, 2021
00d3d0c
[QOL-7906] replace 'builtins' with 'six'
ThrawnCA Jun 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[flake8]
# @see https://flake8.pycqa.org/en/latest/user/configuration.html?highlight=.flake8

exclude =
ckan
scripts

# Extended output format.
format = pylint

# Show the source of errors.
show_source = True

max-complexity = 10
max-line-length = 127

# List ignore rules one per line.
ignore =
C901
W503
97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
#based on https://raw.githubusercontent.com/ckan/ckanext-scheming/master/.github/workflows/test.yml
# alternative https://github.com/ckan/ckan/blob/master/contrib/cookiecutter/ckan_extension/%7B%7Bcookiecutter.project%7D%7D/.github/workflows/test.yml
name: Tests
on: [push, pull_request]
env:
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
CKAN_SOLR_URL: http://solr:8983/solr/ckan
CKAN_REDIS_URL: redis://redis:6379/1

jobs:
lint:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.6'
- name: Cache pip
uses: actions/cache@v2
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-flake8-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-flake8-
${{ runner.os }}-
- name: Install requirements
run: pip install flake8 pycodestyle
- name: Check syntax
run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics --exclude ckan

test:
needs: lint
strategy:
matrix:
ckan-version: [2.8, 2.9-py2, 2.9]
fail-fast: false

name: CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-18.04
container:
image: openknowledge/ckan-dev:${{ matrix.ckan-version }}
services:
solr:
image: ckan/ckan-solr-dev:${{ matrix.ckan-version }}
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:3
# env: ${{ matrix.env }}

steps:
- uses: actions/checkout@v2

- name: Cache pip
uses: actions/cache@v2
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('*requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-

- name: Install requirements
run: |
pip install -r dev-requirements.txt
# pip install -r pip-requirements.txt
pip install -r requirements.txt
pip install -e .
# Replace default path to CKAN core config file with the one on the container
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini

- name: Setup extension (CKAN >= 2.9)
if: ${{ matrix.ckan-version != '2.7' && matrix.ckan-version != '2.8' }}
run: |
ckan -c test.ini db init
ckan -c test.ini report initdb
- name: Setup extension (CKAN < 2.9)
if: ${{ matrix.ckan-version == '2.7' || matrix.ckan-version == '2.8' }}
run: |
paster --plugin=ckan db init -c test.ini
paster report initdb -c test.ini

- name: Run all tests
run: |
pytest --ckan-ini=test.ini --cov=ckanext.report ckanext/report/tests
49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
dist: bionic

language: python

install:
- bash bin/travis-build.bash
services:
- redis
- postgresql

script: bash bin/travis-run.bash
before_install:
- pip install codecov
after_success:
- codecov

jobs:
include:
- stage: Flake8
python: 2.7
env: FLAKE8=True
install:
- pip install flake8==3.5.0
- pip install pycodestyle==2.3.0
script:
- flake8 --version
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics --exclude ckan
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --max-line-length=127 --statistics --exclude ckan --exit-zero
- stage: Tests
python: "2.7"
env: CKANVERSION=master
- python: "3.6"
env: CKANVERSION=master
- python: "2.7"
env: CKANVERSION=2.8
- python: "2.7"
env: CKANVERSION=2.7
- python: "2.7"
env: CKANVERSION=2.6
- python: "2.7"
env: CKANVERSION=2.5
- python: "2.7"
env: CKANVERSION=2.4

cache:
directories:
- $HOME/.cache/pip
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ TODO:

Compatibility: Requires CKAN version 2.1 or later (but can be easily adapted for older versions).


| CKAN version | Compatibility |
| --------------- | ------------------- |
| 2.6 and earlier | yes |
| 2.7 | yes |
| 2.8 | yes |
| 2.9 | no - needs updating |


Status: in production at data.gov.uk but since that uses its own CSS rather than core CKAN's, for others to use it CSS needs adding. For an example, see this branch: see https://github.com/yaditi/ckanext-report/tree/geoversion

Author(s): David Read
Expand Down
122 changes: 122 additions & 0 deletions bin/travis-build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash
set -e

echo "This is travis-build.bash..."
echo "Targetting CKAN $CKANVERSION on Python $TRAVIS_PYTHON_VERSION"
if [ $CKANVERSION == 'master' ]
then
export CKAN_MINOR_VERSION=100
else
export CKAN_MINOR_VERSION=${CKANVERSION##*.}
fi

export PYTHON_MAJOR_VERSION=${TRAVIS_PYTHON_VERSION%.*}


echo "Installing the packages that CKAN requires..."
sudo apt-get update -qq
sudo apt-get install solr-jetty

echo "Installing CKAN and its Python dependencies..."
git clone https://github.com/ckan/ckan
cd ckan
if [ $CKANVERSION == 'master' ]
then
echo "CKAN version: master"
else
CKAN_TAG=$(git tag | grep ^ckan-$CKANVERSION | sort --version-sort | tail -n 1)
git checkout $CKAN_TAG
echo "CKAN version: ${CKAN_TAG#ckan-}"
fi


# install the recommended version of setuptools
if [ -f requirement-setuptools.txt ]
then
echo "Updating setuptools..."
pip install -r requirement-setuptools.txt
fi

python setup.py develop

if [ $CKANVERSION == '2.7' ]
then
echo "Installing setuptools"
pip install setuptools==39.0.1
fi

if (( $CKAN_MINOR_VERSION >= 9 )) && (( $PYTHON_MAJOR_VERSION == 2 ))
then
pip install -r requirements-py2.txt
else
if (( $CKAN_MINOR_VERSION <= 7 ))
then
sed -i -r 's/psycopg2==.*//g' requirements.txt
fi
pip install -r requirements.txt
fi

# Override psycopg version to avoid problems with Travis and Postgres 10
if (( $CKAN_MINOR_VERSION <= 7 ))
then
pip install --upgrade psycopg2==2.7.7
fi

pip install -r dev-requirements.txt
cd -

echo "Setting up Solr..."
# solr is multicore for tests on ckan master now, but it's easier to run tests
# on Travis single-core still.
# see https://github.com/ckan/ckan/issues/2972
sed -i -e 's/solr_url.*/solr_url = http:\/\/127.0.0.1:8983\/solr/' ckan/test-core.ini

# Fix solr-jetty starting issues https://stackoverflow.com/a/56007895
sudo mkdir /etc/systemd/system/jetty9.service.d
printf "[Service]\nReadWritePaths=/var/lib/solr" | sudo tee /etc/systemd/system/jetty9.service.d/solr.conf
sed '16,21d' /etc/solr/solr-jetty.xml | sudo tee /etc/solr/solr-jetty.xml
sudo systemctl daemon-reload

printf "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_ARGS=\"jetty.http.port=8983\"\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty9
sudo cp ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml
sudo service jetty9 restart

# Wait for jetty9 to start
timeout 20 bash -c 'while [[ "$(curl -s -o /dev/null -I -w %{http_code} http://localhost:8983)" != "200" ]]; do sleep 2;done'

echo "Creating the PostgreSQL user and database..."
sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';"
sudo -u postgres psql -c 'CREATE DATABASE ckan_test WITH OWNER ckan_default;'

echo "Initialising the database..."
cd ckan


if (( $CKAN_MINOR_VERSION >= 9 ))
then
ckan -c test-core.ini db init
else
paster db init -c test-core.ini
fi
cd -

echo "Installing ckanext-report and its requirements..."
pip install -r requirements.txt
pip install -r dev-requirements.txt
python setup.py develop


echo "Moving test.ini into a subdir..."
mkdir subdir
mv test.ini subdir


if (( $CKAN_MINOR_VERSION >= 9 ))
then
ckan -c subdir/test.ini report initdb
else
paster report initdb -c subdir/test.ini
fi


echo "travis-build.bash is done."
17 changes: 17 additions & 0 deletions bin/travis-run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

if [ $CKANVERSION == 'master' ]
then
export CKAN_MINOR_VERSION=100
else
export CKAN_MINOR_VERSION=${CKANVERSION##*.}
fi


#if (( $CKAN_MINOR_VERSION >= 9 ))
#then
pytest --ckan-ini=subdir/test.ini --cov=ckanext.report ckanext/report/tests
#else
# nosetests --ckan --nologcapture --with-pylons=subdir/test-nose.ini --with-coverage --cover-package=ckanext.report --cover-inclusive --cover-erase --cover-tests ckanext/report/tests/nose
#fi
Loading