Exemplo n.º 1
0
def test_get():
    """Verify that a menu item can be correctly retrieved."""
    expected_name = 'Name2'
    expected_short_description = 'ShortDescription2'
    expected_icon = 'Icon2'
    expected_url = 'index'
    url_name = 'index'
    reversed_url = reverse(url_name)
    expected_order = 2
    menu = Menu('menu-test',
                expected_name,
                expected_short_description,
                expected_icon,
                url_name,
                order=expected_order,
                advanced=True)
    actual_item = menu.get(expected_url)

    assert actual_item is not None
    assert expected_name == actual_item.name
    assert expected_short_description == actual_item.short_description
    assert expected_icon == actual_item.icon
    assert reversed_url == actual_item.url
    assert expected_order == actual_item.order
    assert actual_item.advanced
    assert not actual_item.items
Exemplo n.º 2
0
def build_menu(size=5):
    """Build a menu with the specified number of items."""
    random.seed()

    menu = Menu('menu-index', url_name='index')

    for index in range(1, size + 1):
        kwargs = {
            'component_id': 'menu-test-' + str(index),
            'name': 'Name' + str(index),
            'short_description': 'ShortDescription' + str(index),
            'icon': 'Icon' + str(index),
            'url_name': 'test',
            'url_kwargs': {
                'a': index,
                'b': index,
                'c': index
            },
            'parent_url_name': 'index',
            'order': random.randint(0, 1000),
        }

        Menu(**kwargs)

    return menu
Exemplo n.º 3
0
def test_menu_creation_with_arguments():
    """Verify the Menu state with initialization parameters."""
    expected_name = 'Name'
    expected_short_description = 'ShortDescription'
    expected_icon = 'Icon'
    url_name = 'test'
    url_kwargs = {'a': 1, 'b': 2, 'c': 3}
    expected_url = reverse(url_name, kwargs=url_kwargs)
    expected_order = 42
    parent_menu = Menu('menu-index', url_name='index')
    menu = Menu('menu-test',
                expected_name,
                expected_short_description,
                expected_icon,
                url_name,
                url_kwargs=url_kwargs,
                parent_url_name='index',
                order=expected_order,
                advanced=True)

    assert len(parent_menu.items) == 1
    assert parent_menu.items[0] == menu
    assert expected_name == menu.name
    assert expected_short_description == menu.short_description
    assert expected_icon == menu.icon
    assert expected_url == menu.url
    assert expected_order == menu.order
    assert menu.advanced
    assert not menu.items
Exemplo n.º 4
0
    def test_get_with_item_not_found(self):
        """Verify that a KeyError is raised if a menu item is not found."""
        expected_label = "Label3"
        expected_icon = "Icon3"
        expected_url = "index"
        expected_order = 3
        menu = Menu()
        menu.add_item(expected_label, expected_icon, expected_url, expected_order)

        self.assertRaises(KeyError, menu.get, expected_url)
Exemplo n.º 5
0
    def test_get_with_item_not_found(self):
        """Verify that a KeyError is raised if a menu item is not found."""
        expected_label = 'Label3'
        expected_icon = 'Icon3'
        expected_url = 'index'
        expected_order = 3
        menu = Menu()
        menu.add_item(expected_label, expected_icon, expected_url,
                      expected_order)

        self.assertRaises(KeyError, menu.get, expected_url)
Exemplo n.º 6
0
 def build_menu(self, size=5):
     """Build a menu with the specified number of items."""
     random.seed()
     item_data = []
     for index in range(1, size + 1):
         item_data.append(['Item' + str(index),
                           'Icon' + str(index),
                           URL_TEMPLATE.format(index, index, index),
                           random.randint(0, 1000)])
     menu = Menu()
     for data in item_data:
         menu.add_item(data[0], data[1], data[2], data[3])
     return menu
Exemplo n.º 7
0
 def build_menu(self, size=5):
     """Build a menu with the specified number of items."""
     random.seed()
     item_data = []
     for index in range(1, size + 1):
         item_data.append([
             'Item' + str(index), 'Icon' + str(index),
             URL_TEMPLATE.format(index, index, index),
             random.randint(0, 1000)
         ])
     menu = Menu()
     for data in item_data:
         menu.add_item(data[0], data[1], data[2], data[3])
     return menu
