Sometimes the information is returned in a json wrapper
(self)
| 107 | @pytest.mark.skipif(not PARSEL_18_PLUS, reason="parsel < 1.8 doesn't support jmespath") |
| 108 | class TestJMESPath: |
| 109 | def test_json_has_html(self) -> None: |
| 110 | """Sometimes the information is returned in a json wrapper""" |
| 111 | |
| 112 | body = """ |
| 113 | { |
| 114 | "content": [ |
| 115 | { |
| 116 | "name": "A", |
| 117 | "value": "a" |
| 118 | }, |
| 119 | { |
| 120 | "name": { |
| 121 | "age": 18 |
| 122 | }, |
| 123 | "value": "b" |
| 124 | }, |
| 125 | { |
| 126 | "name": "C", |
| 127 | "value": "c" |
| 128 | }, |
| 129 | { |
| 130 | "name": "<a>D</a>", |
| 131 | "value": "<div>d</div>" |
| 132 | } |
| 133 | ], |
| 134 | "html": "<div><a>a<br>b</a>c</div><div><a>d</a>e<b>f</b></div>" |
| 135 | } |
| 136 | """ |
| 137 | resp = TextResponse(url="http://example.com", body=body, encoding="utf-8") |
| 138 | assert ( |
| 139 | resp.jmespath("html").get() |
| 140 | == "<div><a>a<br>b</a>c</div><div><a>d</a>e<b>f</b></div>" |
| 141 | ) |
| 142 | assert resp.jmespath("html").xpath("//div/a/text()").getall() == ["a", "b", "d"] |
| 143 | assert resp.jmespath("html").css("div > b").getall() == ["<b>f</b>"] |
| 144 | assert resp.jmespath("content").jmespath("name.age").get() == "18" |
| 145 | |
| 146 | def test_html_has_json(self) -> None: |
| 147 | body = """ |
nothing calls this directly
no test coverage detected