def test_get_first_and_second_and_third_level_if_nested_under_third(self): def other_dummy(request): pass kwargs = self.kwargs.copy() kwargs['view_attrs'] = {'four': 4444} patterns_6 = patterns('', url('asdf', other_dummy, **self.kwargs)) patterns_5 = patterns('', url('^xxx$', include(patterns_6))) patterns_4 = patterns('', url('^xxx$', include(patterns_5))) patterns_3 = patterns('', url(*self.args, **kwargs), url('^xxx$', include(patterns_4))) patterns_2 = patterns('', url('^xxx$', include(patterns_3), view_attrs={'three': 333, 'four': 444})) patterns_1 = patterns('', url('^xxx$', include(patterns_2), view_attrs={'two': 22, 'three': 33, 'four': 44})) patterns('', url('^xxx$', include(patterns_1), view_attrs={'one': 1, 'two': 2, 'three': 3, 'four': 4})) self.assertEqual(other_dummy.one, 1) self.assertEqual(other_dummy.two, 22) self.assertEqual(other_dummy.three, 333) self.assertEqual(other_dummy.four, 444) self.assertEqual(self.dummy_view.one, 1) self.assertEqual(self.dummy_view.two, 22) self.assertEqual(self.dummy_view.three, 333) self.assertEqual(self.dummy_view.four, 4444)
def test_remain_unaffected_if_not_nested_under_first_level(self): def other_dummy(request): pass kwargs = self.kwargs.copy() kwargs['view_attrs'] = {'four': 4444} patterns_6 = patterns('', url(*self.args, **kwargs)) patterns_5 = patterns('', url('asdf', other_dummy, **self.kwargs)) patterns_4 = patterns('', url('^xxx$', include(patterns_5))) patterns_3 = patterns('', url('^xxx$', include(patterns_6), view_attrs={'three': 333, 'four': 444})) patterns_2 = patterns('', url('^xxx$', include(patterns_3), view_attrs={'two': 22, 'three': 33, 'four': 44})) patterns_1 = patterns('', url('^xxx$', include(patterns_4))) patterns('', url('^xxx$', include(patterns_2), view_attrs={'one': 1, 'two': 2, 'three': 3, 'four': 4}), url('^xxx$', include(patterns_1))) self.assertFalse(hasattr(other_dummy, 'one')) self.assertFalse(hasattr(other_dummy, 'two')) self.assertFalse(hasattr(other_dummy, 'three')) self.assertFalse(hasattr(other_dummy, 'four')) self.assertEqual(self.dummy_view.one, 1) self.assertEqual(self.dummy_view.two, 22) self.assertEqual(self.dummy_view.three, 333) self.assertEqual(self.dummy_view.four, 4444)
def test_inherit_parent_attributes(self): def another_func(request): pass patterns_1 = patterns('', url(*self.args, **self.kwargs), url('asdf', another_func, **self.kwargs)) patterns('', url('^xxx$', include(patterns_1), view_attrs={'asdf': 1234, 'wxyz': 'abcd'})) self.assertEqual(self.dummy_view.asdf, 1234) self.assertEqual(self.dummy_view.wxyz, 'abcd') self.assertEqual(another_func.asdf, 1234) self.assertEqual(another_func.wxyz, 'abcd')
def test_inherit_multiple_levels_deep(self): patterns_3 = patterns('', url(*self.args, **self.kwargs)) patterns_2 = patterns('', url('^xxx$', include(patterns_3), view_attrs={'level_three': 'three'})) patterns_1 = patterns('', url('^xxx$', include(patterns_2), view_attrs={'level_two': 'two'})) patterns('', url('^xxx$', include(patterns_1), view_attrs={'level_one': 'one'})) self.assertEqual(self.dummy_view.level_one, 'one') self.assertEqual(self.dummy_view.level_two, 'two') self.assertEqual(self.dummy_view.level_three, 'three')
def test_override_parents_at_child_levels(self): kwargs = self.kwargs.copy() kwargs['view_attrs'] = {'four': 4444} patterns_3 = patterns('', url(*self.args, **kwargs)) patterns_2 = patterns('', url('^xxx$', include(patterns_3), view_attrs={'three': 333, 'four': 444})) patterns_1 = patterns('', url('^xxx$', include(patterns_2), view_attrs={'two': 22, 'three': 33, 'four': 44})) patterns('', url('^xxx$', include(patterns_1), view_attrs={'one': 1, 'two': 2, 'three': 3, 'four': 4})) self.assertEqual(self.dummy_view.one, 1) self.assertEqual(self.dummy_view.two, 22) self.assertEqual(self.dummy_view.three, 333) self.assertEqual(self.dummy_view.four, 4444)
def test_add_attributes_to_callable(self): patterns('', url(*self.args, **self.new_kwargs)) self.assertEqual(self.dummy_view.one, 1) self.assertEqual(self.dummy_view.two, 2)