<commit_before># coding: utf8
# Copyright (c) 2010 gocept gmbh & co. kg
# See also LICENSE.txt

import contextlib
import zeit.content.article.testing


class ImageTest(zeit.content.article.testing.FunctionalTestCase):

    def test_image_can_be_set(self):
        from zeit.content.article.edit.image import Image
        import lxml.objectify
        import zeit.cms.interfaces
        tree = lxml.objectify.E.tree(
            lxml.objectify.E.image())
        image = Image(None, tree.image)
        image.__name__ = u'myname'
        image.layout = u'large'
        image_uid = 'http://xml.zeit.de/2006/DSC00109_2.JPG'
        image.references = image.references.create(
            zeit.cms.interfaces.ICMSContent(image_uid))
        self.assertEqual(image_uid, image.references.target.uniqueId)
        self.assertEqual(image_uid, image.xml.get('src'))
        self.assertEqual(u'myname', image.__name__)
        self.assertEqual(u'large', image.layout)

    def test_setting_image_to_none_removes_href(self):
        from zeit.content.article.edit.image import Image<commit_msg>Re VIV-305: Ensure that the XML structure of references looks sane<commit_after># coding: utf8
# Copyright (c) 2010 gocept gmbh & co. kg
# See also LICENSE.txt

import contextlib
import zeit.content.article.testing


class ImageTest(zeit.content.article.testing.FunctionalTestCase):

    def test_image_can_be_set(self):
        from zeit.content.article.edit.image import Image
        import lxml.objectify
        import zeit.cms.interfaces
        tree = lxml.objectify.E.tree(
            lxml.objectify.E.image())
        image = Image(None, tree.image)
        image.__name__ = u'myname'
        image.layout = u'large'
        image_uid = 'http://xml.zeit.de/2006/DSC00109_2.JPG'
        image.references = image.references.create(
            zeit.cms.interfaces.ICMSContent(image_uid))
        self.assertEqual(image_uid, image.references.target.uniqueId)
        self.assertEqual(image_uid, image.xml.get('src'))
        self.assertEqual(u'myname', image.__name__)
        self.assertEqual(u'large', image.layout)
        self.assertEllipsis("""\
<image ... src="{image_uid}" ... is_empty="False">
  <bu xsi:nil="true"/>
  <copyright py:pytype="str">&#169;</copyright>
</image>
        """.format(image_uid=image_uid), lxml.etree.tostring(
            image.xml, pretty_print=True))

    def test_setting_image_to_none_removes_href(self):
        from zeit.content.article.edit.image import Image
{'fraction_non_alphanumeric': 0.11797752808988764, 'fraction_numerical': 0.014446227929373997, 'mean_word_length': 3.086885245901639, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '928784', 'n_tokens_mistral': 823, 'n_tokens_neox': 784, 'n_words': 138}