Exemplo n.º 8
0
def test_menu_creation_without_arguments():
    """Verify the Menu state without initialization parameters."""
    with pytest.raises(ValueError):
        Menu('menu-test')

    menu = Menu('menu-index', url_name='index')
    assert menu.component_id == 'menu-index'
    assert menu.name is None
    assert menu.short_description is None
    assert menu.icon is None
    assert menu.url == '/'
    assert menu.order == 50
    assert not menu.advanced
    assert not menu.items
Exemplo n.º 9
0
    def test_add_item(self):
        """Verify that a menu item can be correctly added."""
        expected_label = 'Label3'
        expected_icon = 'Icon3'
        expected_url = '/ggg/hhh/iii/'
        expected_order = 3
        menu = Menu()
        actual_item = menu.add_item(expected_label, expected_icon,
                                    expected_url, expected_order)

        self.assertIsNotNone(actual_item)
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 10
0
def test_get_with_item_not_found():
    """Verify that a KeyError is raised if a menu item is not found."""
    expected_name = 'Name3'
    expected_short_description = 'ShortDescription3'
    expected_icon = 'Icon3'
    url_name = 'index'
    expected_order = 3
    menu = Menu('menu-test',
                expected_name,
                expected_short_description,
                expected_icon,
                url_name,
                order=expected_order)

    with pytest.raises(KeyError):
        menu.get('apps')
