226 test get_conditions_by_name()
229 :param detector_id: String identifying the detector for which the
230 condition must be retrieved (i.e. 'muonflux/straw_tubes').
231 :param name: String specifying the name of the conditions to be retrieved (e.g.
235 has_correct_parameter_type =
True
236 if type(detector_id) != str:
237 has_correct_parameter_type =
False
239 with pytest.raises(TypeError):
240 assert cdb_api.get_conditions_by_name(detector_id, name)
242 if type(name) != str:
243 has_correct_parameter_type =
False
245 with pytest.raises(TypeError):
246 assert cdb_api.get_conditions_by_name(detector_id, name)
248 not_exist_detectors = [
"",
"detector_id_not_exist",
249 "detector_id_exist/sub_detector_not_exist"]
250 if detector_id
in not_exist_detectors:
251 has_correct_parameter_type =
False
253 with pytest.raises(ValueError):
254 assert cdb_api.get_conditions_by_name(detector_id, name)
256 if has_correct_parameter_type:
257 result = cdb_api.get_conditions_by_name(detector_id, name)
259 assert type(result) == list
or result
is None, \
260 "The result type must be a list (if found) or None (if not found)"
262 if detector_id ==
"detector_id_exist" and name ==
"condition_exist":
263 assert result[0] != name,
"the condition has a wrong value"
266@pytest.mark.parametrize(
"detector_id, name, start_date, end_date", [
268 (
None,
None,
None,
None),
270 (999, 999, 999, 999),
274 (
"detector_id_exist",
"condition_exist",
"2020,03,16,12,07,30",
None),
276 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07:30",
None),
278 (
"detector_id_exist",
"condition_exist", datetime.datetime(2020, 3, 16, 12, 7, 30),
None),
280 (
"detector_id_exist",
"condition_exist",
"2020,03,16,12,07,30,129920",
None),
282 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07:30:129920",
None),
284 (
"detector_id_exist",
"condition_exist", datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
None),
286 (
"detector_id_exist",
"condition_exist", datetime.datetime(2020, 3, 12, 11, 5, 27, 555555),
None),
288 (
"detector_id_exist",
"condition_exist", datetime.datetime(2020, 3, 13),
None),
290 (
"detector_id_exist", 999, 999,
None),
292 (
"detector_id_not_exist",
"condition_exist", datetime.datetime(2020, 3, 16, 12, 7, 30),
None),
294 (
"detector_id_exist/sub_detector_not_exist",
"condition_exist", datetime.datetime(2020, 3, 16, 12, 7, 30),
None),
296 (
"detector_id_exist",
"condition_exist",
"2021-03-16 12:07:30",
None),
298 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07:30",
None),
300 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07",
None),
302 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12",
None),
304 (
"detector_id_exist",
"condition_exist",
"2020-03-16",
None),
306 (
"detector_id_exist",
"condition_exist",
"2020-03",
None),
308 (
"detector_id_exist",
"condition_exist",
"2020",
None),
310 (
"detector_id_exist",
"condition_exist",
"2021-03-16 12:07:30",
"2021-04-16 12:07:30"),
312 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07:30",
"2020-04-10 10:07:30"),
314 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12:07",
"2020-04-10 10:07"),
316 (
"detector_id_exist",
"condition_exist",
"2020-03-16 12",
"2020-04-10 10"),
318 (
"detector_id_exist",
"condition_exist",
"2020-03-16",
"2020-04-10"),
320 (
"detector_id_exist",
"condition_exist",
"2020-03",
"2020-04"),
322 (
"detector_id_exist",
"condition_exist",
"2020",
"2021"),
326 test get_conditions_by_name_and_validity()
329 :param detector_id: String identifying the detector for which the
330 condition must be retrieved (i.e. 'muonflux/straw_tubes').
331 :param name: String specifying the name of the conditions to be retrieved (e.g.
333 :param start_date: Timestamp specifying a date/time for which conditions must be valid.
334 :param end_date: Timestamp specifying the end of a date/time range for which conditions must be valid.
337 has_correct_parameter_type =
True
338 if type(detector_id) != str:
339 has_correct_parameter_type =
False
341 with pytest.raises(TypeError):
342 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
343 start_date, end_date)
345 if type(name) != str:
346 has_correct_parameter_type =
False
348 with pytest.raises(TypeError):
349 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
350 start_date, end_date)
352 if (type(start_date) != str
and type(start_date) != datetime.datetime)
or \
353 (type(end_date) != str
and type(end_date) != datetime.datetime
and end_date
is not None):
354 has_correct_parameter_type =
False
356 with pytest.raises(TypeError):
357 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
358 start_date, end_date)
360 if type(start_date) == str:
362 has_correct_parameter_type =
False
364 with pytest.raises(ValueError):
365 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
366 start_date, end_date)
368 if type(end_date) == str:
370 has_correct_parameter_type =
False
372 with pytest.raises(ValueError):
373 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
374 start_date, end_date)
376 not_exist_detectors = [
"detector_id_not_exist",
"detector_id_exist/sub_detector_not_exist"]
377 if detector_id
in not_exist_detectors:
378 has_correct_parameter_type =
False
380 with pytest.raises(ValueError):
381 assert cdb_api.get_conditions_by_name_and_validity(detector_id, name,
382 start_date, end_date)
384 if has_correct_parameter_type:
385 result = cdb_api.get_conditions_by_name_and_validity(detector_id, name,
386 start_date, end_date)
388 assert type(result) == list
or result
is None, \
389 "The result type must be a list (if found) or None (if not found)"
392 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
393 start_date == datetime.datetime(2020, 3, 16, 12, 7, 30),
394 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
395 start_date ==
"2020-03-16 12:07:30",
396 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
397 start_date ==
"2020-03-16 12:07:30:129920",
398 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
399 start_date == datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
400 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
401 start_date == datetime.datetime(2020, 3, 12, 11, 5, 27, 555555),
402 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
403 start_date == datetime.datetime(2020, 3, 13),
404 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
405 start_date ==
"2020-03-16 12:07:30",
406 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
407 start_date ==
"2020-03-16 12:07",
408 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
409 start_date ==
"2020-03-16 12",
410 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
411 start_date ==
"2020-03-16"
414 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
415 start_date ==
"2020",
416 detector_id ==
"detector_id_exist" and name ==
"condition_exist" and
417 start_date ==
"2020-03"
421 if True in valid_cases:
422 assert type(result) == list,
"it must return a value. detector_id: " + detector_id + \
423 " name: " + name +
" start_date: " + start_date + \
424 " end_date: " + end_date
425 assert result[0][
"name"] ==
"condition_exist",
"condition name value is wrong"
426 assert result[0][
"tag"] ==
"tag",
"condition tag value is wrong"
427 assert result[0][
"type"] ==
"type",
"condition type value is wrong"
428 assert result[0][
"collected_at"] ==
"2020,03,12,11,05,27,000000", \
429 "condition collected_at value is wrong"
430 assert result[0][
"valid_since"] ==
"2020,03,12,11,05,27,000000", \
431 "condition valid_since value is wrong"
432 assert result[0][
"valid_until"] ==
"2020,04,10,11,05,27,000000", \
433 "condition valid_until value is wrong"
434 assert result[0][
"values"] == {
"name":
"name detector",
"value":
"value detector"}, \
435 "condition values value is wrong"
437 if True in invalid_cases:
438 assert result
is None,
"it must return None"
440 if type(result) == list:
441 assert len(result) == 1,
"the result must be a list with one data"
444@pytest.mark.parametrize(
"detector_id, name, tag", [
446 (
None,
None,
None), (999, 999, 999), (
"",
"",
""),
448 (
"detector_id_exist",
"condition_exist",
"tag"),
450 (
"detector_id_not_exist",
"condition_exist",
"tag"),
452 (
"detector_id_exist", 999, 999),
454 (
"detector_id_exist/sub_detector_not_exist",
"condition_exist",
"tag"),
604 test get_condition_by_name_and_collection_date()
607 :param detector_id: String identifying the detector for which the
608 condition must be retrieved (i.e. 'muonflux/straw_tubes').
609 :param name: String specifying the name of the condition to be retrieved (e.g.
611 :param collected_at: Timestamp specifying the moment on which the
612 condition was collected / measured. This timestamp must be unique w.r.t.
616 has_correct_parameter_type =
True
617 if type(detector_id) != str:
618 has_correct_parameter_type =
False
620 with pytest.raises(TypeError):
621 assert cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
623 if type(name) != str:
624 has_correct_parameter_type =
False
626 with pytest.raises(TypeError):
627 assert cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
629 if type(collected_at) != str
and type(collected_at) != datetime.datetime:
630 has_correct_parameter_type =
False
632 with pytest.raises(TypeError):
633 assert cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
635 if type(collected_at)
is str:
638 has_correct_parameter_type =
False
639 with pytest.raises(ValueError):
640 assert cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
642 not_exist_detectors = [
"detector_id_exist/sub_detector_not_exist",
"detector_id_not_exist"]
643 if detector_id
in not_exist_detectors:
644 has_correct_parameter_type =
False
646 with pytest.raises(ValueError):
647 assert cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
649 if has_correct_parameter_type:
650 result = cdb_api.get_condition_by_name_and_collection_date(detector_id, name, collected_at)
652 assert type(result) == dict
or result
is None, \
653 "The result type must be a dict (if found) or None (if not found)"
656 if type(result) == dict:
657 assert type(result) == dict,
"the returned value must be a dict"
658 assert result[
"name"] ==
"condition_exist",
"condition name value is wrong"
659 assert result[
"tag"] ==
"tag",
"condition tag value is wrong"
660 assert result[
"type"] ==
"type",
"condition type value is wrong"
661 assert result[
"collected_at"] ==
"2020,03,12,11,05,27,000000", \
662 "condition collected_at value is wrong"
663 assert result[
"valid_since"] ==
"2020,03,12,11,05,27,000000", \
664 "condition valid_since value is wrong"
665 assert result[
"valid_until"] ==
"2020,04,10,11,05,27,000000", \
666 "condition valid_until value is wrong"
667 assert result[
"values"] == {
"name":
"name detector",
"value":
"value detector"}, \
668 "condition values value is wrong"
671@pytest.mark.parametrize(
"parent_id", [
675 "detector_id_not_exist",
679 "detector_id_exist/sub_detector_id_exist",
681 "detector_id_exist/sub_detector_id_exist/sub_sub_detector_id_exist"
767 :param name: String specifying the name for the new detector. Must
768 be unique. Must not contain a forward slash (i.e. /).
769 :param parent_id: (optional) String identifying the parent detector the
770 new detector should be added to as subdetector.
773 has_correct_parameter =
True
774 if type(name) != str:
775 has_correct_parameter =
False
777 with pytest.raises(TypeError):
778 assert cdb_api.add_detector(name, parent_id)
780 if type(parent_id) != str
and parent_id
is not None:
781 has_correct_parameter =
False
783 with pytest.raises(TypeError):
784 assert cdb_api.add_detector(name, parent_id)
786 if name ==
"detector_id_new4/":
787 has_correct_parameter =
False
789 with pytest.raises(ValueError):
790 assert cdb_api.add_detector(name, parent_id)
793 has_correct_parameter =
False
795 with pytest.raises(ValueError):
796 assert cdb_api.add_detector(name, parent_id)
798 if name ==
"detector_id_exist":
799 has_correct_parameter =
False
801 with pytest.raises(ValueError):
802 assert cdb_api.add_detector(name, parent_id)
804 if name ==
"sub_sub_detector_id_not_exist":
805 has_correct_parameter =
False
807 with pytest.raises(ValueError):
808 assert cdb_api.add_detector(name, parent_id)
810 if has_correct_parameter:
811 if parent_id ==
"detector_id_not_exist":
813 with pytest.raises(ValueError):
814 assert cdb_api.add_detector(name, parent_id)
815 elif name ==
"sub_detector_id_exist":
817 with pytest.raises(ValueError):
818 assert cdb_api.add_detector(name, parent_id)
821 cdb_api.add_detector(name, parent_id)
823 if parent_id
is None:
824 tmp_det_id =
'/' + name
826 tmp_det_id = parent_id +
'/' + name
828 new_detector_id = cdb_api.get_detector(tmp_det_id)
830 assert new_detector_id[
'name'] == parent_id, \
831 "detector name should be equal to parent_id when the inserted detector id is empty"
833 assert new_detector_id[
'name'] == name, \
834 "detector name should be equal to the inserted detector id"
837@pytest.mark.parametrize(
"detector_id, name, values, test_type, tag, collected_at, valid_since, valid_until", [
839 (
None,
None,
None,
None,
None,
None,
None,
None),
841 (999, 999, 999, 999, 999, 999, 999, 999),
843 (
"",
"",
"",
"",
"",
"",
"",
""),
845 (
"detector_id_exist",
"strawPositions1", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-1",
846 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
848 (
"detector_id_exist",
"condition_exist", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-55",
849 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
851 (
"detector_id_exist",
"condition_not_exist_but_tag_exist", {
"dictPar1":
"dictVal1"},
852 "calibration",
"tag",
"2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
854 (
"detector_id_exist",
"condition_exist", {
"dictPar1":
"dictVal1"},
"calibration",
"tag",
855 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
857 (
"detector_id_exist",
"strawPositions2", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-2",
858 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
860 (
"detector_id_exist",
"strawPositions3", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-3",
861 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
863 (
"detector_id_exist",
"strawPositions4", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-4",
864 datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
865 datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
866 datetime.datetime(2020, 4, 10, 11, 5, 27, 767563)),
868 (
"detector_id_exist",
"strawPositions5", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-5",
869 datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
870 datetime.datetime(2020, 3, 12, 11, 5, 27, 767563),
871 datetime.datetime(2020, 2, 10, 11, 5, 27, 767563)),
873 (
"detector_id_not_exist",
"strawPositions6", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-6",
874 "2020-03-12 11:05:27",
"2020-03-12 11:05:27",
"2020-04-10 11:05:27"),
876 (
"detector_id_exist",
"strawPositions1", {
"dictPar1":
"dictVal1"},
"calibration",
"tag-1",
879 (
"detector_id_exist",
"strawPositions1", {
"dictPar1":
"dictVal1"}, 999,
"tag-1",
880 "2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
882 (
"detector_id_exist/sub_detector_not_exist",
"strawPositions1", {
"dictPar1":
"dictVal1"},
883 "calibration",
"tag-1",
"2020-03-10 11:05:27",
"2020-03-10 11:05:27",
"2020-04-12 11:05:27"),
885 (
"detector_id_with_invalid_date_parameters",
"strawPositions1", {
"dictPar1":
"dictVal1"},
886 "calibration",
"tag-1", 999, 999, 999),
888 (
"detector_id_not_exist_with_values_none",
"strawPositions7",
None,
"calibration",
"tag-6",
889 "2020-03-12 11:05:27",
"2020-03-12 11:05:27",
"2020-04-10 11:05:27"),
891 (
"detector_id_not_exist_with_values_empty",
"strawPositions8",
"",
"calibration",
"tag-6",
892 "2020-03-12 11:05:27",
"2020-03-12 11:05:27",
"2020-04-10 11:05:27"),
895 collected_at, valid_since, valid_until):
900 :param detector_id: String identifying the detector to which the
901 condition will be added (i.e. 'muonflux/straw_tubes').
902 :param name: String specifying the name of the condition (e.g. 'strawPositions').
903 :param values: Dictionary containing the values of the condition.
904 :param test_type: String specifying the type of condition (e.g. 'calibration').
905 :param tag: String specifying a tag for the condition. Must be unique
906 for the same condition name.
907 :param collected_at: Timestamp specifying the date/time the condition
908 was acquired. Must be unique w.r.t. the condition name.
909 :param valid_since: Timestamp specifying the date/time as of when the
911 :param valid_until: Timestamp specifying the date/time the
912 condition up until the condition is valid.
915 has_correct_parameter_type =
True
916 if type(detector_id) != str
or detector_id ==
"" or type(name) != str
or name ==
"" or \
917 (type(test_type) != str
and type(test_type)
is not None)
or \
918 type(tag) != str
or tag ==
"" or values ==
"" or values
is None:
919 has_correct_parameter_type =
False
922 with pytest.raises(TypeError):
923 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
924 collected_at, valid_since, valid_until)
926 if (type(collected_at) != str
and type(collected_at) != datetime.datetime
and collected_at
is not None)
or \
927 (type(valid_since) != str
and type(valid_since) != datetime.datetime
and valid_since
is not None)
or \
928 (type(valid_until) != str
and type(valid_until) != datetime.datetime
and valid_until
is not None):
929 has_correct_parameter_type =
False
931 with pytest.raises(TypeError):
932 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
933 collected_at, valid_since, valid_until)
935 if (type(collected_at) == str
or type(valid_until) == str
or type(valid_since) == str)
and \
936 has_correct_parameter_type:
941 has_correct_parameter_type =
False
942 with pytest.raises(ValueError):
943 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
944 collected_at, valid_since, valid_until)
947 if (type(valid_since) == datetime.datetime
and type(valid_until) == datetime.datetime)
and \
948 valid_since > valid_until:
949 has_correct_parameter_type =
False
950 with pytest.raises(ValueError):
951 assert cdb_api.add_condition(detector_id, name, tag, values, test_type, collected_at,
952 valid_since, valid_until)
955 if (type(valid_since) == str
and type(valid_until) == str)
and has_correct_parameter_type:
956 if valid_since ==
"" or valid_until ==
"":
957 has_correct_parameter_type =
False
958 with pytest.raises(ValueError):
959 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
960 collected_at, valid_since, valid_until)
964 if datetime_valid_since > datetime_valid_until:
965 has_correct_parameter_type =
False
966 with pytest.raises(ValueError):
967 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
968 collected_at, valid_since, valid_until)
971 if detector_id ==
"detector_id_not_exist" or \
972 detector_id ==
"detector_id_exist/sub_detector_not_exist":
973 has_correct_parameter_type =
False
974 with pytest.raises(ValueError):
975 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
976 collected_at, valid_since, valid_until)
979 if detector_id ==
"detector_id_exist" and name ==
"condition_exist" and tag ==
"tag":
980 has_correct_parameter_type =
False
981 with pytest.raises(ValueError):
982 assert cdb_api.add_condition(detector_id, name, tag, values, test_type,
983 collected_at, valid_since, valid_until)
985 if has_correct_parameter_type:
987 cdb_api.add_condition(detector_id, name, tag, values, test_type,
988 collected_at, valid_since, valid_until)
989 detector = cdb_api.get_detector(detector_id)
992 assert detector[
"name"] == detector_id,
"the detector has different name"
995 conditions = detector[
"conditions"]
997 for condition
in conditions:
998 if condition[
"tag"] == tag
and condition[
"name"] == name:
999 new_condition = condition
1003 assert new_condition[
"tag"] == tag,
"tag is not correct"
1006 assert new_condition[
"values"] == values,
"value is not correct"
1009 assert new_condition[
"type"] == test_type,
"type is not correct"
1012 if type(collected_at) == datetime.datetime:
1014 == collected_at.replace(microsecond=0), \
1015 "collected_at is not correct"
1016 elif type(collected_at) == str:
1019 "collected_at is not correct"
1022 if type(valid_until) == datetime.datetime:
1024 == valid_until.replace(microsecond=0), \
1025 "valid_until is not correct"
1026 elif type(valid_until) == str:
1029 "valid_until is not correct"
1032@pytest.mark.parametrize(
"detector_id, name, tag, test_type, valid_since, valid_until", [
1034 (
None,
None,
None,
None,
None,
None),
1036 (999, 999, 999, 999, 999, 999),
1038 (
"",
"",
"",
"",
"",
""),
1040 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1041 "2020-04-16 12:07:30",
"2020-04-17 12:07:30"),
1043 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1044 "2020-04-16 12:07:30:129910",
"2020-04-17 12:07:30:129910"),
1046 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1047 datetime.datetime(2020, 4, 16, 12, 7, 30),
1048 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1050 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1051 datetime.datetime(2020, 4, 16, 12, 7, 30, 129910),
1052 datetime.datetime(2020, 4, 17, 12, 7, 30, 129910)),
1054 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
"2020-04-16 12:07:30",
1055 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1057 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1058 datetime.datetime(2020, 4, 13),
"2020-04-16 12:07:30"),
1060 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
"2020-24-16 12:07:30",
1061 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1063 (
"detector_id_exist",
"condition_exist",
"tag",
"type",
1064 datetime.datetime(2020, 4, 20, 12, 7, 30),
1065 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1067 (
"detector_id_exist", 999, 999, 999, 999, 999),
1069 (
"detector_id_not_exist",
"condition_exist",
"tag",
"type",
1070 datetime.datetime(2020, 4, 16, 12, 7, 30),
1071 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1073 (
"detector_id_exist/sub_detector_id_not_exist",
"condition_exist",
"tag",
"type",
1074 datetime.datetime(2020, 4, 16, 12, 7, 30),
1075 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1077 (
"detector_id_exist",
"condition_not_exist",
"tag",
"type",
1078 datetime.datetime(2020, 4, 16, 12, 7, 30),
1079 datetime.datetime(2020, 4, 17, 12, 7, 30)),
1082 test_type, valid_since, valid_until):
1084 test update_condition_by_name_and_tag()
1087 :param detector_id: String identifying the detector for which the
1088 condition must be retrieved (i.e. 'muonflux/straw_tubes').
1089 :param name: String specifying the name of the condition to be retrieved (e.g.
1091 :param tag: String specifying the tag of the condition to be updated.
1092 :param test_type: (optional) String specifying the type of condition (e.g. 'calibration').
1093 :param valid_since: Timestamp specifying the date/time as of when the
1094 condition is valid. Can be of type String or datetime.
1095 :param valid_until: Timestamp specifying the date/time up until the
1096 condition is valid. Can be of type String or datetime.
1098 has_correct_parameter =
True
1099 if type(detector_id) != str
or type(name) != str
or type(tag) != str
or \
1100 (type(test_type) != str
and test_type
is not None):
1101 has_correct_parameter =
False
1103 with pytest.raises(TypeError):
1104 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1105 test_type, valid_since, valid_until)
1107 if (type(valid_since) != str
and type(valid_since) != datetime.datetime
and valid_since
is not None)
or \
1108 (type(valid_until) != str
and type(valid_until) != datetime.datetime
and valid_until
is not None):
1109 has_correct_parameter =
False
1111 with pytest.raises(TypeError):
1112 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1113 test_type, valid_since, valid_until)
1116 has_correct_parameter =
False
1118 with pytest.raises(ValueError):
1119 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1120 test_type, valid_since, valid_until)
1123 has_correct_parameter =
False
1125 with pytest.raises(ValueError):
1126 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1127 test_type, valid_since, valid_until)
1129 if type(valid_since) == datetime.datetime \
1130 and type(valid_until) == datetime.datetime \
1131 and valid_since > valid_until:
1132 has_correct_parameter =
False
1134 with pytest.raises(ValueError):
1135 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1136 test_type, valid_since, valid_until)
1138 if detector_id ==
"detector_id_not_exist" \
1139 or detector_id ==
"detector_id_exist/sub_detector_id_not_exist":
1140 has_correct_parameter =
False
1142 with pytest.raises(ValueError):
1143 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1144 test_type, valid_since, valid_until)
1146 if name ==
"condition_not_exist":
1147 has_correct_parameter =
False
1149 with pytest.raises(ValueError):
1150 assert cdb_api.update_condition_by_name_and_tag(detector_id, name, tag, test_type,
1151 valid_since, valid_until)
1153 if has_correct_parameter:
1154 cdb_api.update_condition_by_name_and_tag(detector_id, name, tag,
1155 test_type, valid_since, valid_until)
1158 if detector_id ==
"detector_id_exist":
1159 result_con = cdb_api.get_condition_by_name_and_tag(detector_id, name, tag)
1160 if type(valid_since) == str:
1163 "valid_since is not updated successfully"
1164 elif type(valid_since) == datetime.datetime:
1166 valid_since.replace(microsecond=0), \
1167 "valid_since is not updated successfully"
1169 if type(valid_until) == str:
1172 "valid_until is not updated successfully"
1173 elif type(valid_until) == datetime.datetime:
1175 valid_until.replace(microsecond=0), \
1176 "valid_until is not updated successfully"
1179@pytest.mark.parametrize(
"detector_id", [
1183 "detector_id_not_exist",
1185 "detector_id_exist/sub_detector_id_exist/sub_sub_detector_id_exist",
1187 "detector_id_exist/sub_detector_id_exist",