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

Tests/reorganise tests#375 #393

Merged
merged 24 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
185e304
Initial reorganisation
Reillyhewitson Nov 16, 2022
aa39a81
Fix linting
Reillyhewitson Nov 16, 2022
7ffc4b8
reorganise new DB tests
Reillyhewitson Nov 22, 2022
4ebeb77
Add panosc mapping to unit tests
Reillyhewitson Dec 1, 2022
c0595ba
Split unit and integration test runs
Reillyhewitson Dec 12, 2022
ebcb7a6
Checkout api earlier
Reillyhewitson Dec 12, 2022
4e275f6
Create config earlier and dependency updates
Reillyhewitson Dec 12, 2022
da66fac
Ignore sqlalchemy vulnerability
Reillyhewitson Dec 13, 2022
b3d0fc5
Use latest codecov action
Reillyhewitson Dec 13, 2022
a6f5d06
Multiple codecov uploads
Reillyhewitson Dec 13, 2022
ebd60b6
update to v1
Reillyhewitson Dec 15, 2022
86b9a11
assert correct values for v1
Reillyhewitson Dec 15, 2022
e7b8794
remove get_icat_entity_name_as_camel_case
Reillyhewitson Dec 15, 2022
24c3bd7
Fix linting
Reillyhewitson Jan 3, 2023
a0e9527
Update python icat to full release
Reillyhewitson Jan 4, 2023
aa4350c
Update readme for new test runners.
Reillyhewitson Jan 4, 2023
985aa02
Remove poetry install and setuptools install
Reillyhewitson Jan 10, 2023
f9eb154
Readd fix for python 3.10
Reillyhewitson Jan 10, 2023
5f11ba2
Poetry install needed for generator
Reillyhewitson Jan 10, 2023
c2e3f77
Remove second checkout
Reillyhewitson Jan 10, 2023
35780bb
Add prep for api for integration tests
Reillyhewitson Jan 10, 2023
fe6b137
Merge branch 'tests/reorganise-tests#375' into tests/python_icatv1
Reillyhewitson Feb 1, 2023
8627dbb
Merge pull request #396 from ral-facilities/tests/python_icatv1
Reillyhewitson Feb 1, 2023
619d3e4
Update for safety
Reillyhewitson Feb 1, 2023
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
99 changes: 54 additions & 45 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,56 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Checkout DataGateway API
uses: actions/checkout@v2

# Install Nox, Poetry and API's dependencies
- name: Install Nox
run: pip install nox==2020.8.22
- name: Install Poetry
run: pip install poetry==1.1.9

# Installing an older version of setuptools for reasons explained at: https://github.com/icatproject/python-icat/issues/99
- name: Uninstall setuptools
run: poetry run pip uninstall -y setuptools
- name: Install older setuptools
run: poetry run pip install 'setuptools<58.0.0'

# This command is a workaround for getting Poetry working with Python 3.10. An
# fix is made in Poetry 1.2.0a2 but there is currently no official release for
# Poetry 1.2 and am apprehensive to moving to a pre-release. Disabling the
# experimental installer is a workaround for Poetry 1.1.x
# See https://github.com/python-poetry/poetry/issues/4210 for more details
- name: Disable Poetry's experimental new installer
run: poetry config experimental.new-installer false

- name: Install dependencies
run: poetry install

# Prep for using the API for tests
- name: Create log file
run: touch logs.log
- name: Configure log file location
run: echo "`yq \
'.log_location="${GITHUB_WORKSPACE}/logs.log"' datagateway_api/config.yaml.example | envsubst`" > datagateway_api/config.yaml.example
- name: Configure datagateway extension
run: echo "`yq \
'.datagateway_api.extension="/datagateway_api"' datagateway_api/config.yaml.example`" > datagateway_api/config.yaml.example
- name: Create config.yaml
run: cp datagateway_api/config.yaml.example datagateway_api/config.yaml
- name: Create search_api_mapping.json
run: cp datagateway_api/search_api_mapping.json.example datagateway_api/search_api_mapping.json

