Skip to content

Commit

Permalink
Merge branch 'master' into 217-add-functionality-to-send-callback-mes…
Browse files Browse the repository at this point in the history
…sages
  • Loading branch information
okolo committed Dec 6, 2023
2 parents 1c71c7e + f8ce41a commit 523a9f5
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 39 deletions.
46 changes: 17 additions & 29 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ on:
push:
branches:
- master
- ci
- release-action
# - main

jobs:
bump-version:
name: Bump package version
if: "!contains(github.event.head_commit.message, 'Bump version')"
runs-on: ubuntu-20.04

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- name: actions/checkout
uses: actions/checkout@v2
# with:
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.BOT_SECRET }}
# persist-credentials: false

- name: Install dependencies
Expand All @@ -29,10 +37,13 @@ jobs:
git config --global user.name "ODA Release Bot"
bump2version patch --verbose --commit --tag
bump2version release --verbose --commit --tag
git push --tags
- uses: stefanzweifel/git-auto-commit-action@v4
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

- name: Build package
run: python -m build

Expand All @@ -42,26 +53,3 @@ jobs:
user: __token__
verify_metadata: false
password: ${{ secrets.PYPI_API_TOKEN }}

#TODO: #211 fix this
# - name: Conda publish
# uses: silvxlabs/conda-skeleton-publish@v2
# with:
# # Name of PyPI package
# pypi_package: oda-api # optional
# # Package version on PyPi
# #package_version: # optional, default is latest
# # Python version to build
# #python_version: # optional
# # Conda channels to use for building package
# build_channels: conda-forge
# # Conda channel to upload to
# upload_channel: mmoda# optional
# # Anaconda client access token
# access_token: ${{ secrets.CONDA_ACCESS_TOKEN }}
# # Platforms to publish
# #platforms: # optional, default is win-64 osx-64 osx-arm64 linux-64 linux-aarch64
# # Set this to true if this is a stable release. Passese a `-l beta` arg if false.
# #stable: # optional
# # If true, waits for the PyPi package to become available.
# wait: true # optional
2 changes: 1 addition & 1 deletion doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Development version
Download code and contribute
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Source code can be found can be found on github https://github.com/oda-hub/oda_api (see https://github.com/oda-hub/oda_api/archive/refs/tags/v1.2.0.tar.gz for latest release bundle).
Source code can be found can be found on github https://github.com/oda-hub/oda_api (see https://github.com/oda-hub/oda_api/archive/refs/tags/v1.2.4.tar.gz for latest release bundle).

To contribute, please feel free to fork the repository, apply your changes, and prepare a pull request.

