Beispiel #1
0
def close_expired_jobs(notify):
    now = datetime.datetime.utcnow()
    today = now.strftime("%Y-%m-%d")

    record_json = type_coerce(RecordMetadata.json, JSONB)
    before_deadline_date = record_json["deadline_date"].astext.cast(
        DateTime) < today
    only_jobs_collection = record_json["_collections"].contains(["Jobs"])
    only_not_closed = not_(record_json["status"].astext == "closed")
    only_not_deleted = or_(
        not_(record_json.has_key("deleted")),  # noqa: W601
        not_(record_json["deleted"] == cast(True, JSONB)),
    )
    expired_jobs = RecordMetadata.query.filter(only_jobs_collection,
                                               only_not_deleted,
                                               only_not_closed,
                                               before_deadline_date).all()
    expired_job_records = [
        JobsRecord(job.json, model=job) for job in expired_jobs
    ]
    for job_record in expired_job_records:
        job_record["status"] = "closed"
        job_record.update(dict(job_record))

    db.session.commit()

    if notify:
        for job_record in expired_job_records:
            send_job_deadline_reminder(dict(job_record))

    LOGGER.info("Closed expired jobs",
                notify=notify,
                num_records=len(expired_jobs))
Beispiel #2
0
def test_dump_ref_letter_contact():
    data_to_load = {
        **DEFAULT_DATA_TO_DUMP,
        "reference_letters": {
            "emails": ["one@email", "second@email"],
            "urls": [
                {
                    "description": "Description of url",
                    "value": "http://url1"
                },
                {
                    "value": "http://url2"
                },
            ],
        },
    }

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {
        **DEFAULT_EXPECTED_DATA_AFTER_DUMP,
        "reference_letters": [
            "one@email",
            "second@email",
            "http://url1",
            "http://url2",
        ],
    }
    assert result == expected_data
Beispiel #3
0
def test_dump_required_data():
    data_to_load = {**DEFAULT_DATA_TO_DUMP}
    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {**DEFAULT_EXPECTED_DATA_AFTER_DUMP}

    assert result == expected_data
Beispiel #4
0
def test_dump_external_job_identifier():
    data_to_load = {**DEFAULT_DATA_TO_DUMP, "description": "Test 1234"}

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {
        **DEFAULT_EXPECTED_DATA_AFTER_DUMP, "description": "Test 1234"
    }

    assert result == expected_data
Beispiel #5
0
def test_dump_field_of_interest():
    data_to_load = {
        **DEFAULT_DATA_TO_DUMP,
        "arxiv_categories": ["cond-mat.dis-nn", "nlin.SI"],
    }

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {
        **DEFAULT_EXPECTED_DATA_AFTER_DUMP,
        "field_of_interest": ["cond-mat.dis-nn", "nlin.SI"],
    }

    assert result == expected_data
Beispiel #6
0
def test_jobs_serializer_should_serialize_whole_basic_record():
    schema = JobsRawSchema()
    data = {
        "$schema": "http://localhost:5000/schemas/records/jobs.json",
        "_collections": ["Jobs"],
        "deadline_date": "1996-11-15",
        "description": "Join us!",
        "position": "staff",
        "regions": ["Europe"],
        "status": "closed",
    }

    job = JobsRecord(data)
    result = schema.dump(job).data

    assert result == data
Beispiel #7
0
def test_dump_url():
    data_to_load = {
        **DEFAULT_DATA_TO_DUMP,
        "urls": [
            {
                "value": "http://url",
                "description": "some description"
            },
            {
                "value": "httpL//url2"
            },
        ],
    }

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {**DEFAULT_EXPECTED_DATA_AFTER_DUMP, "url": "http://url"}

    assert result == expected_data
Beispiel #8
0
def test_dump_contacts():
    data_to_load = {
        **DEFAULT_DATA_TO_DUMP,
        "contact_details": [
            {
                "name": "Some name",
                "email": "some@email",
                "record": {
                    "$ref": "http://"
                }
            },
            {
                "name": "other name",
                "email": "other@email",
                "curated_relation": False
            },
        ],
    }

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {
        **DEFAULT_EXPECTED_DATA_AFTER_DUMP,
        "contacts": [
            {
                "name": "Some name",
                "email": "some@email",
                "record": {
                    "$ref": "http://"
                }
            },
            {
                "name": "other name",
                "email": "other@email",
                "curated_relation": False
            },
        ],
    }

    assert result == expected_data
Beispiel #9
0
def test_dump_experiments():
    data_to_load = {
        **DEFAULT_DATA_TO_DUMP,
        "accelerator_experiments": [
            {
                "legacy_name": "Experiment Name",
                "record": {
                    "$ref": "http://ref"
                }
            },
            {
                "legacy_name": "Another Experiment Name",
                "record": {
                    "$ref": "http://ref2"
                },
            },
        ],
    }

    record = JobsRecord(data_to_load)
    result = Job().dump(record).data

    expected_data = {
        **DEFAULT_EXPECTED_DATA_AFTER_DUMP,
        "experiments": [
            {
                "legacy_name": "Experiment Name",
                "record": {
                    "$ref": "http://ref"
                }
            },
            {
                "legacy_name": "Another Experiment Name",
                "record": {
                    "$ref": "http://ref2"
                },
            },
        ],
    }

    assert result == expected_data