Beispiel #1
0
class TestLayout(UnitTestCase):

    def setUp(self):
        super(TestLayout, self).setUp()
        self.page = Page(pk=1)
        self.layout = Layout(self.page, deepcopy(stored_layout))

    def test_get_static_widgets(self):
        self.assert_equals(
            [{'state': 2, 'config': {}, 'widget_id': 20, 'widget_ct_id': 1}],
            self.layout.static_widgets)

    def test_get_dynamic_widgets(self):
        self.assert_equals(
            [1, 2, 11],
            map(lambda x: x['widget_id'], self.layout.dynamic_widgets))

    def test_get_widgets(self):
        self.assert_equals(
            [1, 2, 11, 20],
            map(lambda x: x['widget_id'], self.layout.widgets))

    def test_get_widget(self):
        self.assert_equals(
            {'state': 2, 'config': {}, 'widget_id': 2, 'widget_ct_id': 1},
            self.layout.get_widget(1, 2))

    def test_get_widget_not_found(self):
        self.assert_raises(
            Layout.WidgetInLayoutDoesNotExist,
            self.layout.get_widget, 1000, 1000)

    def test_get_widget_reference(self):
        config = {'a':1}
        wil = self.layout.get_widget(1, 2)
        wil.config = config
        self.assert_equals(
            config,
            self.layout.get_widget(1, 2).config)
        self.assert_equals(
            config,
            self.layout['containers'][0][1].config)
        self.assert_true(self.layout.changed)