# Run Unit tests
- name: Run Nox unit tests session
run: nox -p ${{ matrix.python-version }} -s unit_tests -- --cov=datagateway_api --cov-report=xml
- name: Upload unit test code coverage report
if: matrix.python-version == '3.6'
uses: codecov/codecov-action@v3

# ICAT Ansible clone and install dependencies
- name: Checkout icat-ansible
if: success()
uses: actions/checkout@v2
with:
repository: icatproject-contrib/icat-ansible
Expand Down Expand Up @@ -77,56 +125,17 @@ jobs:
run: |
cd /home/runner/install/icat.server/ && ./setup -vv install

- name: Checkout DataGateway API
uses: actions/checkout@v2

# Prep for using the API for tests
- name: Create log file
run: touch logs.log
- name: Configure log file location
run: echo "`yq \
'.log_location="${GITHUB_WORKSPACE}/logs.log"' datagateway_api/config.yaml.example | envsubst`" > datagateway_api/config.yaml.example
- name: Configure datagateway extension
run: echo "`yq \
'.datagateway_api.extension="/datagateway_api"' datagateway_api/config.yaml.example`" > datagateway_api/config.yaml.example
- name: Create config.yaml
run: cp datagateway_api/config.yaml.example datagateway_api/config.yaml
- name: Create search_api_mapping.json
run: cp datagateway_api/search_api_mapping.json.example datagateway_api/search_api_mapping.json

# Install Nox, Poetry and API's dependencies
- name: Install Nox
run: pip install nox==2020.8.22
- name: Install Poetry
run: pip install poetry==1.1.9

# Installing an older version of setuptools for reasons explained at: https://github.com/icatproject/python-icat/issues/99
- name: Uninstall setuptools
run: poetry run pip uninstall -y setuptools
- name: Install older setuptools
run: poetry run pip install 'setuptools<58.0.0'

# This command is a workaround for getting Poetry working with Python 3.10. An
# fix is made in Poetry 1.2.0a2 but there is currently no official release for
# Poetry 1.2 and am apprehensive to moving to a pre-release. Disabling the
# experimental installer is a workaround for Poetry 1.1.x
# See https://github.com/python-poetry/poetry/issues/4210 for more details
- name: Disable Poetry's experimental new installer
run: poetry config experimental.new-installer false

- name: Install dependencies
run: poetry install

- name: Add dummy data to icatdb
run: |
poetry run python -m util.icat_db_generator

# Run Nox tests session, saves and uploads a coverage report to codecov
- name: Run Nox tests session
run: nox -p ${{ matrix.python-version }} -s tests -- --cov=datagateway_api --cov-report=xml
- name: Upload code coverage report
# Run Nox integration tests session, saves and uploads a coverage report to codecov
- name: Run Nox Integration tests session
if: success()
run: nox -p ${{ matrix.python-version }} -s integration_tests -- --cov=datagateway_api --cov-report=xml
- name: Upload integration test code coverage report
if: matrix.python-version == '3.6'
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3

linting:
runs-on: ubuntu-20.04
Expand Down
29 changes: 26 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def safety(session):
external=True,
)
# Ignore 50916 as the latest version of pydantic and
# Ignore 51457 as the latest version of pytest does not support
# Ignore 51457 as the latest version of pytest and
# Ignore 51668 as the latest version of SQLAchemy as they do not support
# python 3.6 which is still used in production
session.run(
"safety",
Expand All @@ -84,6 +85,8 @@ def safety(session):
"50916",
"--ignore",
"51457",
"--ignore",
"51668",
)

