Skip to content

Commit

Permalink
Patch - fix GH release and add HTTP header (#283)
Browse files Browse the repository at this point in the history
* Bump patch version

* Fix GitHub release (#276)

* Set ActAsReadUser header (#282)
  • Loading branch information
ludovicsteinbach authored Mar 16, 2023
1 parent cc986aa commit d4ad4be
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 12 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
TEST_SERVER_URL: ${{ secrets.TEST_SERVER_URL }}
TEST_SERVER_READ_USER: ${{ secrets.TEST_SERVER_READ_USER }}
TEST_SERVER_READ_PASS: ${{ secrets.TEST_SERVER_READ_PASS }}
TEST_SERVER_WRITE_USER: ${{ secrets.TEST_SERVER_WRITE_USER }}
TEST_SERVER_WRITE_PASS: ${{ secrets.TEST_SERVER_WRITE_PASS }}

doc-deploy-dev:
name: "Deploy development documentation"
Expand Down Expand Up @@ -65,11 +67,23 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: ansys-grantami-bomanalytics-wheel
path: ~/dist
path: dist

- uses: actions/download-artifact@v3
with:
name: Documentation-pdf
path: dist

- uses: actions/download-artifact@v3
with:
name: Documentation-html
path: dist/documentation-html/

- name: "Compressing HTML documentation"
uses: vimtor/action-zip@v1.1
with:
files: dist/documentation-html/
dest: dist/documentation-html.zip

- name: "Deploy stable documentation"
uses: pyansys/actions/doc-deploy-stable@v4
Expand All @@ -92,6 +106,6 @@ jobs:
with:
generate_release_notes: true
files: |
~/**/*.whl
./**/*.zip
./**/*.pdf
dist/*.whl
dist/documentation-html.zip
dist/*.pdf
6 changes: 6 additions & 0 deletions .github/workflows/server_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ on:
required: true
TEST_SERVER_READ_PASS:
required: true
TEST_SERVER_WRITE_USER:
required: true
TEST_SERVER_WRITE_PASS:
required: true
workflow_dispatch:

concurrency:
Expand Down Expand Up @@ -80,6 +84,8 @@ jobs:
TEST_SL_URL: ${{secrets.TEST_SERVER_URL}}
TEST_USER: ${{secrets.TEST_SERVER_READ_USER}}
TEST_PASS: ${{secrets.TEST_SERVER_READ_PASS}}
TEST_WRITE_USER: ${{secrets.TEST_SERVER_WRITE_USER}}
TEST_WRITE_PASS: ${{secrets.TEST_SERVER_WRITE_PASS}}

docs:
name: Build documentation
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "ansys-grantami-bomanalytics"
description = "Perform compliance analysis on materials data stored in Granta MI."
version = "1.1.2"
version = "1.1.3"
license = "MIT"
authors = ["ANSYS, Inc."]
maintainers = ["PyAnsys Maintainers <pyansys.maintainers@ansys.com>"]
repository = "https://github.com/pyansys/grantami-bomanalytics"
documentation = "https://grantami.docs.pyansys.com"
documentation = "https://bomanalytics.grantami.docs.pyansys.com"
readme = "README.rst"
keywords = [
"Ansys",
Expand Down Expand Up @@ -109,6 +109,8 @@ passenv =
TEST_SL_URL
TEST_USER
TEST_PASS
TEST_WRITE_USER
TEST_WRITE_PASS
[testenv:style]
deps =
Expand Down
1 change: 1 addition & 0 deletions src/ansys/grantami/bomanalytics/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self, api_url: str, session_configuration: Optional[SessionConfigur
session_configuration = self._session_configuration
session_configuration.headers["X-Granta-ApplicationName"] = GRANTA_APPLICATION_NAME_HEADER
session_configuration.headers["User-Agent"] = generate_user_agent("ansys-grantami-bomanalytics", __version__)
session_configuration.headers["X-Granta-ActAsReadUser"] = "true"

def connect(self) -> "BomAnalyticsClient":
"""Finalize the BoM Analytics client and return it for use.
Expand Down
24 changes: 18 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from .common import CUSTOM_TABLES

sl_url = os.getenv("TEST_SL_URL", "http://localhost/mi_servicelayer")
username = os.getenv("TEST_USER")
password = os.getenv("TEST_PASS")
read_username = os.getenv("TEST_USER")
read_password = os.getenv("TEST_PASS")

write_username = os.getenv("TEST_WRITE_USER")
write_password = os.getenv("TEST_WRITE_PASS")


@pytest.fixture(scope="session")
def default_connection():
connection = Connection(api_url=sl_url).with_credentials(username, password).connect()
connection = Connection(api_url=sl_url).with_credentials(read_username, read_password).connect()
return connection


@pytest.fixture
def configurable_connection(request):
connection = Connection(api_url=sl_url).with_credentials(username, password).connect()
def _get_connection(request, url, username, password):
connection = Connection(api_url=url).with_credentials(username, password).connect()
if request.param:
if isinstance(request.param, str):
db_key = request.param
Expand All @@ -31,6 +33,16 @@ def configurable_connection(request):
return connection


@pytest.fixture
def configurable_connection(request):
return _get_connection(request, sl_url, read_username, read_password)


@pytest.fixture
def configurable_connection_write(request):
return _get_connection(request, sl_url, write_username, write_password)


@pytest.fixture
def mock_connection():
with requests_mock.Mocker() as m:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,31 @@ def test_missing_table_raises_grantami_exception(default_connection):
@pytest.mark.parametrize("configurable_connection", [True, False], indirect=True)
def test_yaml(configurable_connection):
assert configurable_connection.run(queries.Yaml)


class TestActAsReadUser:
def _run_query(self, connection):
MATERIAL_ID = "plastic-abs-pc-flame"
LEGISLATION_ID = "The SIN List 2.1 (Substitute It Now!)"
mat_query = (
queries.MaterialImpactedSubstancesQuery()
.with_material_ids([MATERIAL_ID])
.with_legislations([LEGISLATION_ID])
)
results = connection.run(mat_query)
return results

@pytest.mark.parametrize("configurable_connection_write", [True], indirect=True)
def test_withdrawn_records_are_not_included(self, configurable_connection_write):
results = self._run_query(configurable_connection_write)

assert not results.messages

@pytest.mark.parametrize("configurable_connection_write", [True], indirect=True)
def test_withdrawn_records_return_warning_messages_if_not_acting_as_read(self, configurable_connection_write):
del configurable_connection_write.rest_client.headers["X-Granta-ActAsReadUser"]
results = self._run_query(configurable_connection_write)

assert any(
"has 1 substance row(s) having more than one linked substance. " in msg.message for msg in results.messages
)

0 comments on commit d4ad4be

Please sign in to comment.