Beispiel #1
0
def test_print_workstatus_old_task_subtasks(caplog):
    session = Session(load_questions=False)
    session.stale_timeout = 5
    nowFunction = lambda tzinfo: datetime.datetime(
        2017, 12, 20, 0, 0, 0, 0, tzinfo=tzinfo
    )
    workStatus = "TEST"
    taskDetails = json.dumps(
        {
            "obtained": "2016-11-22 10:43:21 UTC",
            "batches": [
                {
                    "completed": 1,
                    "description": "Fooing the bar",
                    "size": 2,
                    "startDate": "2016-11-22 10:43:22 UTC",
                }
            ],
        }
    )
    _print_work_status_helper(session, workStatus, taskDetails, nowFunction)
    assert "status: TEST" in caplog.text
    assert (
        ".... {obtained} Fooing the bar 1 / 2. (1y27d13:16:39 elapsed)".format(
            obtained=_print_timestamp(
                _parse_timestamp(json.loads(taskDetails)["obtained"])
            )
        )
        in caplog.text
    )
Beispiel #2
0
def test_print_workstatus_fresh_task(caplog):
    session = Session(load_questions=False)
    session.stale_timeout = 5
    nowFunction = lambda tzinfo: datetime.datetime(
        2017, 12, 20, 0, 0, 0, 0, tzinfo=tzinfo
    )
    workStatus = "TEST"
    taskDetails = json.dumps(
        {
            "obtained": "2017-12-20 00:00:00 UTC",
            "batches": [
                {
                    "completed": 0,
                    "description": "Fooing the bar",
                    "size": 0,
                    "startDate": "2017-12-20 00:00:00 UTC",
                }
            ],
        }
    )
    _print_work_status_helper(session, workStatus, taskDetails, nowFunction)
    assert "status: TEST" in caplog.text
    assert (
        ".... {obtained} Fooing the bar".format(
            obtained=_print_timestamp(
                _parse_timestamp(json.loads(taskDetails)["obtained"])
            )
        )
        in caplog.text
    )
Beispiel #3
0
def test_print_workstatus_old_task(logger, caplog):
    session = Session(logger)
    session.stale_timeout = 5
    nowFunction = lambda tzinfo: datetime.datetime(2017, 12, 20, 0, 0, 0, 0,
                                                   tzinfo=tzinfo)
    workStatus = "TEST"
    taskDetails = json.dumps({
        "obtained": "2017-12-20 00:00:00 UTC",
        "batches": [{
            "completed": 0,
            "description": "Fooing the bar",
            "size": 0,
            "startDate": "2016-11-22 10:43:21 UTC"
        }]
    })
    _print_work_status(session, workStatus, taskDetails, nowFunction)
    assert "status: TEST" in caplog.text
    assert ".... {obtained} Fooing the bar Elapsed 1y27d13:16:39".format(
        obtained=_print_timestamp(
            _parse_timestamp(json.loads(taskDetails)["obtained"]))) \
           in caplog.text
Beispiel #4
0
def test_parse_rfc3339_timestamp():
    s = '2017-11-29T18:51:23.456+0000'
    ref = datetime.datetime(2017, 11, 29, 18, 51, 23, 456000, tzinfo=UTC)
    assert _parse_timestamp(s) == ref
Beispiel #5
0
def test_parse_numeric_timestamp():
    # When older versions of Batfish sent numeric timestamps, they were in
    # server's local time.
    s = '1511981483456'
    ref = datetime.datetime(2017, 11, 29, 18, 51, 23, 456000)
    assert _parse_timestamp(s) == ref