try:
Expand All @@ -95,7 +98,27 @@ def safety(session):


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True)
def tests(session):
def unit_tests(session):
args = session.posargs
# Installing setuptools that will work with `2to3` which is used when building
# `python-icat` < 1.0. 58.0.0 removes support of this tool during builds:
# https://setuptools.pypa.io/en/latest/history.html#v58-0-0
# Ideally this would be done within `pyproject.toml` but specifying `setuptools` as
# a dependency requires Poetry 1.2:
# https://github.com/python-poetry/poetry/issues/4511#issuecomment-922420457
# Currently, only a pre-release exists for Poetry 1.2. Testing on the pre-release
# version didn't fix the `2to3` issue when building Python ICAT, perhaps because
# Python ICAT isn't built on the downgraded version for some reason?
session.run("pip", "uninstall", "-y", "setuptools")
# Not using `poetry run` as it errors on Windows OS when a version with the '<'
# sign is specified for a package
session.run("pip", "install", "setuptools<58.0.0")
session.run("poetry", "install", external=True)
session.run("pytest", "test/unit", *args)


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True)
def integration_tests(session):
args = session.posargs
# Installing setuptools that will work with `2to3` which is used when building
# `python-icat` < 1.0. 58.0.0 removes support of this tool during builds:
Expand All @@ -111,4 +134,4 @@ def tests(session):
# sign is specified for a package
session.run("pip", "install", "setuptools<58.0.0")
session.run("poetry", "install", external=True)
session.run("pytest", *args)
session.run("pytest", "test/integration", *args)
28 changes: 14 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Flask-Cors = "3.0.9"
apispec = "3.3.0"
flask-swagger-ui = "3.25.0"
PyYAML = "5.4"
python-icat = "0.21.0"
python-icat = "^0.21.0"
suds-community = "^0.8.4"
py-object-pool = "^1.1"
cachetools = "^4.2.1"
Expand Down
67 changes: 1 addition & 66 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
from datetime import datetime, timedelta
import json
from unittest.mock import mock_open, patch

from flask import Flask
from icat.client import Client
from icat.query import Query
import pytest

from datagateway_api.src.api_start_utils import (
create_api_endpoints,
create_app_infrastructure,
)
from datagateway_api.src.common.config import APIConfig, Config
from datagateway_api.src.datagateway_api.database.helpers import (
delete_row_by_id,
insert_row_into_table,
)
from datagateway_api.src.datagateway_api.database.models import SESSION


@pytest.fixture(scope="package")
def icat_client():
client = Client(
Config.config.datagateway_api.icat_url,
checkCert=Config.config.datagateway_api.icat_check_cert,
)
client.login(
Config.config.test_mechanism, Config.config.test_user_credentials.dict(),
)
return client
from datagateway_api.src.common.config import APIConfig


@pytest.fixture()
Expand All @@ -46,47 +22,6 @@ def invalid_credentials_header():
return {"Authorization": "Test"}


@pytest.fixture(scope="package")
def flask_test_app():
"""This is used to check the endpoints exist and have the correct HTTP methods"""
test_app = Flask(__name__)
api, spec = create_app_infrastructure(test_app)
create_api_endpoints(test_app, api, spec)

yield test_app


@pytest.fixture(scope="package")
def flask_test_app_db():
"""
This is in the common conftest file because this test app is also used in
non-backend specific tests
"""
db_app = Flask(__name__)
db_app.config["TESTING"] = True
db_app.config["TEST_BACKEND"] = "db"

api, spec = create_app_infrastructure(db_app)
create_api_endpoints(db_app, api, spec)
db_app.app_context().push()

yield db_app.test_client()


@pytest.fixture()
def valid_db_credentials_header():
session = SESSION()
session.id = "Test"
session.expireDateTime = datetime.now() + timedelta(hours=1)
session.username = "Test User"

insert_row_into_table(SESSION, session)

yield {"Authorization": f"Bearer {session.id}"}

delete_row_by_id(SESSION, "Test")


@pytest.fixture()
def test_config_data():
return {
Expand Down
File renamed without changes.
Loading