Beispiel #1
0
async def test_restrictions_screen_on_body(restrictions_modal):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_

        return MockTarget()

    event = Event('Mouse', 'click')
    event.target = target(None)

    restrictions_modal.build()
    await restrictions_modal.on_body(event)
    assert restrictions_modal.modal is None

    event.target = target({
        'id': '',
        'resource': '',
        'privilege': '',
        'active': ''
    })

    await restrictions_modal.on_body(event)
    await asyncio.sleep(0)

    assert restrictions_modal.modal is not None
Beispiel #2
0
async def test_application_on_menu_click(application):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_
        return MockTarget()

    event = Event('Mouse', 'click')

    application.build()

    event.target = target({'tag': 'users'})
    await application.on_menu_click(event)

    assert type(application.body.children[0]).__name__ == 'UsersScreen'

    event.target = target({'tag': 'roles'})
    await application.on_menu_click(event)

    assert type(application.body.children[0]).__name__ == 'RolesScreen'

    event.target = target({'tag': 'dominions'})
    await application.on_menu_click(event)

    assert type(application.body.children[0]).__name__ == 'DominionsScreen'

    event.target = target({'tag': 'other'})
    await application.on_menu_click(event)
    await asyncio.sleep(0)
    assert type(application.body.children[0]).__name__ == 'DominionsScreen'
Beispiel #3
0
async def test_users_screen_on_body(users_screen):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_

        return MockTarget()

    event = Event('Mouse', 'click')
    event.target = target(None)

    await users_screen.on_body(event)
    assert users_screen.modal is None

    event.target = target({
        'id': '1',
        'name': '',
        'username': '',
        'email': '',
        'attributes': {}
    })

    await users_screen.on_body(event)
    await asyncio.sleep(0)

    assert users_screen.modal is not None
Beispiel #4
0
async def test_roles_screen_on_body(roles_screen):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_
        return MockTarget()

    event = Event('Mouse', 'click')
    event.target = target(None)

    await roles_screen.on_body(event)
    assert roles_screen.modal is None

    event.target = target({'id': '1', 'name': 'admin',
                           'dominion_id': '1', 'description': ''})

    await roles_screen.on_body(event)
    await asyncio.sleep(0)

    assert roles_screen.modal is not None
Beispiel #5
0
async def test_dominions_screen_on_body(dominions_screen):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_

        return MockTarget()

    event = Event('Mouse', 'click')
    event.target = target(None)

    await dominions_screen.on_body(event)
    assert dominions_screen.modal is None

    event.target = target({'name': ''})

    await dominions_screen.on_body(event)
    await asyncio.sleep(0)

    assert dominions_screen.modal is not None
Beispiel #6
0
async def test_users_selection_modal_on_select(users_selection_modal):
    def target(item_):
        class MockTarget:
            class parent:
                item = item_

            def focus(self):
                pass
        return MockTarget()

    users_selection_modal.connect()
    event = Event('Mouse', 'click')
    event.target = target({'id': '1', 'username': '******',
                           'email': '[email protected]'})

    await users_selection_modal.on_select(event)
    await asyncio.sleep(0)

    assert users_selection_modal.focused == {
        'id': '1', 'username': '******',
        'email': '[email protected]'}
Beispiel #7
0
async def test_dominions_modal_on_body(dominions_modal):
    given_details = None

    async def mock_done(self, details):
        nonlocal given_details
        given_details = details

    dominions_modal.connect()
    dominions_modal.done = MethodType(mock_done, dominions_modal)

    def target(item_):
        class MockTarget:
            class parent:
                item = item_
        return MockTarget()

    event = Event('Mouse', 'click')
    event.target = target({'id': '1', 'name': 'Dominion'})

    await dominions_modal.on_body(event)
    await asyncio.sleep(0)

    assert given_details == {'id': '1', 'name': 'Dominion'}