Ejemplo n.º 1
0
 def test_as_html(self):
     doc_json = self.fixture_search[0]
     doc = prismic.Document(doc_json)
     expected_html = """<section data-field="product.allergens"><span class="text">Contains almonds, eggs, milk</span></section><section data-field="product.image"><img src="https://wroomio.s3.amazonaws.com/lesbonneschoses/0417110ebf2dc34a3e8b7b28ee4e06ac82473b70.png" width="500" height="500"></section><section data-field="product.short_lede"><h2>Crispiness and softness, rolled into one</h2></section><section data-field="product.testimonial_author[0]"><h3>Chef Guillaume Bort</h3></section><section data-field="product.related[0]"><a href="document/UdUjvt_mqVNObPeO">dark-chocolate-macaron</a></section><section data-field="product.name"><h1>Vanilla Macaron</h1></section><section data-field="product.related[1]"><a href="document/UdUjsN_mqT1ObPeM">salted-caramel-macaron</a></section><section data-field="product.testimonial_quote[0]"><p>The taste of pure vanilla is very hard to tame, and therefore, most cooks resort to substitutes. <strong>It takes a high-skill chef to know how to get the best of tastes, and <strong><em></strong>Les Bonnes Choses<strong></em></strong>'s vanilla macaron does just that</strong>. The result is more than a success, it simply is a gastronomic piece of art.</p></section><section data-field="product.flavour[0]"><span class="text">Vanilla</span></section><section data-field="product.price"><span class="number">3.55</span></section><section data-field="product.color"><span class="color">#ffeacd</span></section><section data-field="product.description"><p>Experience the ultimate vanilla experience. Our vanilla Macarons are made with our very own (in-house) <strong>pure extract of Madagascar vanilla</strong>, and subtly dusted with <strong>our own vanilla sugar</strong> (which we make from real vanilla beans).</p></section>"""
     doc_html = doc.as_html(lambda link_doc: "document/%s" % link_doc.id)
     # Comparing len rather than actual strings because json loading is not in a deterministic order for now
     self.assertEqual(len(expected_html), len(doc_html))
Ejemplo n.º 2
0
def test_empty_paragraph(fixture_empty_paragraph):
    doc_json = fixture_empty_paragraph
    doc = prismic.Document(doc_json)

    doc_html = doc.get_field('announcement.content').as_html(link_resolver)
    expected = """<p>X</p><p></p><p>Y</p>"""
    assert doc_html == expected
Ejemplo n.º 3
0
    def test_block_labels(self):
        doc_json = self.fixture_block_labels
        doc = prismic.Document(doc_json)

        doc_html = doc.get_field('announcement.content').as_html(PrismicTestCase.link_resolver)
        expected = """<p class="code">some code</p>"""
        self.assertEqual(doc_html, expected)
Ejemplo n.º 4
0
def test_embed():
    data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"video\":{\"type\":\"Embed\",\"value\":{\"oembed\":{\"provider_url\":\"http://www.youtube.com/\",\"type\":\"video\",\"thumbnail_height\":360,\"height\":270,\"thumbnail_url\":\"http://i1.ytimg.com/vi/baGfM6dBzs8/hqdefault.jpg\",\"width\":480,\"provider_name\":\"YouTube\",\"html\":\"<iframe width=\\\"480\\\" height=\\\"270\\\" src=\\\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\"author_name\":\"Siobhan Wilson\",\"version\":\"1.0\",\"author_url\":\"http://www.youtube.com/user/siobhanwilsonsongs\",\"thumbnail_width\":480,\"title\":\"Siobhan Wilson - All Dressed Up\",\"embed_url\":\"https://www.youtube.com/watch?v=baGfM6dBzs8\"}}}}}}"
    document = prismic.Document(json.loads(data))
    video = document.get_embed("article.video")
    # Html is the code to include to embed the object, and depends on the embedded service
    html = video and video.as_html
    assert html == "<div data-oembed=\"https://www.youtube.com/watch?v=baGfM6dBzs8\" data-oembed-type=\"video\" data-oembed-provider=\"YouTube\"><iframe width=\"480\" height=\"270\" src=\"http://www.youtube.com/embed/baGfM6dBzs8?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe></div>"
Ejemplo n.º 5
0
 def test_get_text(self):
     doc_json = self.fixture_search[0]
     doc = prismic.Document(doc_json)
     self.assertEqual(
         doc.get_text('product.description'),
         'Experience the ultimate vanilla experience. Our vanilla Macarons are made with our very own (in-house) pure extract of Madagascar vanilla, and subtly dusted with our own vanilla sugar (which we make from real vanilla beans).'
     )
