Skip to content

Commit

Permalink
bugfix and first test
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Jul 3, 2023
1 parent 9fd17cd commit 6ce7c76
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cdci_data_analysis/analysis/drupal_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ def post_revolution_processing_log_to_gallery(product_gallery_url, gallery_jwt_t
# set the type of content to post
body_gallery_article_node["_links"]["type"]["href"] = os.path.join(product_gallery_url,

Check warning on line 1067 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1067

Added line #L1067 was not covered by tests
body_gallery_article_node["_links"]["type"][
"href"], 'data_product')
"href"], 'revolution_processing_log')

# set the initial body content
body_gallery_article_node["body"][0]["value"] = ''

Check warning on line 1072 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1072

Added line #L1072 was not covered by tests
Expand All @@ -1077,7 +1077,7 @@ def post_revolution_processing_log_to_gallery(product_gallery_url, gallery_jwt_t
"target_id": user_id_product_creator
}]

# body_gallery_article_node["title"]["value"] = "revnumber_status_log"
body_gallery_article_node["title"]["value"] = "_".join(["revolution_processing_log", str(uuid.uuid4())])

Check warning on line 1080 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1080

Added line #L1080 was not covered by tests

# let's go through the kwargs and if any overwrite some values for the product to post
for k, v in kwargs.items():

Check warning on line 1083 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1083

Added line #L1083 was not covered by tests
Expand All @@ -1091,7 +1091,7 @@ def post_revolution_processing_log_to_gallery(product_gallery_url, gallery_jwt_t
headers = get_drupal_request_headers(gallery_jwt_token)

Check warning on line 1091 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1091

Added line #L1091 was not covered by tests

logger.info("posting a new revolution-processing-log")
log_res = execute_drupal_request(os.path.join(product_gallery_url, 'node', ),
log_res = execute_drupal_request(os.path.join(product_gallery_url, 'node'),

Check warning on line 1094 in cdci_data_analysis/analysis/drupal_helper.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/drupal_helper.py#L1093-L1094

Added lines #L1093 - L1094 were not covered by tests
method='post',
data=json.dumps(body_gallery_article_node),
headers=headers,
Expand Down
44 changes: 44 additions & 0 deletions tests/test_server_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,50 @@ def test_product_gallery_post_period_of_observation(dispatcher_live_fixture_with
assert drupal_res_obs_info_obj['title'][0]['value'] == params['title']


@pytest.mark.test_drupal
def test_revolution_processing_log_gallery_post(dispatcher_live_fixture_with_gallery, dispatcher_test_conf_with_gallery):
dispatcher_fetch_dummy_products('default')

server = dispatcher_live_fixture_with_gallery

logger.info("constructed server: %s", server)

# send simple request
# 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')
params = {
'content_type': 'revolution_processing_log',
'revolution_number': 1,
'log': 'test log',
'type': 'success',
'token': encoded_token
}

c = requests.post(os.path.join(server, "post_revolution_processing_log_to_gallery"),
params={**params},
)

assert c.status_code == 200

drupal_res_obj = c.json()

assert 'title' in drupal_res_obj

assert 'field_log' in drupal_res_obj
assert drupal_res_obj['field_log'][0]['value'] == params['log']

assert 'field_revolution_number' in drupal_res_obj
assert drupal_res_obj['field_revolution_number'][0]['value'] == params['revolution_number']

assert 'field_type' in drupal_res_obj
assert drupal_res_obj['field_type'][0]['value'] == params['type']


@pytest.mark.test_drupal
@pytest.mark.parametrize("provide_job_id", [True, False])
@pytest.mark.parametrize("provide_instrument", [True, False])
Expand Down

0 comments on commit 6ce7c76

Please sign in to comment.