Пример #1
0
def test_purge_progress_when_already_empty_in_body_but_not_in__patch(handler):
    body = {}
    patch = {'status': {'kopf': {'progress': {'some-id': {'retries': 5}}}}}
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    state.purge(patch=patch, body=body)
    assert not patch
    assert body == origbody  # not modified
Пример #2
0
def test_purge_progress_when_already_empty_in_body_and_patch(handler):
    body = {}
    patch = {}
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    state.purge(patch=patch, body=body)
    assert not patch
    assert body == origbody  # not modified
Пример #3
0
def test_purge_progress_when_exists_in_body(handler):
    body = {'status': {'kopf': {'progress': {'some-id': {'retries': 5}}}}}
    patch = {}
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    state.purge(patch=patch, body=body)
    assert patch == {'status': {'kopf': {'progress': None}}}
    assert body == origbody  # not modified
Пример #4
0
def test_always_started_when_created_from_body(handler, body, expected):
    origbody = copy.deepcopy(body)
    patch = {}
    state = State.from_body(body=body, handlers=[handler])
    state.store(patch=patch)
    assert patch['status']['kopf']['progress']['some-id'][
        'started'] == expected
    assert body == origbody  # not modified
Пример #5
0
def test_set_awake_time(handler, expected, body, delay):
    origbody = copy.deepcopy(body)
    patch = {}
    state = State.from_body(body=body, handlers=[handler])
    state = state.with_outcomes(
        outcomes={handler.id: HandlerOutcome(final=False, delay=delay)})
    state.store(patch=patch)
    assert patch['status']['kopf']['progress']['some-id'].get(
        'delayed') == expected
    assert body == origbody  # not modified
Пример #6
0
def test_store_success(handler, expected_retries, expected_stopped, body):
    origbody = copy.deepcopy(body)
    patch = {}
    state = State.from_body(body=body, handlers=[handler])
    state = state.with_outcomes(
        outcomes={handler.id: HandlerOutcome(final=True)})
    state.store(patch=patch)
    assert patch['status']['kopf']['progress']['some-id']['success'] is True
    assert patch['status']['kopf']['progress']['some-id']['failure'] is False
    assert patch['status']['kopf']['progress']['some-id'][
        'retries'] == expected_retries
    assert patch['status']['kopf']['progress']['some-id'][
        'stopped'] == expected_stopped
    assert patch['status']['kopf']['progress']['some-id']['message'] is None
    assert body == origbody  # not modified
Пример #7
0
def test_get_retry_count(handler, expected, body):
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    result = state[handler.id].retries
    assert result == expected
    assert body == origbody  # not modified
Пример #8
0
def test_awakening_time(handler, expected, body):
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    result = state[handler.id].delayed
    assert result == expected
    assert body == origbody  # not modified
Пример #9
0
def test_sleeping_flag(handler, expected, body):
    origbody = copy.deepcopy(body)
    state = State.from_body(body=body, handlers=[handler])
    result = state[handler.id].sleeping
    assert result == expected
    assert body == origbody  # not modified