4 changes: 2 additions & 2 deletions doc/source/user_guide/TestAPI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quick Start (oda api v1.2.0)"
"# Quick Start (oda api v1.2.4)"
]
},
{
Expand Down Expand Up @@ -1488,7 +1488,7 @@
" 'HDUCLAS2': 'TOTAL',\n",
" 'HDUCLAS3': 'RATE',\n",
" 'HDUCLASS': 'OGIP',\n",
" 'HDUVERS': '1.2.1',\n",
" 'HDUVERS': '1.2.4',\n",
" 'INSTRUME': 'IBIS',\n",
" 'ISDCLEVL': 'SPE',\n",
" 'LONGSTRN': 'OGIP 1.0',\n",
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/UploadToGallery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Upload of a product to the gallery (oda api v1.2.0)\n",
"# Upload of a product to the gallery (oda api v1.2.4)\n",
"\n",
"This notebooks documents the functionality for uploading a data product over the data-product gallery.\n",
"\n",
Expand Down
48 changes: 48 additions & 0 deletions oda_api/gallery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,54 @@ def post_observation_to_gallery(self,

return response_json

def delete_data_product_from_gallery_via_product_id(self,
product_id: str,
token: typing.Optional[str] = None):
"""
:param product_id: identifier of a data product assigned by the user, this can be used during the creation of a new data-product,
as well as to identify an already existing one and update it with the arguments provided by the user
:param token: user token
"""
if token is None:
token = self.token

params = {
'content_type': 'data_product',
'token': token,
'product_id': product_id,
}

posting_msg = f'Deleting from the gallery a product with product_id {product_id}'
logger.info(posting_msg)

res = requests.post("%s/delete_product_to_gallery" % self.url,
params={**params}
)

if res.status_code != 200:
error_message = (f"An issue occurred while performing a request on the product gallery, "
f"the following error was returned:\n")
try:
response_json = res.json()
except json.decoder.JSONDecodeError:
error_msg = res.text
response_json = {'error_message': error_msg}
logger.debug(response_json)

if 'error_message' in response_json:
error_message += '\n' + response_json['error_message']
if 'drupal_helper_error_message' in response_json:
error_message += '-' + response_json['drupal_helper_error_message']

logger.warning(error_message)
else:
response_json = self._decode_res_json(res)
logger.info(f"Product successfully deleted from the gallery")

return response_json


def post_data_product_to_gallery(self,
product_title: typing.Optional[str] = None,
product_id: str = None,
Expand Down
2 changes: 1 addition & 1 deletion oda_api/pkg_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "1.2.0"}
{"version": "1.2.4"}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.0
current_version = 1.2.4
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
5 changes: 2 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import ChainMap
from click.testing import CliRunner
import pytest
Expand Down Expand Up @@ -74,9 +75,7 @@ def test_get(dispatcher_live_fixture, caplog, monkeypatch, tmpdir):
result = runner.invoke(cli.cli, ['-u', dispatcher_live_fixture, 'get'], obj={})
assert result.exit_code == 0

assert "found instruments: ['empty', 'empty-async', 'empty-semi-async']" in caplog.text or \
"found instruments: ['empty', 'empty-async', 'empty-semi-async', 'isgri', 'jemx', 'osa_fake']" in caplog.text or \
"found instruments: ['isgri', 'jemx', 'osa_fake', 'empty', 'empty-async', 'empty-semi-async']" in caplog.text
assert re.search(r"found instruments: \[.*\]", caplog.text)

runner = CliRunner()
result = runner.invoke(cli.cli, ['-u', dispatcher_live_fixture, 'get', '-i', 'empty'], obj={})
Expand Down
26 changes: 26 additions & 0 deletions tests/test_drupal.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,32 @@ def test_update_product_gallery(dispatcher_api_with_gallery, dispatcher_test_con
assert link_field_derived_from_observation in res['_links']


@pytest.mark.test_drupal
def test_delete_product_gallery(dispatcher_api_with_gallery, dispatcher_test_conf_with_gallery):
# let's generate a valid token
token_payload = {
**default_token_payload,
'roles': 'general, gallery contributor'
}
encoded_token = jwt.encode(token_payload, secret_key, algorithm='HS256')
product_id = 'aaabbbccc_' + str(time.time())
disp = dispatcher_api_with_gallery

disp.post_data_product_to_gallery(product_title='Test data product to be deleted',
token=encoded_token,
product_id=product_id,
e1_kev=45, e2_kev=95)

list_products = disp.get_list_products_with_conditions(token=encoded_token, product_id=product_id)
assert len(list_products) == 1

res = disp.delete_data_product_from_gallery_via_product_id(token=encoded_token, product_id=product_id)
assert res == {}

list_products = disp.get_list_products_with_conditions(token=encoded_token, product_id=product_id)
assert len(list_products) == 0


@pytest.mark.test_drupal
@pytest.mark.parametrize("product_type", ["spectrum", "lightcurve", "image"])
def test_product_gallery_get_product_with_conditions(dispatcher_api_with_gallery, dispatcher_test_conf_with_gallery, product_type):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def validate_data(data, scw_kind):
assert len(t) == 1


def test_instruments():
def test_instruments(remove_any_token_from_environment):
from oda_api.api import DispatcherAPI
disp = DispatcherAPI(
host=get_platform_dispatcher(),
Expand Down

0 comments on commit 523a9f5

Please sign in to comment.