Ejemplo n.º 6
0
 def test_lists(self):
     doc_json = self.fixture_structured_lists[0]
     doc = prismic.Document(doc_json)
     doc_html = doc.get_structured_text("article.content").as_html(lambda x: "/x")
     expected = ("""<ul><li>Element1</li><li>Element2</li><li>Element3</li></ul>"""
                 """<p>Ordered list:</p><ol><li>Element1</li><li>Element2</li><li>Element3</li></ol>""")
     self.assertEqual(doc_html, expected)
Ejemplo n.º 7
0
    def test_empty_paragraph(self):
        doc_json = self.fixture_empty_paragraph
        doc = prismic.Document(doc_json)

        doc_html = doc.get_field('announcement.content').as_html(PrismicTestCase.link_resolver)
        expected = """<p>X</p><p></p><p>Y</p>"""
        self.assertEqual(doc_html, expected)
Ejemplo n.º 8
0
 def test_color(self):
     data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"background\":{\"type\":\"Color\",\"value\":\"#000000\"}}}}"
     document = prismic.Document(json.loads(data))
     # startgist:c9ebba9bcbce4b4cc785:prismic-color.py
     bgcolor = document.get_color("article.background")
     hex = bgcolor.value
     # endgist
     self.assertEqual(hex, "#000000")
Ejemplo n.º 9
0
 def test_link(self):
     data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"source\":{\"type\":\"Link.document\",\"value\":{\"document\":{\"id\":\"UlfoxUnM0wkXYXbE\",\"type\":\"product\",\"tags\":[\"Macaron\"],\"slug\":\"dark-chocolate-macaron\"},\"isBroken\":false}}}}}"
     document = prismic.Document(json.loads(data))
     def resolver(document_link):
         return "/document/%s/%s" % (document_link.id, document_link.slug)
     source = document.get_link("article.source")
     url = source and source.get_url(resolver)
     self.assertEqual(url, "/document/UlfoxUnM0wkXYXbE/dark-chocolate-macaron")
Ejemplo n.º 10
0
    def test_composite_slices(self):
        self.maxDiff = 1000
        doc = prismic.Document(self.fixture_composite_slices)
        slices = doc.get_slice_zone("test.body")
        slices_html = slices.as_html(PrismicTestCase.link_resolver)
        expected_html = """<div data-slicetype="slice-a" class="slice"><section data-field="non-repeat-text"><p>Slice A non-repeat text</p></section><section data-field="non-repeat-title"><h1>Slice A non-repeat title</h1></section><section data-field="repeat-text"><p>Repeatable text A</p></section><section data-field="repeat-title"><h1>Repeatable title A</h1></section>
<section data-field="repeat-text"><p>Repeatable text B</p></section><section data-field="repeat-title"><h1>Repeatable title B</h1></section></div>
<div data-slicetype="slice-b" class="slice"><section data-field="image"><img src="https://prismic-io.s3.amazonaws.com/tails/014c1fe46e3ceaf04b7cc925b2ea7e8027dc607a_mobile_header_tp.png" alt="" width="800" height="500" /></section><section data-field="title"><h1>Slice A non-repeat title</h1></section></div>"""
        # Comparing len rather than actual strings because json loading is not in a deterministic order for now
        self.assertEqual(len(expected_html), len(slices_html))
Ejemplo n.º 11
0
def test_geopoint():
    data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"location\":{\"type\":\"GeoPoint\",\"value\":{\"latitude\":48.877108,\"longitude\":2.333879}}}}}"
    document = prismic.Document(json.loads(data))
    # "near" predicate for GeoPoint fragments
    near = predicates.near("my.store.location", 48.8768767, 2.3338802, 10)

    # Accessing GeoPoint fragments
    place = document.get_geopoint("article.location")
    coordinates = place and ("%.6f,%.6f" % (place.latitude, place.longitude))
    assert coordinates == "48.877108,2.333879"
