Skip to content

Commit

Permalink
dedicated test
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Sep 19, 2023
1 parent 81a6283 commit 0cf3847
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/test_drupal.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,104 @@ 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
@pytest.mark.parametrize("product_type", ["spectrum", "lightcurve"])
def test_product_gallery_get_product_with_conditions(dispatcher_api_with_gallery, dispatcher_test_conf_with_gallery, product_type):
# let's generate a valid token
token_payload = {

Check warning on line 772 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L772

Added line #L772 was not covered by tests
**default_token_payload,
"roles": "general, gallery contributor",
}
encoded_token = jwt.encode(token_payload, secret_key, algorithm='HS256')
disp = dispatcher_api_with_gallery
product_type = 'isgri_lightcurve'
if product_type == 'spectrum':
product_type = 'isgri_spectrum'
instrument_name = 'isgri'
T1 = '2022-07-21T00:29:47'
params = {'time_to_convert': T1,

Check warning on line 783 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L776-L783

Added lines #L776 - L783 were not covered by tests
'token': encoded_token}

c = requests.get(os.path.join(disp.url, "get_revnum"),

Check warning on line 786 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L786

Added line #L786 was not covered by tests
params={**params}
)
revnum_obj = c.json()
T1_revs = revnum_obj['revnum']

Check warning on line 790 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L789-L790

Added lines #L789 - L790 were not covered by tests

T2 = '2022-08-23T05:29:11'
params = {'time_to_convert': T2,

Check warning on line 793 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L792-L793

Added lines #L792 - L793 were not covered by tests
'token': encoded_token}

c = requests.get(os.path.join(disp.url, "get_revnum"),

Check warning on line 796 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L796

Added line #L796 was not covered by tests
params={**params}
)
revnum_obj = c.json()
T2_revs = revnum_obj['revnum']

Check warning on line 800 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L799-L800

Added lines #L799 - L800 were not covered by tests

source_name = 'test astro entity' + '_' + str(uuid.uuid4())
product_title = 'test same source different name'
disp.post_data_product_to_gallery(

Check warning on line 804 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L802-L804

Added lines #L802 - L804 were not covered by tests
product_title=product_title,
instrument=instrument_name,
product_type=product_type,
src_name=source_name,
insert_new_source=True,
token=encoded_token,
e1_kev=150, e2_kev=350,
T1=T1, T2=T2
)

for e1_kev, e2_kev, t1, t2 in [

Check warning on line 815 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L815

Added line #L815 was not covered by tests
(100, 350, '2022-07-21T00:29:47', '2022-08-23T05:29:11'),
(100, 350, '2022-07-19T00:29:47', '2022-08-25T05:29:11'),
(100, 350, '2022-07-29T00:29:47', '2022-08-01T05:29:11'),
(100, 350, '2022-07-19T00:29:47', '2022-08-23T05:29:11'),
(50, 400, '2022-07-21T00:29:47', '2022-08-23T05:29:11'),
(200, 350, '2022-07-21T00:29:47', '2022-08-23T05:29:11'),
(50, 300, '2022-07-21T00:29:47', '2022-08-23T05:29:11'),
]:
params = {'time_to_convert': t1,

Check warning on line 824 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L824

Added line #L824 was not covered by tests
'token': encoded_token}

c = requests.get(os.path.join(disp.url, "get_revnum"),

Check warning on line 827 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L827

Added line #L827 was not covered by tests
params={**params}
)
revnum_obj = c.json()
t1_revs = revnum_obj['revnum']

Check warning on line 831 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L830-L831

Added lines #L830 - L831 were not covered by tests

params['time_to_convert'] = t2
c = requests.get(os.path.join(disp.url, "get_revnum"),

Check warning on line 834 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L833-L834

Added lines #L833 - L834 were not covered by tests
params={**params}
)
revnum_obj = c.json()

Check warning on line 837 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L837

Added line #L837 was not covered by tests

t2_revs = revnum_obj['revnum']
if product_type == 'spectrum':
spectra_list = disp.get_list_spectra_with_conditions(source_name=source_name,

Check warning on line 841 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L839-L841

Added lines #L839 - L841 were not covered by tests
t1=t1, t2=t2,
instrument=instrument_name,
token=encoded_token)
assert isinstance(spectra_list, list)

Check warning on line 845 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L845

Added line #L845 was not covered by tests

if t1_revs > T1_revs or t2_revs < T2_revs:
assert len(spectra_list) == 0

Check warning on line 848 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L847-L848

Added lines #L847 - L848 were not covered by tests
else:
assert len(spectra_list) == 1

Check warning on line 850 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L850

Added line #L850 was not covered by tests

elif product_type == 'lightcurve':
spectra_list = disp.get_list_lightcurve_with_conditions(source_name=source_name,

Check warning on line 853 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L852-L853

Added lines #L852 - L853 were not covered by tests
e1_kev=e1_kev, e2_kev=e2_kev,
t1=t1, t2=t2,
instrument=instrument_name,
token=encoded_token)
assert isinstance(spectra_list, list)

Check warning on line 858 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L858

Added line #L858 was not covered by tests

if e1_kev > 100 or e2_kev < 350 or t1_revs > T1_revs or t2_revs < T2_revs:
assert len(spectra_list) == 0

Check warning on line 861 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L860-L861

Added lines #L860 - L861 were not covered by tests
else:
assert len(spectra_list) == 1

Check warning on line 863 in tests/test_drupal.py

View check run for this annotation

Codecov / codecov/patch

tests/test_drupal.py#L863

Added line #L863 was not covered by tests


@pytest.mark.test_drupal
@pytest.mark.parametrize("source_name", ["new", "known"])
def test_product_gallery_get_product_list_by_source_name(dispatcher_api_with_gallery, dispatcher_test_conf_with_gallery, source_name):
Expand Down

0 comments on commit 0cf3847

Please sign in to comment.