当前位置: 首页>>代码示例>>Python>>正文


Python tests.SnippetTemplateFactory类代码示例

本文整理汇总了Python中snippets.base.tests.SnippetTemplateFactory的典型用法代码示例。如果您正苦于以下问题:Python SnippetTemplateFactory类的具体用法?Python SnippetTemplateFactory怎么用?Python SnippetTemplateFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SnippetTemplateFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic

    def test_basic(self):
        variable1 = SnippetTemplateVariableFactory()
        variable2 = SnippetTemplateVariableFactory()
        template1 = SnippetTemplateFactory.create(
            variable_set=[variable1, variable2])

        variable3 = SnippetTemplateVariableFactory()
        template2 = SnippetTemplateFactory.create(variable_set=[variable3])

        choices = (('', 'blank'), (template1.pk, 't1'), (template2.pk, 't2'))
        widget = TemplateSelect(choices=choices)
        d = pq(widget.render('blah', None))

        # Blank option should have no data attributes.
        blank_option = d('option:contains("blank")')
        eq_(blank_option.attr('data-variables'), None)

        # Option 1 should have two variables in the data attribute.
        option1 = d('option:contains("t1")')
        variables = json.loads(option1.attr('data-variables'))
        eq_(len(variables), 2)
        ok_({'name': variable1.name, 'type': variable1.type,
             'description': variable1.description} in variables)
        ok_({'name': variable2.name, 'type': variable2.type,
             'description': variable1.description} in variables)

        # Option 2 should have just one variable.
        option2 = d('option:contains("t2")')
        variables = json.loads(option2.attr('data-variables'))
        eq_(variables, [{'name': variable3.name, 'type': variable3.type,
                         'description': variable3.description}])
开发者ID:Mastert123,项目名称:snippets-service,代码行数:31,代码来源:test_forms.py

示例2: test_save_related_remove_old

    def test_save_related_remove_old(self):
        """
        save_related should delete TemplateVariables that don't exist in the
        saved template anymore.
        """
        template = SnippetTemplateFactory.create(code="""
            <p>Testing {{ sample_var }}</p>
            {% if not another_test_var %}
              <p>Blah</p>
            {% endif %}
        """)
        SnippetTemplateVariableFactory.create(
            name='does_not_exist', template=template)
        SnippetTemplateVariableFactory.create(
            name='does_not_exist_2', template=template)

        self.assertTrue(SnippetTemplateVariable.objects
                        .filter(template=template, name='does_not_exist').exists())
        self.assertTrue(SnippetTemplateVariable.objects
                        .filter(template=template, name='does_not_exist_2').exists())

        variables = self._save_related(template)
        self.assertEqual(len(variables), 2)
        self.assertTrue('sample_var' in variables)
        self.assertTrue('another_test_var' in variables)

        self.assertFalse(SnippetTemplateVariable.objects
                         .filter(template=template, name='does_not_exist').exists())

        self.assertFalse(SnippetTemplateVariable.objects
                         .filter(template=template, name='does_not_exist_2').exists())
开发者ID:schalkneethling,项目名称:snippets-service,代码行数:31,代码来源:test_admin.py

示例3: test_render_not_cached

    def test_render_not_cached(self, mock_from_string, mock_sha1):
        """If the template isn't in the cache, add it."""
        template = SnippetTemplateFactory(code='asdf')
        mock_cache = {}

        with patch('snippets.base.models.template_cache', mock_cache):
            result = template.render({})

        jinja_template = mock_from_string.return_value
        cache_key = mock_sha1.return_value.hexdigest.return_value
        eq_(mock_cache, {cache_key: jinja_template})

        mock_sha1.assert_called_with('asdf')
        mock_from_string.assert_called_with('asdf')
        jinja_template.render.assert_called_with({'snippet_id': 0})
        eq_(result, jinja_template.render.return_value)
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:16,代码来源:test_models.py

示例4: test_render_cached

    def test_render_cached(self, mock_from_string, mock_sha1):
        """
        If the template is in the cache, use the cached version instead
        of bothering to compile it.
        """
        template = SnippetTemplateFactory(code='asdf')
        cache_key = mock_sha1.return_value.hexdigest.return_value
        jinja_template = Mock()
        mock_cache = {cache_key: jinja_template}

        with patch('snippets.base.models.template_cache', mock_cache):
            result = template.render({})

        mock_sha1.assert_called_with('asdf')
        ok_(not mock_from_string.called)
        jinja_template.render.assert_called_with({'snippet_id': 0})
        eq_(result, jinja_template.render.return_value)
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:17,代码来源:test_models.py

示例5: test_valid_args_activity_stream

 def test_valid_args_activity_stream(self):
     """If template_id and data are both valid, return the preview page."""
     template = SnippetTemplateFactory.create()
     data = '{"a": "b"}'
     response = self._preview_snippet(template_id=template.id, activity_stream=True, data=data)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context['client'].startpage_version, 5)
     self.assertTemplateUsed(response, 'base/preview_as.jinja')
开发者ID:glogiotatidis,项目名称:snippets-service,代码行数:8,代码来源:test_views.py

示例6: test_snippets

 def test_snippets(self):
     instance = UploadedFileFactory.build()
     instance.file = MagicMock()
     instance.file.url = '/media/foo.png'
     snippets = SnippetFactory.create_batch(2, data='lalala {0} foobar'.format(instance.url))
     template = SnippetTemplateFactory.create(code='<foo>{0}</foo>'.format(instance.url))
     more_snippets = SnippetFactory.create_batch(3, template=template)
     self.assertEqual(set(instance.snippets), set(list(snippets) + list(more_snippets)))
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:8,代码来源:test_models.py