Ejemplo n.º 12
0
 def test_group(self):
     data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"documents\":{\"type\":\"Group\",\"value\":[{\"linktodoc\":{\"type\":\"Link.document\",\"value\":{\"document\":{\"id\":\"UrDejAEAAFwMyrW9\",\"type\":\"doc\",\"tags\":[],\"slug\":\"installing-meta-micro\"},\"isBroken\":false}},\"desc\":{\"type\":\"StructuredText\",\"value\":[{\"type\":\"paragraph\",\"text\":\"A detailed step by step point of view on how installing happens.\",\"spans\":[]}]}},{\"linktodoc\":{\"type\":\"Link.document\",\"value\":{\"document\":{\"id\":\"UrDmKgEAALwMyrXA\",\"type\":\"doc\",\"tags\":[],\"slug\":\"using-meta-micro\"},\"isBroken\":false}}}]}}}}"
     document = prismic.Document(json.loads(data))
     def resolver(document_link):
         return "/document/%s/%s" % (document_link.id, document_link.slug)
     group = document.get_group("article.documents")
     docs = (group and group.value) or []
     for doc in docs:
         desc = doc.get_structured_text("desc")
         link = doc.get_link("linktodoc")
     self.assertEqual(docs[0].get_structured_text("desc").as_html(resolver), "<p>A detailed step by step point of view on how installing happens.</p>")
Ejemplo n.º 13
0
 def test_slicezone(self):
     self.maxDiff = 10000
     doc = prismic.Document(self.fixture_slices)
     slices = doc.get_slice_zone("article.blocks")
     slices_html = slices.as_html(PrismicTestCase.link_resolver)
     expected_html = (
         """<div data-slicetype="features" class="slice"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" alt="" width="4285" height="709" /></section>"""
         """<section data-field="title"><span class="text">c'est un bloc features</span></section></div>\n"""
         """<div data-slicetype="text" class="slice"><p>C'est un bloc content</p></div>""")
     # Comparing len rather than actual strings because json loading is not in a deterministic order for now
     self.assertEqual(len(expected_html), len(slices_html))
Ejemplo n.º 14
0
 def test_group(self):
     contributor = prismic.Document(self.fixture_groups)
     links = contributor.get_group("contributor.links")
     self.assertEqual(len(links.value), 2)
Ejemplo n.º 15
0
 def test_geo_point(self):
     store = prismic.Document(self.fixture_store_geopoint)
     geopoint = store.get_field("store.coordinates")
     self.assertEqual(geopoint.as_html, (
         """<div class="geopoint"><span class="latitude">37.777431</span>"""
         """<span class="longitude">-122.415419</span></div>"""))
Ejemplo n.º 16
0
def test_document(fixture_search):
    docs = [prismic.Document(doc) for doc in fixture_search]
    assert len(docs) == 3
    doc = docs[0]
    assert doc.slug == "vanilla-macaron"
Ejemplo n.º 17
0
 def setUp(self):
     super(TestFragmentsTestCase, self).setUp()
     doc_json = self.fixture_search[0]
     self.doc = prismic.Document(doc_json)
Ejemplo n.º 18
0
 def test_empty_slug(self):
     doc_json = self.fixture_search[0]
     doc_json["slugs"] = None
     doc = prismic.Document(doc_json)
     self.assertEqual(doc.slug, "-")
Ejemplo n.º 19
0
 def test_document(self):
     docs = [prismic.Document(doc) for doc in self.fixture_search]
     self.assertEqual(len(docs), 3)
     doc = docs[0]
     self.assertEqual(doc.slug, "vanilla-macaron")
Ejemplo n.º 20
0
 def test_color(self):
     data = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"background\":{\"type\":\"Color\",\"value\":\"#000000\"}}}}"
     document = prismic.Document(json.loads(data))
     bgcolor = document.get_color("article.background")
     hex = bgcolor.value
     self.assertEqual(hex, "#000000")
Ejemplo n.º 21
0
def test_empty_slug(fixture_search):
    doc_json = fixture_search[0]
    doc_json["slugs"] = None
    doc = prismic.Document(doc_json)
    assert doc.slug == "-"
Ejemplo n.º 22
0
def doc(fixture_search):
    doc_json = fixture_search[0]
    return prismic.Document(doc_json)
Ejemplo n.º 23
0
def test_block_labels(fixture_block_labels):
    doc = prismic.Document(fixture_block_labels)

    doc_html = doc.get_field('announcement.content').as_html(link_resolver)
    expected = """<p class="code">some code</p>"""
    assert doc_html == expected
Ejemplo n.º 24
0
def test_group(fixture_groups):
    contributor = prismic.Document(fixture_groups)
    links = contributor.get_group("contributor.links")
    assert len(links.value) == 2
Ejemplo n.º 25
0
 def test_document(self):
     docs = [prismic.Document(doc) for doc in self.fixture_search]
     self.assertTrue(len(docs) == 3)
     doc = docs[0]
     self.assertTrue(doc.slug == "vanilla-macaron")