def test_build_content(self): pagelet = ApplicationPagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) content = pagelet._build_content() #mock_resolve.assert_called_once_with(mock_pagelet_model_starting_url, mock_urlconf_test_application) self.assertIsInstance(content, Markup, 'content was not markup') self.assertEqual(content, mock_resolve_response.content, 'content was incorrect %s' % content)
def test_get_html_data(self): pagelet = ApplicationPagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) data = pagelet._get_html_data() expected_data = {'starting_url' : mock_pagelet_model_starting_url, 'application' : mock_pagelet_model_application} self.assertDictContainsSubset(expected_data, data, 'data was missing expceted values %s' % data)
def test_get_context(self): pagelet = SimplePagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) context = pagelet._get_context() self.assertIn('content', context, 'context did not contain content %s' % context) self.assertIsInstance(context['content'], Markup, 'content was not markup') self.assertEqual(context['content'], mock_pagelet_model.content, 'content was incorrect %s' % context['content'])
def test_get_context(self): pagelet = MenuPagelet(request=mock_data.mock_request(), request_kwargs={}, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) context = pagelet._get_context() self.assertIn('menu_label', context, 'context did not contain menu_label') self.assertIn('selected_item', context, 'context did not contain selected_item') self.assertEqual(mock_menu_label, context['menu_label'], 'context contained incorrect menu_label') self.assertEqual(mock_menu_selected_item, context['selected_item'], 'context contained incorrect selected_item')
def test_get_context_with_content(self): pagelet = ApplicationPagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) context = pagelet._get_context(include_content=True) #mock_resolve.assert_called_once_with(mock_pagelet_model_starting_url, mock_urlconf_test_application) self.assertIn('content', context, 'context did not contain content %s' % context) self.assertIsInstance(context['content'], Markup, 'content was not markup') self.assertEqual(context['content'], mock_resolve_response.content, 'content was incorrect %s' % context['content'])
def test_json(self): pagelet = ApplicationPagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) json_output = pagelet.json() json_output = json.loads(json_output) #FIXME: Should check for html expected_json_output = {'location': mock_pagelet_model_starting_url, 'css': expected_css, 'js': expected_js} self.assertDictContainsSubset(expected_json_output, json_output, 'json was incorrect %s' % json_output)
def test_build_css(self): pagelet = MenuPagelet(request=mock_data.mock_request(), request_kwargs={}, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) css = pagelet._build_css() expected_css = ['%scss/%s.css' % (settings.AMPCMS_MEDIA_URL, mock_menu_label)] self.assertListEqual(expected_css, css, 'css was incorrect %s' % css)
def test_get_html_data(self): pagelet = MenuPagelet(request=mock_data.mock_request(), request_kwargs={}, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) data = pagelet._get_html_data() expected_data = {'name': mock_menu_label} self.assertDictEqual(expected_data, data, 'data was incorrect %s' % data)
def test_append(self): pagelet = MenuPagelet(request=mock_data.mock_request(), request_kwargs=None) pagelet.append(mock_menu_item_1, mock_menu_url_1) self.assertIn((mock_menu_item_1, mock_menu_url_1), pagelet._children, 'did not append item to menu')
def test_build_js(self): pagelet = BasePagelet(request=mock_data.mock_request(), request_kwargs=None, pagelet=mock_pagelet_model) js = pagelet._build_js() self.assertListEqual(expected_js, js, 'css was incorrect %s' % js)
def test_get_html_data(self): pagelet = BasePagelet(request=mock_data.mock_request(), request_kwargs=None, pagelet=mock_pagelet_model) data = pagelet._get_html_data() self.assertIn('name', data, 'data does not include a name %s' % data)
def test_get_context_no_content(self): pagelet = ApplicationPagelet(request=mock_data.mock_request(), request_kwargs={}, pagelet=mock_pagelet_model, menu_label=mock_menu_label, selected_item=mock_menu_selected_item) context = pagelet._get_context() self.assertNotIn('content', context, 'context incorrectly contained content %s' % context)
def test_get_context_with_request(self): content_type = BaseContentType(request=mock_data.mock_request(), request_kwargs=None) context = content_type._get_context() self.assertIsInstance(context, RequestContext, 'context was not a dictionary')