Beispiel #1
0
def test_term_clause():
    body = {"user": {"value": "Kimchy", "boost": 1}}
    expected = {"term": body}

    q1 = Term(field="user", value="Kimchy", boost=1)
    q2 = Term(user={"value": "Kimchy", "boost": 1})
    for q in (q1, q2):
        assert q.body == body
        assert q.to_dict() == expected
        assert q.line_repr(depth=None) == (
            "term",
            'field=user, boost=1, value="Kimchy"',
        )

    # other format
    q3 = Term(user="******")
    assert q3.body == {"user": {"value": "Kimchy"}}
    assert q3.to_dict() == {"term": {"user": {"value": "Kimchy"}}}
    assert q3.line_repr(depth=None) == ("term", 'field=user, value="Kimchy"')
    def test_term_clause(self):
        body = {"user": {"value": "Kimchy", "boost": 1}}
        expected = {"term": body}

        q1 = Term(field="user", value="Kimchy", boost=1)
        q2 = Term(user={"value": "Kimchy", "boost": 1})
        for q in (q1, q2):
            self.assertEqual(q.body, body)
            self.assertEqual(q.serialize(), expected)
            self.assertEqual(q.line_repr(depth=None),
                             'term, field=user, boost=1, value="Kimchy"')

        # other format
        q3 = Term(user="******")
        self.assertEqual(q3.body, {"user": {"value": "Kimchy"}})
        self.assertEqual(q3.serialize(),
                         {"term": {
                             "user": {
                                 "value": "Kimchy"
                             }
                         }})
        self.assertEqual(q3.line_repr(depth=None),
                         'term, field=user, value="Kimchy"')