diff --git a/scripts/beam.py b/scripts/beam.py new file mode 100644 index 0000000000000000000000000000000000000000..a005e6343aded362cfc3af07d7cd3640ab5c20ac --- /dev/null +++ b/scripts/beam.py @@ -0,0 +1,15 @@ +def calc_beam(name): + # the beam number can be found by parsing the number in the string pattern "_B012." + beam = 0 + try: + position = name.find("_B") + if position>=0: + beam_string = name[position:position+6] + if beam_string.find(".") == 5: + beam = int(beam_string[2:5]) + + return beam + except: + pass + + return 0 \ No newline at end of file diff --git a/scripts/convert_alta_to_adex_cache_django.py b/scripts/convert_alta_to_adex_cache_django.py index 84c0e1aa5b4699536ecacfcbfaf3828dd5179f3b..65b0a9d3b3924ec898e754952cf94e2a899ad5ae 100644 --- a/scripts/convert_alta_to_adex_cache_django.py +++ b/scripts/convert_alta_to_adex_cache_django.py @@ -6,6 +6,8 @@ from psycopg2 import Error import argparse import sql_scripts +from scripts.beam import calc_beam + def parse_database_url(url): # parse database url like: postgres:postgres@localhost:5432/altadb_1sept2022 @@ -26,24 +28,6 @@ def parse_database_url(url): return user, password, host, database, db_port - -def calc_beam(name): - # the beam number can be found by parsing the number in the string pattern "_B012." - beam = 0 - try: - position = name.find("_B") - if position>=0: - beam_string = name[position:position+6] - if beam_string.find(".") == 5: - beam = int(beam_string[2:5]) - - return beam - except: - pass - - return 0 - - # conversion algorithm to extract a bit more metadata from an ALTA record def convert_dataproduct(row): name, pid, access_url, ra, dec, dt, dst, observation = row diff --git a/scripts/convert_alta_to_adex_cache_fastapi.py b/scripts/convert_alta_to_adex_cache_fastapi.py index 2bcb2bfb415e42ce93149d107da42217cf4dc138..7d6fa69fdf4f9ade6901255e059d7d1beb800adb 100644 --- a/scripts/convert_alta_to_adex_cache_fastapi.py +++ b/scripts/convert_alta_to_adex_cache_fastapi.py @@ -6,6 +6,8 @@ from psycopg2 import Error import argparse import sql_scripts +from scripts.beam import calc_beam + def parse_database_url(url): @@ -27,24 +29,6 @@ def parse_database_url(url): return user, password, host, database, db_port - -def calc_beam(name): - # the beam number can be found by parsing the number in the string pattern "_B012." - beam = 0 - try: - position = name.find("_B") - if position>=0: - beam_string = name[position:position+6] - if beam_string.find(".") == 5: - beam = int(beam_string[2:5]) - - return beam - except: - pass - - return 0 - - # conversion algorithm to extract a bit more metadata from an ALTA record def convert_dataproduct(row): name, pid, access_url, ra, dec, dt, dst, observation = row diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test.py b/tests/test.py deleted file mode 100644 index 2563626b27a291adfe7470d7339dc72d452b183f..0000000000000000000000000000000000000000 --- a/tests/test.py +++ /dev/null @@ -1,9 +0,0 @@ -import unittest -from scraper.adex_io import ADEX -class TestConnectors(unittest.TestCase): - - def test_connector(self): - pass - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/test_beam.py b/tests/test_beam.py new file mode 100644 index 0000000000000000000000000000000000000000..fa028bf3cde959d3315796a782b960cf94109744 --- /dev/null +++ b/tests/test_beam.py @@ -0,0 +1,20 @@ +import unittest + +from scripts.beam import calc_beam + + +class TestBeam(unittest.TestCase): + def test_calc_beam_no_beam_number_at_all(self): + actual = calc_beam("abc") + expected = 0 + self.assertEqual(actual, expected) + + def test_calc_beam_no_beam_number_but_partial_match_no_dot(self): + actual = calc_beam("_BXXXXX") + expected = 0 + self.assertEqual(actual, expected) + + def test_calc_beam_valid_beam_number(self): + actual = calc_beam("_B099.") + expected = 99 + self.assertEqual(actual, expected) \ No newline at end of file diff --git a/tests/test_connectors_postgres.py b/tests/test_connectors_postgres.py new file mode 100644 index 0000000000000000000000000000000000000000..39504d569cea7a66601ff0f2d9ee8d4951143249 --- /dev/null +++ b/tests/test_connectors_postgres.py @@ -0,0 +1,35 @@ +import types +import unittest +from scraper.postgres.connectors.apertif import Inspectionplots + + +class TestConnectorPostgresApertif(unittest.TestCase): + def test_translate(self): + connector = Inspectionplots() + + name = 'my_name' + pid = 5 + url = 'some_access_url' + dataset_id = 23 + + row = (name, pid, url, '', '', dataset_id) + + args_collection = [1, 2, 3] + args = types.SimpleNamespace(collection=args_collection) + + actual = connector.translate(row=row, args=args) + + expected = { + 'pid': pid, + 'name': name, + 'dp_type': 'diagnostic_plots', + 'format': 'png', + 'locality': 'online', + 'access_url': url, + 'dataset_id': str(dataset_id), + 'parent': None, + 'collection': args_collection, + } + + self.assertDictEqual(actual, expected) + diff --git a/tests/test_connectors_vo.py b/tests/test_connectors_vo.py new file mode 100644 index 0000000000000000000000000000000000000000..ea5dad4d416fe326664b433503d1497ee83ab117 --- /dev/null +++ b/tests/test_connectors_vo.py @@ -0,0 +1,16 @@ +import unittest + + +# TODO: implement +class TestConnectorVOApertif(unittest.TestCase): + pass + + +# TODO: implement +class TestConnectorVOFocus(unittest.TestCase): + pass + + +# TODO: implement +class TestConnectorVOLotssDR2(unittest.TestCase): + pass