Ejemplo n.º 1
0
 def test_add_new_template(self):
     amp_deps = AmpDependencies(test_pod)
     amp_deps.add('amp-mustache', '0.2', 'template')
     self.assertEqual(1, len(amp_deps._dependencies))
     version, dep_type = amp_deps._dependencies.get('amp-mustache')
     self.assertEqual('0.2', version)
     self.assertEqual('template', dep_type)
Ejemplo n.º 2
0
 def test_add_new_component(self):
     amp_deps = AmpDependencies(test_pod)
     amp_deps.add('amp-anim', '0.1')
     self.assertEqual(1, len(amp_deps._dependencies))
     version, dep_type = amp_deps._dependencies.get('amp-anim')
     self.assertEqual('0.1', version)
     self.assertEqual('element', dep_type)
Ejemplo n.º 3
0
    def test_inject_without_emit(self):
        amp_deps = AmpDependencies(test_pod)
        amp_deps.add('amp-anim', '0.1')
        amp_deps.add('amp-mustache', '0.2', 'template')

        content = amp_deps.inject('')
        self.assertEqual('', content)
Ejemplo n.º 4
0
    def test_emit_and_inject(self):
        amp_deps = AmpDependencies(test_pod)
        amp_deps.add('amp-anim', '99.9')
        amp_deps.add('amp-mustache', '77.7', 'template')

        content = amp_deps.emit()
        content = amp_deps.inject(content)
        self.assertEqual(
            '<script custom-element="amp-anim" '
            'src="https://cdn.ampproject.org/v0/amp-anim-99.9.js" async></script>'
            '<script custom-template="amp-mustache" '
            'src="https://cdn.ampproject.org/v0/amp-mustache-77.7.js" async></script>',
            content)
Ejemplo n.º 5
0
 def test_add_none_second(self):
     amp_deps = AmpDependencies(test_pod)
     amp_deps.add('amp-anim', '99.9')
     amp_deps.add('amp-anim', None)
     self.assertEqual(1, len(amp_deps._dependencies))
     _version, dep_type = amp_deps._dependencies.get('amp-anim')
     self.assertEqual('99.9', _version)
Ejemplo n.º 6
0
 def test_add_other_version(self):
     amp_deps = AmpDependencies(test_pod)
     amp_deps.add('amp-anim', '0.1')
     try:
         amp_deps.add('amp-anim', '0.2')
     except RuntimeError:
         # expected
         return
     self.fail('no exception')
Ejemplo n.º 7
0
    def test_emit_and_inject_with_default_version(self):
        amp_deps = AmpDependencies(test_pod)
        amp_deps.add('amp-anim')

        content = amp_deps.emit()
        content = amp_deps.inject(content)
        self.assertEqual(
            '<script custom-element="amp-anim" '
            'src="https://cdn.ampproject.org/v0/amp-anim-0.1.js" async></script>',
            content)
Ejemplo n.º 8
0
    def trigger(self, previous_result, doc, raw_content, *_args, **_kwargs):
        amp_dependencies = AmpDependencies(doc.pod)
        setattr(doc, 'amp_dependencies', amp_dependencies)

        return previous_result if previous_result else raw_content
Ejemplo n.º 9
0
 def test_add_same_twice(self):
     amp_deps = AmpDependencies(test_pod)
     amp_deps.add('amp-anim', '0.1')
     amp_deps.add('amp-anim', '0.1')
     self.assertEqual(1, len(amp_deps._dependencies))