File: test_utils.py

package info (click to toggle)
awscli 2.31.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156,692 kB
  • sloc: python: 213,816; xml: 14,082; makefile: 189; sh: 178; javascript: 8
file content (61 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from prompt_toolkit.application import Application
from prompt_toolkit.layout import Layout

from awscli.customizations.wizard.app import WizardTraverser
from awscli.customizations.wizard.ui.utils import (
    get_ui_control_by_buffer_name,
    move_to_previous_prompt,
)
from awscli.testutils import mock, unittest


class TestGetUIControlByName(unittest.TestCase):
    def test_get_ui_control_by_name(self):
        layout = mock.Mock(Layout)
        desired_ui_control = mock.Mock()
        desired_ui_control.buffer.name = 'desired-buffer'
        other_ui_control = mock.Mock()
        other_ui_control.buffer.name = 'different-name'
        layout.find_all_controls.return_value = [
            object(),  # Does not have a buffer property
            other_ui_control,
            desired_ui_control,
        ]
        self.assertIs(
            get_ui_control_by_buffer_name(layout, 'desired-buffer'),
            desired_ui_control,
        )

    def test_raises_error_when_no_matching_ui_control_found(self):
        layout = mock.Mock(Layout)
        layout.find_all_controls.return_value = []
        with self.assertRaises(ValueError):
            get_ui_control_by_buffer_name(layout, 'buffer-does-not-exist')


class TestMoveToPreviousPrompt(unittest.TestCase):
    def test_move_to_previous_prompt(self):
        app = mock.Mock(Application)
        app.layout = mock.Mock(Layout)
        previous_control = mock.Mock()
        previous_control.buffer.name = 'previous'
        app.layout.find_all_controls.return_value = [
            previous_control,
        ]
        app.traverser = mock.Mock(WizardTraverser)
        app.traverser.previous_prompt.return_value = 'previous'

        move_to_previous_prompt(app)
        app.layout.focus.assert_called_with(previous_control)