Пример #1
0
def public_candidate2(public_filter, user):
    obj = ObjFactory(groups=[public_filter.group])
    DBSession.add(
        Candidate(
            obj=obj,
            filter=public_filter,
            passed_at=datetime.utcnow() -
            timedelta(seconds=np.random.randint(0, 100)),
            uploader_id=user.id,
        ))
    DBSession.commit()
    return obj
Пример #2
0
def public_candidate(public_filter, user):
    obj = ObjFactory(groups=[public_filter.group])
    candidate = Candidate(
        obj=obj,
        filter=public_filter,
        passed_at=datetime.utcnow() - timedelta(seconds=np.random.randint(0, 100)),
        uploader_id=user.id,
    )
    DBSession.add(candidate)
    DBSession.commit()
    yield obj
    ObjFactory.teardown(obj)
Пример #3
0
def public_candidate_two_groups(public_filter, public_filter2, public_group,
                                public_group2, user):
    obj = ObjFactory(groups=[public_group, public_group2])
    candidates = []
    for filter_ in [public_filter, public_filter2]:
        candidate = Candidate(
            obj=obj,
            filter=filter_,
            passed_at=datetime.utcnow() -
            timedelta(seconds=np.random.randint(0, 100)),
            uploader_id=user.id,
        )
        candidates.append(candidate)
        DBSession.add(candidate)
    DBSession.commit()
    yield obj
    ObjFactory.teardown(obj)
Пример #4
0
def public_source_no_data(public_group):
    obj = Obj(
        id=str(uuid.uuid4()),
        ra=0.0,
        dec=0.0,
        redshift=0.0,
    )
    DBSession.add(obj)
    DBSession().add(ThumbnailFactory(obj_id=obj.id, type="new"))
    DBSession().add(ThumbnailFactory(obj_id=obj.id, type="ps1"))
    source = Source(obj_id=obj.id, group_id=public_group.id)
    DBSession.add(source)
    DBSession.commit()
    obj_id = obj.id
    yield obj
    # If the obj wasn't deleted by the test using it, clean up
    DBSession().expire(obj)
    if DBSession().query(Obj).filter(Obj.id == obj_id).first():
        DBSession().delete(obj)
        DBSession().commit()
Пример #5
0
def public_candidate2(public_filter):
    obj = ObjFactory(groups=[public_filter.group])
    DBSession.add(Candidate(obj=obj, filter=public_filter))
    DBSession.commit()
    return obj
Пример #6
0
def public_source_group2(public_group2):
    obj = ObjFactory(groups=[public_group2])
    DBSession.add(Source(obj_id=obj.id, group_id=public_group2.id))
    DBSession.commit()
    return obj
Пример #7
0
def public_source_two_groups(public_group, public_group2):
    obj = ObjFactory(groups=[public_group, public_group2])
    for group in [public_group, public_group2]:
        DBSession.add(Source(obj_id=obj.id, group_id=group.id))
    DBSession.commit()
    return obj
Пример #8
0
)

import astroplan

print("Loading test configuration from _test_config.yaml")
basedir = pathlib.Path(os.path.dirname(__file__))
cfg = load_config([(basedir / "../../test_config.yaml").absolute()])
set_server_url(f'http://localhost:{cfg["ports.app"]}')
print("Setting test database to:", cfg["database"])
models.init_db(**cfg["database"])

# Add a "test factory" User so that all factory-generated comments have a
# proper author, if it doesn't already exist (the user may already be in
# there if running the test server and running tests individually)
if not DBSession.query(User).filter(User.username == "test factory").scalar():
    DBSession.add(User(username="******"))
    DBSession.commit()


def pytest_runtest_setup(item):
    # Print timestamp when running each test
    print(datetime.now().strftime('[%H:%M:%S] '), end='')


# set up a hook to be able to check if a test has failed
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    # execute all other hooks to obtain the report object
    outcome = yield
    rep = outcome.get_result()
Пример #9
0
    AllocationFactory,
    InvitationFactory,
    NotificationFactory,
    UserNotificationFactory,
    ThumbnailFactory,
    GcnFactory,
)
from skyportal.tests.fixtures import TMP_DIR  # noqa: F401
from skyportal.models import Obj

# Add a "test factory" User so that all factory-generated comments have a
# proper author, if it doesn't already exist (the user may already be in
# there if running the test server and running tests individually)
if (not DBSession().execute(
        sa.select(User).filter(User.username == "test factory")).scalar()):
    DBSession.add(User(username="******"))
    DBSession.commit()

# Also add the test driver user (testuser-cesium-ml-org) if needed so that the driver
# fixture has a user to login as (without needing an invitation token).
# With invitations enabled on the test configs, the driver fails to login properly
# without this user because the authenticator looks for the user or an
# invitation token when neither exists initially on fresh test databases.
if (not DBSession().execute(
        sa.select(User).filter(
            User.username == "testuser-cesium-ml-org")).scalar()):
    DBSession.add(
        User(username="******",
             oauth_uid="*****@*****.**"))
    DBSession.commit()
Пример #10
0
def public_candidate(public_filter):
    obj = ObjFactory()
    DBSession.add(Candidate(obj=obj, filter=public_filter))
    DBSession.commit()
    return obj
Пример #11
0
def public_source(public_group):
    obj = ObjFactory()
    DBSession.add(Source(obj_id=obj.id, group_id=public_group.id))
    DBSession.commit()
    return obj