def test_render(self): site = Site.objects.get_current() template = Template.objects.create(name='default', slug='default', body=get_default_template()) config = Config.objects.create(site_name='Site Name', site=site) Seo.objects.create(content_object=config, title='Site Name - {{ sodaseo.site_name }}', template=template) post = mommy.make(Post) url = reverse('post_detail', args=[post.pk]) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains(response, '<title>Site Name - Site Name</title>') url_obj = Url.objects.create(site=site, path='/posts/{0}/'.format(post.pk)) Seo.objects.create(content_object=url_obj, title='Post Detail - {{ sodaseo.site_name }}', template=template) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains(response, '<title>Post Detail - Site Name</title>') Seo.objects.create(content_object=post, title='Post Detail 2 - {{ sodaseo.site_name }}', template=template) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains(response, '<title>Post Detail 2 - Site Name</title>')
def test_render(self): site = Site.objects.get_current() template = Template.objects.create( name='default', slug='default', body=get_default_template() ) config = Config.objects.create( site_name='Site Name', site=site ) Seo.objects.create( content_object=config, title='Index - {{ sodaseo.site_name }}', template=template ) url_obj = Url.objects.create( site=site, path='/sodaseo-render-tags/' ) Seo.objects.create( content_object=url_obj, title='Render Tags - {{ sodaseo.site_name }}', template=template ) response = self.client.get(self.url) self.assertContains(response, 'Index - Site Name') response = self.client.get(self.url, {'url': '/sodaseo-render-tags/'}) self.assertContains(response, 'Render Tags - Site Name')
def test_render(self): site = Site.objects.get_current() template = Template.objects.create(name='default', slug='default', body=get_default_template()) config = Config.objects.create(site_name='Site Name', site=site, google_analytics_id='UA-00000000-0') Seo.objects.create(content_object=config, title='Site Name - {{ sodaseo.site_name }}', template=template) mommy.make(Post, _quantity=5) url = reverse('post_list') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 5) self.assertContains(response, '<title>Site Name - Site Name</title>') self.assertContains(response, 'UA-00000000-0') url_obj = Url.objects.create(site=site, path='/posts/') Seo.objects.create(content_object=url_obj, title='Post List - {{ sodaseo.site_name }}', template=template) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 5) self.assertContains(response, '<title>Post List - Site Name</title>')
def sodaseo_render_tags(context, site_id=1): if 'request' not in context: return '' sodaseo_ctx = context.get('sodaseo', {}) request = context['request'] ctx = get_sodaseo_context(request, sodaseo_ctx, site_id=site_id) # template template = get_default_template() try: template = ctx['template'].body except KeyError: pass try: t = Template(template) context.update({'sodaseo': ctx}) c = Context(context) return t.render(c) except: pass return ''
def setUp(self): self.factory = RequestFactory() self.site = Site.objects.get_current() self.template = Template.objects.create(name='Default', slug='default', body=get_default_template()) self.config = Config.objects.create(site=self.site, site_name='My Site', extra_head='HUEHUEBR') self.config_seo = Seo(template=self.template, title='My Awesome Site.', description='My Awesome Site Description.') self.config_seo.content_object = self.config self.config_seo.save()
def test_render(self): site = Site.objects.get_current() template = Template.objects.create( name='default', slug='default', body=get_default_template() ) config = Config.objects.create( site_name='Site Name', site=site ) Seo.objects.create( content_object=config, title='Site Name - {{ sodaseo.site_name }}', template=template ) post = mommy.make(Post) url = reverse('post_detail', args=[post.pk]) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains( response, '<title>Site Name - Site Name</title>' ) url_obj = Url.objects.create( site=site, path='/posts/{0}/'.format(post.pk) ) Seo.objects.create( content_object=url_obj, title='Post Detail - {{ sodaseo.site_name }}', template=template ) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains( response, '<title>Post Detail - Site Name</title>' ) Seo.objects.create( content_object=post, title='Post Detail 2 - {{ sodaseo.site_name }}', template=template ) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['object'], post) self.assertContains( response, '<title>Post Detail 2 - Site Name</title>' )
def setUp(self): self.factory = RequestFactory() self.site = Site.objects.get_current() self.template = Template.objects.create( name='Default', slug='default', body=get_default_template() ) self.config = Config.objects.create( site=self.site, site_name='My Site', google_analytics_id='HUEHUEBR' ) self.config_seo = Seo( template=self.template, title='My Awesome Site.', description='My Awesome Site Description.' ) self.config_seo.content_object = self.config self.config_seo.save()
def test_render(self): site = Site.objects.get_current() template = Template.objects.create(name='default', slug='default', body=get_default_template()) config = Config.objects.create(site_name='Site Name', site=site) Seo.objects.create(content_object=config, title='Index - {{ sodaseo.site_name }}', template=template) url_obj = Url.objects.create(site=site, path='/sodaseo-render-tags/') Seo.objects.create(content_object=url_obj, title='Render Tags - {{ sodaseo.site_name }}', template=template) response = self.client.get(self.url) self.assertContains(response, 'Index - Site Name') response = self.client.get(self.url, {'url': '/sodaseo-render-tags/'}) self.assertContains(response, 'Render Tags - Site Name')
def setUp(self): self.factory = RequestFactory() self.site = Site.objects.get_current() self.template = Template.objects.create(name='Default', slug='default', body=get_default_template()) self.config = Config.objects.create(site=self.site, site_name='My Site') self.config_seo = Seo(template=self.template, title='My Awesome Site.', description='My Awesome Site Description.') self.config_seo.content_object = self.config self.config_seo.save() self.url = Url.objects.create(site=self.site, path='/') self.url_seo = Seo(template=self.template, title='Welcome to my site.', description='Welcome to my site description.') self.url_seo.content_object = self.url self.url_seo.save()
def test_render(self): site = Site.objects.get_current() template = Template.objects.create( name='default', slug='default', body=get_default_template() ) config = Config.objects.create( site_name='Site Name', site=site, google_analytics_id='UA-00000000-0' ) Seo.objects.create( content_object=config, title='Site Name - {{ sodaseo.site_name }}', template=template ) mommy.make(Post, _quantity=5) url = reverse('post_list') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 5) self.assertContains( response, '<title>Site Name - Site Name</title>' ) self.assertContains(response, 'UA-00000000-0') url_obj = Url.objects.create( site=site, path='/posts/' ) Seo.objects.create( content_object=url_obj, title='Post List - {{ sodaseo.site_name }}', template=template ) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['object_list']), 5) self.assertContains( response, '<title>Post List - Site Name</title>' )
def setUp(self): self.factory = RequestFactory() self.site = Site.objects.get_current() self.template = Template.objects.create( name='Default', slug='default', body=get_default_template() ) self.config = Config.objects.create( site=self.site, site_name='My Site' ) self.config_seo = Seo( template=self.template, title='My Awesome Site.', description='My Awesome Site Description.' ) self.config_seo.content_object = self.config self.config_seo.save() self.url = Url.objects.create(site=self.site, path='/') self.url_seo = Seo( template=self.template, title='Welcome to my site.', description='Welcome to my site description.' ) self.url_seo.content_object = self.url self.url_seo.save()
def __init__(self, *args, **kwargs): super(TemplateForm, self).__init__(*args, **kwargs) if not self.instance.pk: self.initial['body'] = get_default_template()
def test_function(self): data = get_default_template() self.assertTrue(data)