Ejemplo n.º 1
0
def test_events_get_events(json_mock, open_mock, verify_init, process_helpers,
                           os_path_mock):
    run_id = str(uuid.uuid4())
    os_path_mock.exists.return_value = True
    json_mock_data = {
        'last_remote_container': 'gcr.io/app_name:container_id',
        'last_push_duration': 0.18889,
        'app_run_id': run_id
    }
    json_mock.load.return_value = json_mock_data

    events_command = EventsCommand({'events': True})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    head_value = "LAST SEEN   FIRST SEEN   COUNT"
    event_value = '-'.join(['app', run_id])
    process_helpers.return_value.stdout.readline.side_effect = [
        head_value, event_value, ''
    ]
    process_helpers.return_value.poll.return_value = 1
    process_helpers.return_value.stderr.readline.return_value = ''
    with catch_stdout() as caught_output:
        events_command.action()
        output = caught_output.getvalue()
    assert head_value in output
    assert event_value in output
Ejemplo n.º 2
0
def get_events(catch_exception=None, job_name=None):
    events_command = EventsCommand({'events': True, '--job-name': job_name})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    with catch_stdout() as caught_output:
        with conditional(catch_exception, pytest.raises(catch_exception)):
            events_command.action()
        output = caught_output.getvalue().strip()
    return output
Ejemplo n.º 3
0
def test_events_no_push_json_file(open_mock, verify_init, process_helpers,
                                  os_path_mock):
    os_path_mock.exists.return_value = False
    events_command = EventsCommand({'events': True})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    with catch_stdout() as caught_output:
        with pytest.raises(SystemExit):
            events_command.action()
        output = caught_output.getvalue()

    assert "This app has not been deployed yet" in output
Ejemplo n.º 4
0
def test_events_corrupted_app_run_id(json_mock, open_mock, verify_init,
                                     process_helpers, os_path_mock):
    run_id = '31dea6fc'
    os_path_mock.exists.return_value = True
    json_mock_data = {
        'last_remote_container': 'gcr.io/app_name:container_id',
        'last_push_duration': 0.18889,
        'app_run_id': run_id}
    json_mock.load.return_value = json_mock_data

    events_command = EventsCommand({'events': True})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    with catch_stdout() as caught_output:
        with pytest.raises(SystemExit):
            events_command.action()
        output = caught_output.getvalue()

    assert"Please re-deploy app again, something went wrong." in output
Ejemplo n.º 5
0
def test_events_no_resources_found(json_mock, open_mock, verify_init,
                                   process_helpers, os_path_mock):
    run_id = str(uuid.uuid4())
    os_path_mock.exists.return_value = True
    json_mock_data = {
        'last_remote_container': 'gcr.io/app_name:container_id',
        'last_push_duration': 0.18889,
        'app_run_id': run_id}
    json_mock.load.return_value = json_mock_data

    events_command = EventsCommand({'events': True})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    process_helpers.side_effect = Exception("No resources found")

    with catch_stdout() as caught_output:
        with pytest.raises(SystemExit):
            events_command.action()
        output = caught_output.getvalue()

    assert "No resources found" in output
Ejemplo n.º 6
0
def test_events_no_events_to_display(json_mock, open_mock, verify_init,
                                     process_helpers, os_path_mock):
    run_id = str(uuid.uuid4())
    os_path_mock.exists.return_value = True
    json_mock_data = {
        'last_remote_container': 'gcr.io/app_name:container_id',
        'last_push_duration': 0.18889,
        'app_run_id': run_id}
    json_mock.load.return_value = json_mock_data

    events_command = EventsCommand({'events': True})
    events_command.config = {'name': 'app', 'namespace': 'namespace'}

    head_value = "LAST SEEN   FIRST SEEN   COUNT"
    process_helpers.return_value.stdout.readline.side_effect = \
        [head_value, "current job events missing", '']
    process_helpers.return_value.poll.return_value = 1
    process_helpers.return_value.stderr.readline.return_value = ''
    with catch_stdout() as caught_output:
        events_command.action()
        output = caught_output.getvalue()

    assert "No events to display for this job" in output