示例7: test_render_unicode

 def test_render_unicode(self):
     variable = SnippetTemplateVariableFactory(name='data')
     template = SnippetTemplateFactory.create(code='{{ data }}',
                                              variable_set=[variable])
     snippet = SnippetFactory(template=template,
                              data='{"data": "\u03c6\u03bf\u03bf"}')
     output = snippet.render()
     eq_(pq(output)[0].text, u'\u03c6\u03bf\u03bf')
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:8,代码来源:test_models.py

示例8: test_valid_args

    def test_valid_args(self):
        """If template_id and data are both valid, return the preview page."""
        template = SnippetTemplateFactory.create()
        data = '{"a": "b"}'

        response = self._preview_snippet(template_id=template.id, data=data)
        self.assertEqual(response.status_code, 200)
        snippet = response.context['snippets_json']
        self.assertTrue(json.loads(snippet))
开发者ID:schalkneethling,项目名称:snippets-service,代码行数:9,代码来源:test_views.py

示例9: test_invalid_data

    def test_invalid_data(self):
        """If data is missing or invalid, return a 400 Bad Request."""
        template = SnippetTemplateFactory.create()
        response = self._preview_snippet(template_id=template.id)
        eq_(response.status_code, 400)

        response = self._preview_snippet(template_id=template.id,
                                         data='{invalid."json]')
        eq_(response.status_code, 400)
开发者ID:alicoding,项目名称:snippets-service,代码行数:9,代码来源:test_views.py

示例10: test_valid_args

    def test_valid_args(self):
        """If template_id and data are both valid, return the preview page."""
        template = SnippetTemplateFactory.create()
        data = '{"a": "b"}'

        response = self._preview_snippet(template_id=template.id, data=data)
        eq_(response.status_code, 200)

        snippet = response.context['snippet']
        eq_(snippet.template, template)
        eq_(snippet.data, data)
开发者ID:Osmose,项目名称:snippets-service,代码行数:11,代码来源:test_views.py

示例11: test_render_campaign

    def test_render_campaign(self):
        template = SnippetTemplateFactory.create()
        template.render = Mock()
        template.render.return_value = '<a href="asdf">qwer</a>'

        data = '{"url": "asdf", "text": "qwer"}'
        snippet = SnippetFactory.create(template=template, data=data, campaign='foo')

        expected = Markup('<div data-snippet-id="{id}" data-weight="100" '
                          'data-campaign="foo" class="snippet-metadata">'
                          '<a href="asdf">qwer</a></div>'.format(id=snippet.id))
        self.assertEqual(snippet.render().strip(), expected)
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:12,代码来源:test_models.py

示例12: test_save_related_add_new

 def test_save_related_add_new(self):
     """
     save_related should add new TemplateVariables for any new variables in
     the template code.
     """
     template = SnippetTemplateFactory.create(code="""
         <p>Testing {{ sample_var }}</p>
         {% if not another_test_var %}
           <p>Blah</p>
         {% endif %}
     """)
     variables = self._save_related(template)
     self.assertEqual(len(variables), 2)
     self.assertTrue('sample_var' in variables)
     self.assertTrue('another_test_var' in variables)
开发者ID:schalkneethling,项目名称:snippets-service,代码行数:15,代码来源:test_admin.py

示例13: test_render_multiple_countries

    def test_render_multiple_countries(self):
        """
        Include multiple countries in data-countries
        """
        template = SnippetTemplateFactory.create()
        template.render = Mock()
        template.render.return_value = '<a href="asdf">qwer</a>'

        data = '{"url": "asdf", "text": "qwer"}'
        snippet = SnippetFactory.create(template=template, data=data, countries=['us', 'el'])

        expected = Markup(
            '<div data-snippet-id="{0}" data-weight="100" data-campaign="" '
            'class="snippet-metadata" data-countries="el,us">'
            '<a href="asdf">qwer</a></div>'.format(snippet.id))
        self.assertEqual(snippet.render().strip(), expected)
开发者ID:akatsoulas,项目名称:snippets-service,代码行数:16,代码来源:test_models.py

示例14: test_render_no_country

    def test_render_no_country(self):
        """
        If the snippet isn't geolocated, don't include the data-country
        attribute.
        """
        template = SnippetTemplateFactory.create()
        template.render = Mock()
        template.render.return_value = '<a href="asdf">qwer</a>'

        data = '{"url": "asdf", "text": "qwer"}'
        snippet = SnippetFactory.create(template=template, data=data)

        expected = ('<div data-snippet-id="{0}" data-weight="100">'
                    '<a href="asdf">qwer</a></div>'
                    .format(snippet.id))
        eq_(snippet.render().strip(), expected)
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:16,代码来源:test_models.py

示例15: test_save_related_reserved_name

    def test_save_related_reserved_name(self):
        """
        save_related should not add new TemplateVariables for variables that
        are in the RESERVED_VARIABLES list.
        """
        template = SnippetTemplateFactory.create(code="""
            <p>Testing {{ reserved_name }}</p>
            {% if not another_test_var %}
              <p>Blah</p>
            {% endif %}
        """)
        variables = self._save_related(template)
        self.assertEqual(len(variables), 1)
        self.assertTrue('another_test_var' in variables)

        self.assertFalse(SnippetTemplateVariable.objects
                         .filter(template=template, name='reserved_name').exists())
开发者ID:schalkneethling,项目名称:snippets-service,代码行数:17,代码来源:test_admin.py


注:本文中的snippets.base.tests.SnippetTemplateFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。