Exemple #1
0
    def test_02_items_states(self):
        print("---")

        items_states = ElementState()
        assert items_states.object_types_states
        assert items_states.default_states
        assert items_states.states
        print("Objects types and states", items_states.object_types_states)
        print("Default states", items_states.default_states)
        print("Items states", items_states.states)

        assert items_states.get_objects_types()
        print("All objects types : ", items_states.get_objects_types())

        assert items_states.get_icon_states()
        print("All objects : ", items_states.get_icon_states())

        assert items_states.get_default_states()
        print("Default states : ", items_states.get_default_states())

        # Objects known states
        for object_type in items_states.object_types_states:
            assert items_states.get_icon_states(object_type)
            print(object_type, ", all states: ",
                  items_states.get_icon_states(object_type))
            for state in items_states.get_icon_states(object_type):
                assert items_states.get_icon_state(object_type, state)
                print(object_type, ", state: ", state, ": ",
                      items_states.get_icon_state(object_type, state))

        assert not items_states.get_icon_state(None, None)

        # Default states are in all objects types
        for state in items_states.get_default_states():
            print("Default state: ", state)
            for object_type in items_states.object_types_states:
                assert items_states.get_icon_states(object_type)
    def test_items_states_2(self):
        """ Items - states (2) """

        items_states = ElementState()
        assert items_states.object_types_states
        assert items_states.default_states
        assert items_states.states
        print("Objects types and states", items_states.object_types_states)
        print("Default states", items_states.default_states)
        print("Items states", items_states.states)

        assert items_states.get_objects_types()
        print("All objects types : ", items_states.get_objects_types())

        assert items_states.get_icon_states()
        print("All objects : ", items_states.get_icon_states())

        assert items_states.get_default_states()
        print("Default states : ", items_states.get_default_states())

        # Objects known states
        for object_type in items_states.object_types_states:
            assert items_states.get_icon_states(object_type)
            print(object_type, ", all states: ", items_states.get_icon_states(object_type))
            for state in items_states.get_icon_states(object_type):
                assert items_states.get_icon_state(object_type, state)
                print(object_type, ", state: ", state, ": ", items_states.get_icon_state(
                    object_type, state))

        assert not items_states.get_icon_state(None, None)

        # Default states are in all objects types
        for state in items_states.get_default_states():
            print("Default state: ", state)
            for object_type in items_states.object_types_states:
                assert items_states.get_icon_states(object_type)
