Skip to content

Commit

Permalink
Adapt CI pipeline to country template v7
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiSG authored May 3, 2024
2 parents 069c542 + c837aef commit 51c3d43
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 64 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 41.4.4 [#1208](https://github.com/openfisca/openfisca-core/pull/1208)

#### Technical changes

- Adapt testing pipeline to Country Template [v7](https://github.com/openfisca/country-template/pull/139).

### 41.4.3 [#1206](https://github.com/openfisca/openfisca-core/pull/1206)

#### Technical changes
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pytest_plugins = [
"tests.fixtures.appclient",
"tests.fixtures.entities",
"tests.fixtures.extensions",
"tests.fixtures.simulations",
"tests.fixtures.taxbenefitsystems",
]
19 changes: 12 additions & 7 deletions openfisca_core/taxbenefitsystems/tax_benefit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import functools
import glob
import importlib
import importlib.metadata
import importlib.util
import inspect
import linecache
import logging
import os
import sys
import traceback

import importlib_metadata

from openfisca_core import commons, periods, variables
from openfisca_core.entities import Entity
from openfisca_core.errors import VariableNameConflictError, VariableNotFoundError
Expand Down Expand Up @@ -524,9 +524,9 @@ def get_package_metadata(self) -> Dict[str, str]:
package_name = module.__package__.split(".")[0]

try:
distribution = importlib_metadata.distribution(package_name)
distribution = importlib.metadata.distribution(package_name)

except importlib_metadata.PackageNotFoundError:
except importlib.metadata.PackageNotFoundError:
return fallback_metadata

source_file = inspect.getsourcefile(module)
Expand All @@ -540,9 +540,14 @@ def get_package_metadata(self) -> Dict[str, str]:
metadata = distribution.metadata

return {
"name": metadata["Name"].lower(),
"version": distribution.version,
"repository_url": metadata["Home-page"],
"name": metadata.get("Name").lower(),
"version": metadata.get("Version"),
"repository_url": next(
filter(
lambda url: url.startswith("Repository"),
metadata.get_all("Project-URL"),
)
).split("Repository, ")[-1],
"location": location,
}

Expand Down
5 changes: 3 additions & 2 deletions openfisca_web_api/loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def build_data(tax_benefit_system):
country_package_metadata = tax_benefit_system.get_package_metadata()
parameters = build_parameters(tax_benefit_system, country_package_metadata)
variables = build_variables(tax_benefit_system, country_package_metadata)
entities = build_entities(tax_benefit_system)
data = {
"tax_benefit_system": tax_benefit_system,
"country_package_metadata": tax_benefit_system.get_package_metadata(),
"country_package_metadata": country_package_metadata,
"openAPI_spec": None,
"parameters": parameters,
"variables": variables,
"entities": build_entities(tax_benefit_system),
"entities": entities,
}
data["openAPI_spec"] = build_openAPI_specification(data)

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
general_requirements = [
"PyYAML >=6.0, <7.0",
"dpath >=2.1.4, <3.0",
"importlib-metadata >=6.1.0, <7.0",
"numexpr >=2.8.4, <3.0",
"numpy >=1.24.2, <1.25",
"pendulum >=2.1.2, <3.0.0",
Expand Down Expand Up @@ -67,7 +66,7 @@

setup(
name="OpenFisca-Core",
version="41.4.3",
version="41.4.4",
author="OpenFisca Team",
author_email="contact@openfisca.org",
classifiers=[
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from importlib import metadata

import pytest


@pytest.fixture()
def test_country_package_name():
return "openfisca_country_template"


@pytest.fixture()
def test_extension_package_name():
return "openfisca_extension_template"


@pytest.fixture()
def distribution(test_country_package_name):
return metadata.distribution(test_country_package_name)
4 changes: 0 additions & 4 deletions tests/web_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
import pkg_resources

TEST_COUNTRY_PACKAGE_NAME = "openfisca_country_template"
distribution = pkg_resources.get_distribution(TEST_COUNTRY_PACKAGE_NAME)
12 changes: 0 additions & 12 deletions tests/web_api/basic_case/__init__.py

This file was deleted.

Empty file.
33 changes: 19 additions & 14 deletions tests/web_api/case_with_extension/test_extensions.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
# -*- coding: utf-8 -*-
from http import client

from http.client import OK
import pytest

from openfisca_core.scripts import build_tax_benefit_system
from openfisca_web_api.app import create_app

TEST_COUNTRY_PACKAGE_NAME = "openfisca_country_template"
TEST_EXTENSION_PACKAGE_NAMES = ["openfisca_extension_template"]

tax_benefit_system = build_tax_benefit_system(
TEST_COUNTRY_PACKAGE_NAME, extensions=TEST_EXTENSION_PACKAGE_NAMES, reforms=None
)
@pytest.fixture()
def tax_benefit_system(test_country_package_name, test_extension_package_name):
return build_tax_benefit_system(
test_country_package_name,
extensions=[test_extension_package_name],
reforms=None,
)


extended_subject = create_app(tax_benefit_system).test_client()
@pytest.fixture()
def extended_subject(tax_benefit_system):
return create_app(tax_benefit_system).test_client()


def test_return_code():
def test_return_code(extended_subject):
parameters_response = extended_subject.get("/parameters")
assert parameters_response.status_code == OK
assert parameters_response.status_code == client.OK


def test_return_code_existing_parameter():
def test_return_code_existing_parameter(extended_subject):
extension_parameter_response = extended_subject.get(
"/parameter/local_town.child_allowance.amount"
)
assert extension_parameter_response.status_code == OK
assert extension_parameter_response.status_code == client.OK


def test_return_code_existing_variable():
def test_return_code_existing_variable(extended_subject):
extension_variable_response = extended_subject.get(
"/variable/local_town_child_allowance"
)
assert extension_variable_response.status_code == OK
assert extension_variable_response.status_code == client.OK
24 changes: 13 additions & 11 deletions tests/web_api/case_with_reform/test_reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
from openfisca_core import scripts
from openfisca_web_api import app

TEST_COUNTRY_PACKAGE_NAME = "openfisca_country_template"
TEST_REFORMS_PATHS = [
f"{TEST_COUNTRY_PACKAGE_NAME}.reforms.add_dynamic_variable.add_dynamic_variable",
f"{TEST_COUNTRY_PACKAGE_NAME}.reforms.add_new_tax.add_new_tax",
f"{TEST_COUNTRY_PACKAGE_NAME}.reforms.flat_social_security_contribution.flat_social_security_contribution",
f"{TEST_COUNTRY_PACKAGE_NAME}.reforms.modify_social_security_taxation.modify_social_security_taxation",
f"{TEST_COUNTRY_PACKAGE_NAME}.reforms.removal_basic_income.removal_basic_income",
]

@pytest.fixture()
def test_reforms_path(test_country_package_name):
return [
f"{test_country_package_name}.reforms.add_dynamic_variable.add_dynamic_variable",
f"{test_country_package_name}.reforms.add_new_tax.add_new_tax",
f"{test_country_package_name}.reforms.flat_social_security_contribution.flat_social_security_contribution",
f"{test_country_package_name}.reforms.modify_social_security_taxation.modify_social_security_taxation",
f"{test_country_package_name}.reforms.removal_basic_income.removal_basic_income",
]


# Create app as in 'openfisca serve' script
@pytest.fixture
def client():
def client(test_country_package_name, test_reforms_path):
tax_benefit_system = scripts.build_tax_benefit_system(
TEST_COUNTRY_PACKAGE_NAME,
test_country_package_name,
extensions=None,
reforms=TEST_REFORMS_PATHS,
reforms=test_reforms_path,
)

return app.create_app(tax_benefit_system).test_client()
Expand Down
Empty file removed tests/web_api/loader/__init__.py
Empty file.
18 changes: 6 additions & 12 deletions tests/web_api/test_headers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# -*- coding: utf-8 -*-

from . import distribution


def test_package_name_header(test_client):
def test_package_name_header(test_client, distribution):
name = distribution.metadata.get("Name").lower()
parameters_response = test_client.get("/parameters")
assert parameters_response.headers.get("Country-Package") == distribution.key
assert parameters_response.headers.get("Country-Package") == name


def test_package_version_header(test_client):
def test_package_version_header(test_client, distribution):
version = distribution.metadata.get("Version")
parameters_response = test_client.get("/parameters")
assert (
parameters_response.headers.get("Country-Package-Version")
== distribution.version
)
assert parameters_response.headers.get("Country-Package-Version") == version

0 comments on commit 51c3d43

Please sign in to comment.