Beispiel #2
0
class TestArrangeWidgets(UnitTestCase):
    def setUp(self):
        super(TestArrangeWidgets, self).setUp()
        self.page = Page(pk=1)
        self.layout = Layout(self.page, deepcopy(stored_layout))

    def test_check_containers(self):
        # TODO move me to my place :)
        from mypage.pages.views import check_containers
        containers_strs = [[[u"1", u"1"], [u"2", u"2"]], [[u"3", u"3"]]]
        containers_ints = [[[1, 1], [2, 2]], [[3, 3]]]
        self.assert_equals(check_containers(containers_strs), containers_ints)

    def test_arrange_widgets_success(self):
        sent_containers = [[[1, 2], [1, 1]], [[1, 11], [1, 12]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(keys_only(self.layout.containers), sent_containers)

    @patch('mypage.pages.layout.get_object', mocked_get_object)
    def test_arrange_widgets_and_place_new_one_success(self):
        widget = Widget(content_type_id=1, pk=100)
        sent_containers = [[[1, 100], [1, 2], [1, 1]], [[1, 11], [1, 12]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(keys_only(self.layout.containers), sent_containers)

    def test_arrange_widgets_and_remove_one_success(self):
        sent_containers = [[[1, 2], [1, 1]], [[1, 11]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(keys_only(self.layout.containers), sent_containers)
Beispiel #3
0
class TestArrangeWidgets(UnitTestCase):

    def setUp(self):
        super(TestArrangeWidgets, self).setUp()
        self.page = Page(pk=1)
        self.layout = Layout(self.page, deepcopy(stored_layout))

    def test_check_containers(self):
        # TODO move me to my place :)
        from mypage.pages.views import check_containers
        containers_strs = [[[u"1", u"1"], [u"2", u"2"]], [[u"3", u"3"]]]
        containers_ints = [[[1, 1], [2, 2]], [[3, 3]]]
        self.assert_equals(
                check_containers(containers_strs),
                containers_ints)

    def test_arrange_widgets_success(self):
        sent_containers = [[[1, 2], [1, 1]], [[1, 11], [1, 12]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(
                keys_only(self.layout.containers),
                sent_containers)

    @patch('mypage.pages.layout.get_object', mocked_get_object)
    def test_arrange_widgets_and_place_new_one_success(self):
        widget = Widget(content_type_id=1, pk=100)
        sent_containers = [[[1, 100], [1, 2], [1, 1]], [[1, 11], [1, 12]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(
                keys_only(self.layout.containers),
                sent_containers)

    def test_arrange_widgets_and_remove_one_success(self):
        sent_containers = [[[1, 2], [1, 1]], [[1, 11]]]
        self.layout.arrange_widgets(sent_containers)
        self.assert_equals(
                keys_only(self.layout.containers),
                sent_containers)
Beispiel #4
0
 def test_template_config_as_hash(self):
     l = deepcopy(stored_layout)
     l.update(dict(template_config=stored_templpate_config))
     layout = Layout(self.page, l)
     self.assert_equals('1deb7217a43e5ad475a76b4158f1c472',
                        layout.template_config.as_hash())
Beispiel #5
0
 def test_template_config_on_layout(self):
     l = deepcopy(stored_layout)
     l.update(dict(template_config=stored_templpate_config))
     layout = Layout(self.page, l)
     self.assert_equals(2, layout.template_config['other_option'])
Beispiel #6
0
 def test_template_config_unknown_option(self):
     layout = Layout(self.page, deepcopy(stored_layout))
     template_config = TemplateConfig(layout)
     self.assert_raises(ImproperlyConfigured, template_config.__getitem__,
                        'unknown_option')
Beispiel #7
0
 def test_template_config_empty_default_option_loading(self):
     layout = Layout(self.page, deepcopy(stored_layout))
     template_config = TemplateConfig(layout)
     self.assert_equals(1, template_config['some_option'])
Beispiel #8
0
 def setUp(self):
     super(TestArrangeWidgets, self).setUp()
     self.page = Page(pk=1)
     self.layout = Layout(self.page, deepcopy(stored_layout))
Beispiel #9
0
 def setUp(self):
     super(TestArrangeWidgets, self).setUp()
     self.page = Page(pk=1)
     self.layout = Layout(self.page, deepcopy(stored_layout))
 def setUp(self):
     super(TestInsertRemoveWidget, self).setUp()
     self.page = Page(pk=1)
     self.layout = Layout(self.page, deepcopy(stored_layout))
     self.widget = Widget(content_type_id=1, pk=100)
class TestInsertRemoveWidget(UnitTestCase):
    def setUp(self):
        super(TestInsertRemoveWidget, self).setUp()
        self.page = Page(pk=1)
        self.layout = Layout(self.page, deepcopy(stored_layout))
        self.widget = Widget(content_type_id=1, pk=100)

    def test_insert_widget_defaults(self):
        self.layout.insert_widget(self.widget)
        self.assert_equals(
            self.layout['containers'][0][2], {
                'state': WidgetInLayout.STATE_NEW,
                'config': {},
                'widget_id': 100,
                'widget_ct_id': 1
            })

    def test_insert_widget_with_config(self):
        self.layout.insert_widget(self.widget,
                                  config={'x': 'y'},
                                  state=WidgetInLayout.STATE_NORMAL)
        self.assert_equals(
            self.layout['containers'][0][2], {
                'state': WidgetInLayout.STATE_NORMAL,
                'config': {
                    'x': 'y'
                },
                'widget_id': 100,
                'widget_ct_id': 1
            })

    def test_insert_widget_to_specified_container(self):
        self.layout.insert_widget(self.widget, container=1)
        self.assert_equals(self.layout['containers'][1][2], {
            'state': 2,
            'config': {},
            'widget_id': 100,
            'widget_ct_id': 1
        })

    def test_insert_widget_to_specified_container_out_of_range(self):
        self.assert_raises(IndexError,
                           self.layout.insert_widget,
                           self.widget,
                           container=2)

    def test_insert_widget_to_specified_position(self):
        self.layout.insert_widget(self.widget, position=0)
        self.assert_equals(self.layout['containers'][0][0], {
            'state': 2,
            'config': {},
            'widget_id': 100,
            'widget_ct_id': 1
        })
        self.assert_equals(self.layout['containers'][0][1], {
            'state': 2,
            'config': {},
            'widget_id': 1,
            'widget_ct_id': 1
        })

    def test_insert_widget_to_specified_position_out_of_range(self):
        self.layout.insert_widget(self.widget, position=100)
        self.assert_equals(self.layout['containers'][0][2], {
            'state': 2,
            'config': {},
            'widget_id': 100,
            'widget_ct_id': 1
        })

    def test_insert_allready_assigned_widget(self):
        self.layout.insert_widget(Widget(content_type_id=1, pk=1))
        self.assert_equals(len(self.layout.widgets), 5)
Beispiel #12
0
 def setUp(self):
     super(TestLayout, self).setUp()
     self.page = Page(pk=1)
     self.layout = Layout(self.page, deepcopy(stored_layout))
 def setUp(self):
     super(TestInsertRemoveWidget, self).setUp()
     self.page = Page(pk=1)
     self.layout = Layout(self.page, deepcopy(stored_layout))
     self.widget = Widget(content_type_id=1, pk=100)
class TestInsertRemoveWidget(UnitTestCase):

    def setUp(self):
        super(TestInsertRemoveWidget, self).setUp()
        self.page = Page(pk=1)
        self.layout = Layout(self.page, deepcopy(stored_layout))
        self.widget = Widget(content_type_id=1, pk=100)

    def test_insert_widget_defaults(self):
        self.layout.insert_widget(self.widget)
        self.assert_equals(
                self.layout['containers'][0][2],
                {'state': WidgetInLayout.STATE_NEW, 'config': {}, 'widget_id': 100, 'widget_ct_id': 1})

    def test_insert_widget_with_config(self):
        self.layout.insert_widget(self.widget, config={'x':'y'}, state=WidgetInLayout.STATE_NORMAL)
        self.assert_equals(
                self.layout['containers'][0][2],
                {'state': WidgetInLayout.STATE_NORMAL, 'config': {'x':'y'}, 'widget_id': 100, 'widget_ct_id': 1})

    def test_insert_widget_to_specified_container(self):
        self.layout.insert_widget(self.widget, container=1)
        self.assert_equals(
                self.layout['containers'][1][2],
                {'state': 2, 'config': {}, 'widget_id': 100, 'widget_ct_id': 1})

    def test_insert_widget_to_specified_container_out_of_range(self):
        self.assert_raises(
            IndexError,
            self.layout.insert_widget, self.widget, container=2)

    def test_insert_widget_to_specified_position(self):
        self.layout.insert_widget(self.widget, position=0)
        self.assert_equals(
                self.layout['containers'][0][0],
                {'state': 2, 'config': {}, 'widget_id': 100, 'widget_ct_id': 1})
        self.assert_equals(
                self.layout['containers'][0][1],
                {'state': 2, 'config': {}, 'widget_id': 1, 'widget_ct_id': 1})

    def test_insert_widget_to_specified_position_out_of_range(self):
        self.layout.insert_widget(self.widget, position=100)
        self.assert_equals(
                self.layout['containers'][0][2],
                {'state': 2, 'config': {}, 'widget_id': 100, 'widget_ct_id': 1})

    def test_insert_allready_assigned_widget(self):
        self.layout.insert_widget(Widget(content_type_id=1, pk=1))
        self.assert_equals(
                len(self.layout.widgets), 5)
Beispiel #15
0
 def layout_get(self):
     if not hasattr(self, '_layout'):
         self._layout = Layout(self, json.deserialize(self.layout_json))
     return self._layout
Beispiel #16
0
 def test_render(self):
     layout = Layout(self.page, self.layout)
     self.assert_equals(
             layout.render(context={}), 
             {'static_containers': [['1:1:None']], 'containers': [['1:2:None', '1:3:None']]})
Beispiel #17
0
 def test_render_with_settab(self):
     layout = Layout(self.page, self.layout)
     self.assert_equals(
             layout.render(context={}, settab=dict(widget_ct_id=1, widget_id=2, tab='sometab')),
             {'static_containers': [['1:1:None']], 'containers': [['1:2:sometab', '1:3:None']]})
Beispiel #18
0
 def setUp(self):
     super(TestWidgetInLayout, self).setUp()
     self.layout = Layout(Page(pk=1), deepcopy(stored_layout))