Exemplo n.º 11
0
    def test_add_item(self):
        """Verify that a menu item can be correctly added."""
        expected_label = 'Label3'
        expected_icon = 'Icon3'
        expected_url = '/ggg/hhh/iii/'
        expected_order = 3
        menu = Menu()
        actual_item = menu.add_item(expected_label, expected_icon,
                                    expected_url, expected_order)

        self.assertIsNotNone(actual_item)
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 12
0
    def test_get(self):
        """Verify that a menu item can be correctly retrieved."""
        expected_label = 'Label2'
        expected_icon = 'Icon2'
        expected_url = '/ddd/eee/fff/'
        expected_order = 2
        menu = Menu()
        menu.add_item(expected_label, expected_icon, expected_url,
                      expected_order)
        actual_item = menu.get(expected_url)

        self.assertIsNotNone(actual_item)
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 13
0
    def test_get(self):
        """Verify that a menu item can be correctly retrieved."""
        expected_label = 'Label2'
        expected_icon = 'Icon2'
        expected_url = '/ddd/eee/fff/'
        expected_order = 2
        menu = Menu()
        menu.add_item(expected_label, expected_icon, expected_url,
                      expected_order)
        actual_item = menu.get(expected_url)

        self.assertIsNotNone(actual_item)
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 14
0
    def test_add_item(self):
        """Verify that a menu item can be correctly added."""
        expected_label = "Label5"
        expected_icon = "Icon5"
        expected_url = "/jjj/kkk/lll/"
        expected_order = 5
        menu = Menu()
        actual_item = menu.add_item(expected_label, expected_icon, expected_url, expected_order)

        self.assertEqual(1, len(menu.items))
        self.assertIsNotNone(actual_item)
        self.assertEqual(actual_item, menu.items[0])
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 15
0
    def test_get(self):
        """Verify that a menu item can be correctly retrieved."""
        expected_label = "Label2"
        expected_icon = "Icon2"
        expected_url = "index"
        reversed_url = reverse(expected_url)
        expected_order = 2
        menu = Menu()
        menu.add_item(expected_label, expected_icon, reversed_url, expected_order)
        actual_item = menu.get(expected_url)

        self.assertIsNotNone(actual_item)
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(reversed_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 16
0
 def test_menu_creation_without_arguments(self):
     """Verify the Menu state without initialization parameters."""
     menu = Menu()
     self.assertEqual('', menu.label)
     self.assertEqual('', menu.icon)
     self.assertEqual('#', menu.url)
     self.assertEqual(50, menu.order)
     self.assertEqual(0, len(menu.items))
Exemplo n.º 17
0
    def test_add_item(self):
        """Verify that a menu item can be correctly added."""
        expected_label = 'Label5'
        expected_icon = 'Icon5'
        expected_url = '/jjj/kkk/lll/'
        expected_order = 5
        menu = Menu()
        actual_item = menu.add_item(expected_label, expected_icon,
                                    expected_url, expected_order)

        self.assertEqual(1, len(menu.items))
        self.assertIsNotNone(actual_item)
        self.assertEqual(actual_item, menu.items[0])
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(expected_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 18
0
    def test_add_urlname(self):
        """Verify that a named URL can be added to a menu correctly."""
        expected_label = "Label4"
        expected_icon = "Icon4"
        expected_url = "index"
        reversed_url = reverse(expected_url)
        expected_order = 4
        menu = Menu()
        actual_item = menu.add_urlname(expected_label, expected_icon, expected_url, expected_order)

        self.assertEqual(1, len(menu.items))
        self.assertIsNotNone(actual_item)
        self.assertEqual(actual_item, menu.items[0])
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(reversed_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 19
0
    def test_add_urlname(self):
        """Verify that a named URL can be added to a menu correctly."""
        expected_label = 'Label4'
        expected_icon = 'Icon4'
        expected_url = 'index'
        reversed_url = reverse(expected_url)
        expected_order = 4
        menu = Menu()
        actual_item = menu.add_urlname(expected_label, expected_icon,
                                       expected_url, expected_order)

        self.assertEqual(1, len(menu.items))
        self.assertIsNotNone(actual_item)
        self.assertEqual(actual_item, menu.items[0])
        self.assertEqual(expected_label, actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(reversed_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 20
0
    def test_add_urlname(self):
        """Verify that a named URL can be added to a menu correctly."""
        expected_title = 'Label4'
        expected_short_description = 'Description4'
        expected_icon = 'Icon4'
        expected_url = 'index'
        reversed_url = reverse(expected_url)
        expected_order = 4
        menu = Menu()
        actual_item = menu.add_urlname(expected_title, expected_icon,
                                       expected_url, expected_short_description, expected_order)

        self.assertEqual(1, len(menu.items))
        self.assertIsNotNone(actual_item)
        self.assertEqual(actual_item, menu.items[0])
        self.assertEqual('Description4 (Label4)', actual_item.label)
        self.assertEqual(expected_icon, actual_item.icon)
        self.assertEqual(reversed_url, actual_item.url)
        self.assertEqual(expected_order, actual_item.order)
        self.assertEqual(0, len(actual_item.items))
Exemplo n.º 21
0
    def test_menu_creation_with_arguments(self):
        """Verify the Menu state with initialization parameters."""
        expected_label = 'Label'
        expected_icon = 'Icon'
        expected_url = '/aaa/bbb/ccc/'
        expected_order = 42
        menu = Menu(expected_label, expected_icon, expected_url,
                    expected_order)

        self.assertEqual(expected_label, menu.label)
        self.assertEqual(expected_icon, menu.icon)
        self.assertEqual(expected_url, menu.url)
        self.assertEqual(expected_order, menu.order)
        self.assertEqual(0, len(menu.items))
Exemplo n.º 22
0
config_dir = None
data_dir = None
store_file = None
actions_dir = None
doc_dir = None
status_log_file = None
access_log_file = None
host = None
port = None
use_x_forwarded_host = False
secure_proxy_ssl_header = None
debug = False
server_dir = '/'
danube_edition = False

main_menu = Menu()

config_file = None

DEFAULT_CONFIG_FILE = '/etc/plinth/plinth.config'
DEFAULT_ROOT = '/'


def get_config_file():
    """Return the configuration file to read."""
    if os.path.isfile(DEFAULT_CONFIG_FILE):
        root_directory = DEFAULT_ROOT
        file_path = DEFAULT_CONFIG_FILE
    else:
        root_directory = os.path.dirname(os.path.realpath(__file__))
        root_directory = os.path.join(root_directory, '..')