Exemple #3
0
    def test_03_html_states(self):
        print("---")

        items_states = ElementState()
        assert items_states.object_types_states
        assert items_states.default_states
        assert items_states.states

        # Objects known states
        save_object_type = 'user'
        for object_type in items_states.object_types_states:
            print("Html for: ", object_type)
            for state in items_states.get_icon_states(object_type):
                if state == 'state_view':
                    continue

                elt = BackendElement({'_id': '0', 'status': state})
                print("Html for:", object_type, ", object:", elt)
                assert items_states.get_html_state(object_type, elt)
                print("Html : ", items_states.get_html_state(object_type, elt))

        # Unknown states
        print("States for: fake")
        print(items_states.get_icon_states('fake'))
        assert not items_states.get_icon_states('fake')

        print("Html for:", save_object_type, ", state: fake")
        print("Unknown state")
        elt = BackendElement({'_id': '0', 'status': 'fake'})
        print(items_states.get_html_state(save_object_type, elt))
        assert items_states.get_html_state(save_object_type,
                                           elt) == 'n/a - status: fake'

        print("Html for: fake, state: unknown")
        print("Unknown object type")
        elt = BackendElement({'_id': '0', 'status': 'unknown'})
        # Unknown object_type provides a default user html state ...
        item_state = items_states.get_html_state('fake', elt)
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="fake"><span class="fa-stack"  title="User default text"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>User default text</span></div>'''
            % elt.id)

        # Bad parameters
        print("No icon/text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=False,
                                                 text='')
        print(item_state)
        self.assertEqual(item_state, 'n/a - icon/text')

        print("Default icon/text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text='')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="User default text"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>User default text</span></div>'''
            % elt.id)

        # Other parameters
        print("Default icon/text - disabled")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text='',
                                                 disabled=True)
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state text-muted " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="User default text"><i class="fa fa-circle fa-stack-2x text-muted"></i><i class="fa fa-user fa-stack-1x "></i></span><span>User default text</span></div>'''
            % elt.id)

        print("Default icon/text - title and default text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 title='Test title')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="Test title"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>User default text</span></div>'''
            % elt.id)

        print("Default icon/text - title without text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text=None,
                                                 title='Test title')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="Test title"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span></span></div>'''
            % elt.id)

        print("Default icon/text - not title and default text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text='Test')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="User default text"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>Test</span></div>'''
            % elt.id)

        print("Default icon/text - not title and text")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text='Test text')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack"  title="User default text"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>Test text</span></div>'''
            % elt.id)

        print("Default icon/text - extra")
        item_state = items_states.get_html_state(save_object_type,
                                                 elt,
                                                 icon=True,
                                                 text='',
                                                 extra='test')
        print(item_state)
        self.assertEqual(
            item_state,
            '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user"><span class="fa-stack" style="opacity: 0.7" title="User default texttest"><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x "></i></span><span>User default texttest</span></div>'''
            % elt.id)
    def test_html_states(self):
        """ Items - HTML states """

        self.maxDiff = None

        items_states = ElementState()
        assert items_states.object_types_states
        assert items_states.default_states
        assert items_states.states

        # Objects known states
        save_object_type = 'user'
        for object_type in items_states.object_types_states:
            print("Html for: ", object_type)
            for state in items_states.get_icon_states(object_type):
                if state == 'state_view':
                    continue

                elt = BackendElement({
                    '_id': '0', 'status': state
                })
                print("Html for:", object_type, ", object:", elt)
                assert items_states.get_html_state(object_type, elt)
                print("Html : ", items_states.get_html_state(object_type, elt))

        # Unknown states
        print("States for: fake")
        print(items_states.get_icon_states('fake'))
        assert not items_states.get_icon_states('fake')

        print("Html for:", save_object_type, ", state: fake")
        print("Unknown state")
        elt = BackendElement({
            '_id': '0', 'status': 'fake'
        })
        print(items_states.get_html_state(save_object_type, elt))
        assert items_states.get_html_state(save_object_type, elt) == 'n/a - status: fake'

        print("Html for: fake, state: unknown")
        print("Unknown object type")
        elt = BackendElement({
            '_id': '0', 'status': 'unknown'
        })
        # Unknown object_type provides a default user html state ...
        item_state = items_states.get_html_state('fake', elt)
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="fake" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id

        # Bad parameters
        print("No icon/text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=False, text='')
        print(item_state)
        assert item_state == 'n/a - icon/text'

        print("Default icon/text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True, text='')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id

        # Other parameters
        print("Default icon/text - disabled")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True, text='',
                                                 disabled=True)
        print(item_state)
        assert item_state == \
                         '''<div class="item-state text-muted " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x text-muted"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id

        print("Default icon/text - title and default text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True,
                                                 title='Test title')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title="Test title"><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id

        print("Default icon/text - title without text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True, text=None,
                                                 title='Test title')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title="Test title"><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id

        print("Default icon/text - not title and default text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True, text='Test')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span>Test</span></div>''' % elt.id

        print("Default icon/text - not title and text")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True,
                                                 text='Test text')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title=""><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span>Test text</span></div>''' % elt.id

        print("Default icon/text - extra")
        item_state = items_states.get_html_state(save_object_type, elt, icon=True, text='',
                                                 extra='test')
        print(item_state)
        assert item_state == \
                         '''<div class="item-state item_user " style="display: inline; font-size:0.9em;" data-item-id="%s" data-item-name="anonymous" data-item-type="user" data-item-state="" title="testtest"><span class="fa-stack " ><i class="fa fa-circle fa-stack-2x item_user"></i><i class="fa fa-user fa-stack-1x fa-inverse"></i></span><span></span></div>''' % elt.id