Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
author decisions: add decision table and populate it
Browse files Browse the repository at this point in the history
implemented task in airflow that allows for this and added unit tests for all the changes

* ref: cern-sis/issues-inspire/issues/522
  • Loading branch information
DonHaul committed Aug 19, 2024
1 parent 209cf52 commit 19d3644
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 75 deletions.
4 changes: 3 additions & 1 deletion workflows/dags/author/author_create/shared_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

@task()
def create_decision_on_curation_choice(**context):
print("wow")
print(context)
data = {
"action": context["params"]["data"]["value"],
"workflow_id": context["params"]["workflow_id"],
}

BackofficeHook().request(method="POST", data=data, endpoint="api/decisions/")
return BackofficeHook().request(method="POST", data=data, endpoint="api/decisions/")
38 changes: 0 additions & 38 deletions workflows/plugins/hooks/backoffice/decision_management_hook.py

This file was deleted.

2 changes: 2 additions & 0 deletions workflows/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest
coverage
pytest-cov
pytest-vcr==1.0.2
vcrpy==6.0.1
Empty file added workflows/tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
interactions:
- request:
body: '{"action": "create", "workflow_id": "ecaa62db-1326-43cf-8885-da96c544af42"}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Authorization:
- Token 2e04111a61e8f5ba6ecec52af21bbb9e81732085
Connection:
- keep-alive
Content-Length:
- '75'
Content-Type:
- application/json
User-Agent:
- python-requests/2.31.0
method: POST
uri: http://host.docker.internal:8000/api/decisions/
response:
body:
string: '{"id":1,"action":"create","_created_at":"2024-08-19T15:13:28.514638Z","_updated_at":"2024-08-19T15:13:28.514646Z","user":"[email protected]","workflow":"ecaa62db-1326-43cf-8885-da96c544af42"}'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Content-Language:
- en
Content-Length:
- '189'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Mon, 19 Aug 2024 15:13:28 GMT
Referrer-Policy:
- same-origin
Server:
- WSGIServer/0.2 CPython/3.11.6
Vary:
- Accept, Accept-Language, Cookie, origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 201
message: Created
version: 1
52 changes: 16 additions & 36 deletions workflows/tests/test_author_create_tasks.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
from workflows.dags.author.author_create.shared_tasks import (
import pytest
from dags.author.author_create.shared_tasks import (
create_decision_on_curation_choice,
)


def test_create_decision_on_curation_choice():
create_decision_on_curation_choice()


# class TestMyTask(unittest.TestCase):
# @patch("my_dag_module.some_dependency")
# def test_my_task(self, mock_dependency):
# # Arrange: Set up any necessary state or mock returns
# mock_dependency.return_value = "expected_value"

# # Act: Execute the task logic directly
# result = my_task_function()

# # Assert: Verify the results are as expected
# self.assertEqual(result, "expected_output")


# class TestMyDag(unittest.TestCase):
# def setUp(self):
# self.dagbag = DagBag()
# self.dag = self.dagbag.get_dag(dag_id="my_dag_id")
# self.task = self.dag.get_task("my_task_id")

# def test_task_execution(self):
# # You can simulate running the task
# from airflow.models import TaskInstance
# from airflow.utils.dates import days_ago

# ti = TaskInstance(task=self.task, execution_date=days_ago(1))

# # You can optionally mock dependencies here

# # Execute the task and assert the outcome
# ti.run(ignore_ti_state=True) # Ignore previous task instance state
# self.assertEqual(ti.state, State.SUCCESS)
class TestAuthorCreate:
context = {
"params": {
"workflow_id": "ecaa62db-1326-43cf-8885-da96c544af42",
"data": {
"value": "create",
},
}
}

@pytest.mark.vcr()
def test_create_decision_on_curation_choice(self):
result = create_decision_on_curation_choice.function(**self.context)
assert result.status_code == 201

0 comments on commit 19d3644

Please sign in to comment.