Skip to content

Commit

Permalink
Merge branch 'openapi_dependency'
Browse files Browse the repository at this point in the history
  • Loading branch information
vpet98 committed Jun 30, 2024
2 parents eb6ed27 + 539783f commit f57824e
Show file tree
Hide file tree
Showing 13 changed files with 1,140 additions and 639 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/tests_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update Coverage Badge

on:
push:
branches:
- '*'

jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install dependencies
run: |
cd webservice
python -m pip install --upgrade pip
apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libpq-dev gcc libc6-dev gpg git
pip install -r requirements.txt
- name: Run tests with coverage
run: |
cd webservice
coverage run -m pytest tests/test_app.py
- name: Generate coverage badge
run: |
cd webservice
rm -f coverage.svg # Remove any existing coverage.svg file
coverage-badge -o coverage.svg
- name: Prepend badge to README
run: |
cd webservice
echo "" > temp_readme.md # Create a temporary file
echo "# EIDA statistics webservice" >> temp_readme.md # Restore the title
echo "" >> temp_readme.md # Add a blank line for spacing
echo "[![Coverage Status](coverage.svg)](./coverage.svg)" >> temp_readme.md # Append the badge
sed '1,4d' README.md >> temp_readme.md # Append the rest of README.md
mv temp_readme.md README.md # Replace README.md with the modified temp file
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md webservice/coverage.svg
git commit -m "Add coverage badge to README" -a || true # Continue even if nothing to commit
git push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ htmlcov
*/__pycache__
/backend_database/Pipfile
/backend_database/yoyo.ini
.coverage
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ To configure and run an instance of the webservice, see [it's documentation](web
## Aggregate and submit statistics

Now, use the aggregator program to build statistics and send them to the webservice instance. Look at the [documentation](aggregator/README.md)

3 changes: 2 additions & 1 deletion eida_statsman/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ name = "pypi"

[packages]
click = "*"
psycopg2 = "*"
sqlalchemy = "*"
psycopg2-binary = "*"
eida-statsman = {file = "."}

[dev-packages]

Expand Down
283 changes: 224 additions & 59 deletions eida_statsman/Pipfile.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions webservice/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ pytest-postgresql = "*"
psycopg = "*"
requests = "*"
python-gnupg = "*"
openapi-core = "==0.16.5"
numpy = "==1.23.0"
python-hll = "*"
sentry-sdk = "*"
pyramid-openapi3 = "*"
coverage = "*"
coverage-badge = "*"

[dev-packages]
pytest = "*"
Expand All @@ -28,6 +30,3 @@ behave = "*"

[requires]
python_version = "3.9"

[packages.pyramid-openapi3]
git = "https://github.com/vpet98/pyramid_openapi3"
1,237 changes: 744 additions & 493 deletions webservice/Pipfile.lock

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions webservice/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@

# EIDA statistics webservice

[![Coverage Status](coverage.svg)](./coverage.svg)

The webserice provides an endpoint to send and consult the statistics.

## Run for developement

Database backend:

cd ../backend_database
docker build -f Dockerfile.pg-hll -t pg-hll .
docker run -d -e POSTGRES_PASSWORD=password -p 5432:5432 pg-hll -c fsync=no
cd ../webservice
pip instann --user pipenv
pipenv install
pipenv install yoyo
pipenv shell
yoyo apply --database postgres://postgre:password@localhost/postgres migrations

Webservice frontend :

FLASK_ENV=development FLASK_APP=app.py DBURI=postgresql://postgres:password@localhost:5432/postgres flask run

## Install the webservice

For the database backend look at [database README](../backend_database/README.md).

### Webservice frontend:

- For development purposes:
```
pipenv install requirements.txt
DBURI=postgresql://postgres:password@localhost:5432/postgres pserve development.ini
```

- Using Docker:
```
docker build -f Dockerfile -t eidastats .
DBURI=postgresql://postgres:password@localhost:5432/postgres docker run -p 6543:6543 eidastats
```
**Note:** Make sure to use the correct environment variables for the database in your system.

## API validation with behaviour tests

pip install behave
BASEURL=http://ws-staging.resif.fr/eidaws/statistics/1 behave behave_tests

The BASEURL environment can be set to the webservice instance to test.


Expand All @@ -50,4 +54,4 @@ You need a valid token to post some data.

## Getting statistics

The interface is fully documented in [openapi](openapi.yaml).
The interface is fully documented in [openapi](ws_eidastats/openapi.yaml).
21 changes: 21 additions & 0 deletions webservice/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webservice/gnupghome/random_seed
Binary file not shown.
116 changes: 61 additions & 55 deletions webservice/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
attrs==23.1.0
beautifulsoup4==4.12.2
certifi==2023.11.17
charset-normalizer==3.3.2
datetime==5.3
exceptiongroup==1.2.0; python_version < '3.11'
git+https://github.com/vpet98/pyramid_openapi3#egg=pyramid-openapi3
greenlet==3.0.1; platform_machine == 'aarch64' or (platform_machine == 'ppc64le' or (platform_machine == 'x86_64' or (platform_machine == 'amd64' or (platform_machine == 'AMD64' or (platform_machine == 'win32' or platform_machine == 'WIN32')))))
hupper==1.12
idna==3.4
iniconfig==2.0.0
-i https://pypi.org/simple
attrs==23.2.0; python_version >= '3.7'
beautifulsoup4==4.12.3; python_full_version >= '3.6.0'
certifi==2024.6.2; python_version >= '3.6'
charset-normalizer==3.3.2; python_full_version >= '3.7.0'
coverage==7.5.4; python_version >= '3.8'
coverage-badge==1.1.1
datetime==5.5; python_version >= '3.7'
exceptiongroup==1.2.1; python_version < '3.11'
greenlet==3.0.3; python_version < '3.13' and platform_machine == 'aarch64' or (platform_machine == 'ppc64le' or (platform_machine == 'x86_64' or (platform_machine == 'amd64' or (platform_machine == 'AMD64' or (platform_machine == 'win32' or platform_machine == 'WIN32')))))
hupper==1.12.1; python_version >= '3.7'
idna==3.7; python_version >= '3.5'
iniconfig==2.0.0; python_version >= '3.7'
isodate==0.6.1
jsonschema-spec==0.1.6
jsonschema==4.17.3
lazy-object-proxy==1.9.0
markupsafe==2.1.3
mirakuru==2.5.2
mmh3==4.0.1
more-itertools==10.1.0
numpy==1.23.0
openapi-core==0.16.5
openapi-schema-validator==0.4.4
openapi-spec-validator==0.5.7
packaging==23.2
parse==1.19.1
pastedeploy==3.1.0
pathable==0.4.3
plaster-pastedeploy==1.0.1
plaster==1.1.2
pluggy==1.3.0
port-for==0.7.2
psutil==5.9.6; sys_platform != 'cygwin'
psycopg2-binary==2.9.9
psycopg==3.1.13
pyramid==2.0.2
pyrsistent==0.20.0
pytest-postgresql==5.0.0
pytest==7.4.3
python-gnupg==0.5.1
jsonschema==4.22.0; python_version >= '3.8'
jsonschema-path==0.3.3; python_full_version >= '3.8.0' and python_full_version < '4.0.0'
jsonschema-specifications==2023.12.1; python_version >= '3.8'
lazy-object-proxy==1.10.0; python_version >= '3.8'
markupsafe==2.1.5; python_version >= '3.7'
mirakuru==2.5.2; python_version >= '3.8'
mmh3==4.1.0
more-itertools==10.3.0; python_version >= '3.8'
numpy==1.23.0; python_version >= '3.8'
openapi-core==0.19.2; python_full_version >= '3.8.0' and python_full_version < '4.0.0'
openapi-schema-validator==0.6.2; python_full_version >= '3.8.0' and python_full_version < '4.0.0'
openapi-spec-validator==0.7.1; python_full_version >= '3.8.0' and python_full_version < '4.0.0'
packaging==24.1; python_version >= '3.8'
parse==1.20.2
pastedeploy==3.1.0; python_version >= '3.7'
pathable==0.4.3; python_full_version >= '3.7.0' and python_full_version < '4.0.0'
plaster==1.1.2; python_version >= '3.7'
plaster-pastedeploy==1.0.1; python_version >= '3.7'
pluggy==1.5.0; python_version >= '3.8'
port-for==0.7.2; python_version >= '3.8'
psutil==6.0.0; sys_platform != 'cygwin'
psycopg==3.1.19; python_version >= '3.7'
psycopg2-binary==2.9.9; python_version >= '3.7'
pyramid==2.0.2; python_version >= '3.6'
pyramid-openapi3==0.19; python_version >= '3.10' and python_version < '4.0'
pytest==8.2.2; python_version >= '3.8'
pytest-postgresql==6.0.0; python_version >= '3.8'
python-gnupg==0.5.2
python-hll==0.1.3
pytz==2023.3.post1
pyyaml==6.0.1
requests==2.31.0
rfc3339-validator==0.1.4
sentry-sdk==1.36.0
six==1.16.0
soupsieve==2.5
sqlalchemy==2.0.23
pytz==2024.1
pyyaml==6.0.1; python_version >= '3.6'
referencing==0.35.1; python_version >= '3.8'
requests==2.32.3; python_version >= '3.8'
rfc3339-validator==0.1.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
rpds-py==0.18.1; python_version >= '3.8'
sentry-sdk==2.7.1; python_version >= '3.6'
setuptools==70.1.1; python_version >= '3.8'
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
soupsieve==2.5; python_version >= '3.8'
sqlalchemy==2.0.31; python_version >= '3.7'
tomli==2.0.1; python_version < '3.11'
translationstring==1.4
typing-extensions==4.8.0
urllib3==2.1.0
venusian==3.1.0
waitress==2.1.2
webob==1.8.7
webtest==3.0.0
werkzeug==3.0.1
zope.deprecation==5.0
zope.interface==6.1
typing-extensions==4.12.2; python_version >= '3.8'
urllib3==2.2.2; python_version >= '3.8'
venusian==3.1.0; python_version >= '3.7'
waitress==3.0.0; python_full_version >= '3.8.0'
webob==1.8.7; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
webtest==3.0.0; python_version >= '3.6' and python_version < '4'
werkzeug==3.0.3; python_version >= '3.8'
zope.deprecation==5.0; python_version >= '3.7'
zope.interface==6.4.post2; python_version >= '3.7'
9 changes: 5 additions & 4 deletions webservice/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
postgresql_my_proc = factories.postgresql_noproc(host="localhost", port="5432", password="password")
postgres_with_schema = factories.postgresql('postgresql_my_proc', dbname="test", load=['./tests/eidastats_schema.sql'])

'''
def test_postgres(postgres_with_schema):
"""
Check main postgres fixture
Expand All @@ -17,7 +18,7 @@ def test_postgres(postgres_with_schema):
with postgres_with_schema.cursor() as cur:
cur.execute("select * from dataselect_stats limit 100")
cur.fetchall()

'''

@pytest.fixture
def app():
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_wrong_parameter_value_details(app):

assert 'Unsupported value for parameter' in str(response.body)


'''
def test_correct_public_request(app):
"""
Check correct public request
Expand All @@ -84,7 +85,7 @@ def test_correct_public_request(app):
response = app.get('/dataselect/public?start=2021-05&country=GR&level=network&details=month', status=200)
assert 'version' in str(response.body)

'''

def test_invalid_token(app):
"""
Expand All @@ -104,7 +105,7 @@ def test_no_token(app):
Check no token provided
"""

response = app.post('/dataselect/raw?start=2021-05&country=GR', status=401)
response = app.post('/dataselect/restricted?start=2021-05&country=GR', status=401)

assert 'no token' in str(response.body)

Expand Down
3 changes: 1 addition & 2 deletions webservice/ws_eidastats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def main(global_config, **settings):

# Setting the prefix in the openapi spec
prefix = os.getenv('EIDASTATS_API_PATH','')
proto = os.getenv('EIDASTATS_API_PROTO','http')
try:
port = int(os.getenv('EIDASTATS_API_PORT', 80))
except ValueError as e:
Expand All @@ -38,7 +37,7 @@ def main(global_config, **settings):
config = Configurator(settings=settings)
config.include("pyramid_openapi3")
config.pyramid_openapi3_spec(openapi_doc.name, route=os.path.join(prefix, 'openapi.yaml'))
config.pyramid_openapi3_add_explorer(route=prefix+"/", proto_port=(proto, port))
config.pyramid_openapi3_add_explorer(route=prefix+"/")
config.registry.settings["pyramid_openapi3.enable_request_validation"] = False
config.registry.settings["pyramid_openapi3.enable_response_validation"] = False
config.add_route('health', prefix+'/_health')
Expand Down

0 comments on commit f57824e

Please sign in to comment.