Skip to content

Commit

Permalink
Update tests fix
Browse files Browse the repository at this point in the history
Fix migration init_db 'id'
Handle app context when needed
Fix conftest fixtures
Rearrange test Dockerfiles
Hide DeprecationWarning during pytest execution
Upgrade all python packages
  • Loading branch information
ymage committed Dec 22, 2022
1 parent 8d849ee commit 8dd03a4
Show file tree
Hide file tree
Showing 14 changed files with 548 additions and 495 deletions.
6 changes: 3 additions & 3 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: "2.1"
version: "3.8"

services:
powerdns-admin:
image: powerdns-admin-test
build:
context: .
dockerfile: docker-test/Dockerfile
image: powerdns-admin-test
container_name: powerdns-admin-test
ports:
- "9191:80"
Expand All @@ -17,10 +17,10 @@ services:
- pdns-server

pdns-server:
image: pdns-server-test
build:
context: .
dockerfile: docker-test/Dockerfile.pdns
image: pdns-server-test
ports:
- "5053:53"
- "5053:53/udp"
Expand Down
30 changes: 24 additions & 6 deletions docker-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
FROM debian:stable-slim
FROM debian:bullseye-slim
LABEL maintainer="[email protected]"

ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8

RUN apt-get update -y \
&& apt-get install -y --no-install-recommends apt-transport-https locales locales-all python3-pip python3-setuptools python3-dev curl libsasl2-dev libldap2-dev libssl-dev libxml2-dev libxslt1-dev libxmlsec1-dev libffi-dev libxmlsec1-openssl pkg-config build-essential libmariadb-dev-compat \
&& apt-get install -y --no-install-recommends \
apt-transport-https \
curl \
build-essential \
libffi-dev \
libldap2-dev \
libmariadb-dev-compat \
libsasl2-dev \
libssl-dev \
libxml2-dev \
libxmlsec1-dev \
libxmlsec1-openssl \
libxslt1-dev \
locales \
locales-all \
pkg-config \
python3-dev \
python3-pip \
python3-setuptools \
&& curl -sL https://deb.nodesource.com/setup_lts.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update -y \
&& apt-get install -y nodejs yarn \
&& apt-get install -y --no-install-recommends \
nodejs \
yarn \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -21,8 +41,6 @@ RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

COPY . /app
COPY ./docker/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ENV FLASK_APP=powerdnsadmin/__init__.py
RUN yarn install --pure-lockfile --production \
Expand All @@ -31,4 +49,4 @@ RUN yarn install --pure-lockfile --production \

COPY ./docker-test/wait-for-pdns.sh /opt
RUN chmod u+x /opt/wait-for-pdns.sh
CMD ["/opt/wait-for-pdns.sh", "/usr/local/bin/pytest","--capture=no","-vv"]
CMD ["/opt/wait-for-pdns.sh", "/usr/local/bin/pytest", "-W", "ignore::DeprecationWarning", "--capture=no", "-vv"]
4 changes: 2 additions & 2 deletions docker-test/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fi

# Import schema structure
if [ -e "/data/pdns.sql" ]; then
rm /data/pdns.db
rm -f /data/pdns.db
cat /data/pdns.sql | sqlite3 /data/pdns.db
rm /data/pdns.sql
rm -f /data/pdns.sql
echo "Imported schema structure"
fi

Expand Down
46 changes: 27 additions & 19 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig

import logging
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool
from flask import current_app

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -17,9 +22,9 @@
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option('sqlalchemy.url',
current_app.config.get('SQLALCHEMY_DATABASE_URI').replace("%","%%"))
config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
Expand All @@ -41,7 +46,9 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True
)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -65,22 +72,23 @@ def process_revision_directives(context, revision, directives):
directives[:] = []
logger.info('No changes in schema detected.')

engine = engine_from_config(config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

connection = engine.connect()
context.configure(connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
render_as_batch=config.get_main_option('sqlalchemy.url').startswith('sqlite:'),
**current_app.extensions['migrate'].configure_args)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)

try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()


if context.is_offline_mode():
run_migrations_offline()
Expand Down
6 changes: 3 additions & 3 deletions migrations/versions/787bdba9e147_init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def seed_data():

op.bulk_insert(template_table,
[
{id: 1, 'name': 'basic_template_1', 'description': 'Basic Template #1'},
{id: 2, 'name': 'basic_template_2', 'description': 'Basic Template #2'},
{id: 3, 'name': 'basic_template_3', 'description': 'Basic Template #3'}
{'id': 1, 'name': 'basic_template_1', 'description': 'Basic Template #1'},
{'id': 2, 'name': 'basic_template_2', 'description': 'Basic Template #2'},
{'id': 3, 'name': 'basic_template_3', 'description': 'Basic Template #3'}
]
)

Expand Down
59 changes: 33 additions & 26 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
Flask==1.1.2
Flask-Assets==2.0
Flask-Login==0.5.0
Flask-SQLAlchemy==2.4.4
Flask-Migrate==2.5.3
SQLAlchemy==1.3.19
mysqlclient==2.0.1
mysqlclient==2.1.1
configobj==5.0.6
bcrypt>=3.1.7
requests==2.24.0
python-ldap==3.4.2
pyotp==2.4.0
qrcode==6.1
bcrypt==4.0.1
requests==2.28.1
python-ldap==3.4.3
pyotp==2.8.0
qrcode==7.3.1
dnspython>=1.16.0
gunicorn==20.0.4
python3-saml
pytz==2020.1
gunicorn==20.1.0
python3-saml==1.14.0
pytz==2022.7
cssmin==0.2.0
rjsmin==1.2.0
Authlib==0.15
rjsmin==1.2.1
Authlib==1.2.0
Flask-SeaSurf==1.1.1
bravado-core==5.17.0
bravado-core==5.17.1
jsonschema[format]>=2.5.1,<4.0.0 # until https://github.com/Yelp/bravado-core/pull/385
lima==0.5
pytest==6.2.5
pytimeparse==1.1.8
PyYAML==5.4
Flask-SSLify==0.1.5
alembic==1.9.0
certifi==2022.12.7
cffi==1.15.1
passlib==1.7.4
pyasn1==0.4.8
webcolors==1.12
zipp==3.11.0
Flask==2.2.2
Flask-Assets==2.0
Flask-Login==0.6.2
Flask-SQLAlchemy==3.0.2
Flask-Migrate==4.0.0
SQLAlchemy==1.4.45
pyOpenSSL==22.1.0
Authlib==1.2.0
Flask-SeaSurf==1.1.1
PyYAML==6.0
Flask-Mail==0.9.1
flask-session==0.3.2
Jinja2==3.0.3
itsdangerous==2.0.1
werkzeug==2.0.3
cryptography==36.0.2
Flask-SSLify==0.1.5
Flask-Session==0.4.0
lxml==4.6.5
pytest==7.2.0
Loading

0 comments on commit 8dd03a4

Please sign in to comment.