def test_handle_s3_object_created_only_jpg(): add_10jpg() with get_session(db_address=DB_ADDRESS) as session: entry = session.query(Image)\ .filter(Image.base_filename==TEST_BASE_FILENAME)\ .one() assert entry.jpg_medium_exists and not entry.header
def test_header_data_exists_includes_header(setup_teardown): # Create new db entry with get_session(db_address=DB_ADDRESS) as session: new_image = Image(base_filename=TEST_BASE_FILENAME, site="tst", data_type="EX") session.add(new_image) session.commit() # Example header we'll use header = { "JSON": 'some data', "OBJCTRA": 12.34, "OBJCTDEC": 56.78, "ALTITUDE": 12.34, "AZIMUTH": 56.78, "FILTER": 'test_filter', "AIRMASS": 1.234, "EXPTIME": 1, "USERID": 'test_userid', "USERNAME": '******', "DATE-OBS": '2021-01-01T12:34.54' } # Add simple header contents update_header_data(DB_ADDRESS, TEST_BASE_FILENAME, 'EX', header) assert header_data_exists(DB_ADDRESS, TEST_BASE_FILENAME)
def test_handle_s3_object_created_all_files(): add_header() add_10jpg() add_01fits() add_10fits() with get_session(db_address=DB_ADDRESS) as session: entry = session.query(Image)\ .filter(Image.base_filename==TEST_BASE_FILENAME)\ .one() assert entry.fits_10_exists and entry.header
def test_header_data_exists_no_header(setup_teardown): # Create new db entry with get_session(db_address=DB_ADDRESS) as session: new_image = Image(base_filename=TEST_BASE_FILENAME, site="tst", data_type="EX") session.add(new_image) session.commit() # Should not have a header entry yet assert not header_data_exists(DB_ADDRESS, TEST_BASE_FILENAME)
def test_db_remove_base_filename(setup_teardown): # Create new db entry with get_session(db_address=DB_ADDRESS) as session: new_image = Image(base_filename=TEST_BASE_FILENAME, site="tst", data_type="EX") session.add(new_image) session.commit() # Verify entry exists with get_session(db_address=DB_ADDRESS) as session: assert session.query(Image.image_id)\ .filter_by(base_filename=TEST_BASE_FILENAME)\ .scalar() is not None # Remove the entry db_remove_base_filename(TEST_BASE_FILENAME) # Verify entry no longer exists with get_session(db_address=DB_ADDRESS) as session: assert session.query(Image.image_id)\ .filter_by(base_filename=TEST_BASE_FILENAME)\ .scalar() is None
def delete_test_entries(base_filename): with get_session(db_address=DB_ADDRESS) as session: s = session.query(Image).filter( Image.base_filename == base_filename).delete()