Esempio n. 1
0
    def test_searches_with_and(self):
        class FakeQuery:
            def __init__(self, type, must):
                self.type = type
                self.must = must

            def __getitem__(self, name):
                self.offset = name.start
                self.limit = name.stop
                self.step = name.step
                return self

            def execute(self):
                assert self.type == "bool"
                assert [q.to_dict() for q in self.must] == [
                    {"match": {"name": "foo"}},
                    {
                        "bool": {
                            "should": [
                                {"match": {"summary": "one"}},
                                {"match": {"summary": "two"}},
                            ],
                        },
                    },
                ]
                assert self.offset is None
                assert self.limit == 1000
                assert self.step is None
                return [
                    pretend.stub(
                        name="foo",
                        summary="my summary",
                        version=["1.0"],
                    ),
                    pretend.stub(
                        name="foo-bar",
                        summary="other summary",
                        version=["2.0", "1.0"],
                    ),
                ]

        request = pretend.stub(es=pretend.stub(query=FakeQuery))
        results = xmlrpc.search(
            request,
            {"name": "foo", "summary": ["one", "two"]},
            "and",
        )
        assert results == [
            {"name": "foo", "summary": "my summary", "version": "1.0"},
            {"name": "foo-bar", "summary": "other summary", "version": "2.0"},
            {"name": "foo-bar", "summary": "other summary", "version": "1.0"},
        ]
Esempio n. 2
0
    def test_searches_with_and(self):
        class FakeQuery:
            def __init__(self, type, must):
                self.type = type
                self.must = must

            def __getitem__(self, name):
                self.offset = name.start
                self.limit = name.stop
                self.step = name.step
                return self

            def execute(self):
                assert self.type == "bool"
                assert [q.to_dict() for q in self.must] == [
                    {"match": {"name": "foo"}},
                    {
                        "bool": {
                            "should": [
                                {"match": {"summary": "one"}},
                                {"match": {"summary": "two"}},
                            ],
                        },
                    },
                ]
                assert self.offset is None
                assert self.limit == 1000
                assert self.step is None
                return [
                    pretend.stub(
                        name="foo",
                        summary="my summary",
                        version=["1.0"],
                    ),
                    pretend.stub(
                        name="foo-bar",
                        summary="other summary",
                        version=["2.0", "1.0"],
                    ),
                ]

        request = pretend.stub(es=pretend.stub(query=FakeQuery))
        results = xmlrpc.search(
            request,
            {"name": "foo", "summary": ["one", "two"]},
            "and",
        )
        assert results == [
            {"name": "foo", "summary": "my summary", "version": "1.0"},
            {"name": "foo-bar", "summary": "other summary", "version": "2.0"},
            {"name": "foo-bar", "summary": "other summary", "version": "1.0"},
        ]
Esempio n. 3
0
    def test_default_search_operator_with_spaces_in_values(self):
        class FakeQuery:
            def __init__(self, type, must):
                self.type = type
                self.must = must

            def __getitem__(self, name):
                self.offset = name.start
                self.limit = name.stop
                self.step = name.step
                return self

            def execute(self):
                assert self.type == "bool"
                assert [q.to_dict() for q in self.must] == [
                    {'bool': {'should': [
                        {'term': {'summary': 'fix code'}},
                        {'term': {'summary': 'like this'}}
                    ]}}
                ]
                assert self.offset is None
                assert self.limit == 1000
                assert self.step is None
                return [
                    pretend.stub(
                        name="foo",
                        summary="fix code",
                        version=["1.0"],
                    ),
                    pretend.stub(
                        name="foo-bar",
                        summary="like this",
                        version=["2.0", "1.0"],
                    ),
                ]

        request = pretend.stub(es=pretend.stub(query=FakeQuery))
        results = xmlrpc.search(
            request,
            {"summary": ["fix code", "like this"]},
        )
        assert results == [
            {"name": "foo", "summary": "fix code", "version": "1.0"},
            {"name": "foo-bar", "summary": "like this", "version": "2.0"},
            {"name": "foo-bar", "summary": "like this", "version": "1.0"},
        ]
Esempio n. 4
0
 def test_fails_with_invalid_operator(self):
     with pytest.raises(ValueError):
         xmlrpc.search(pretend.stub(), {}, "lol nope")
Esempio n. 5
0
    def test_fails_if_spec_not_mapping(self):
        with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
            xmlrpc.search(pretend.stub(), "a string")

        assert exc.value.faultString == \
            "TypeError: Invalid spec, must be a mapping/dictionary."
Esempio n. 6
0
    def test_fails_with_invalid_operator(self):
        with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
            xmlrpc.search(pretend.stub(), {}, "lol nope")

        assert exc.value.faultString == \
            "ValueError: Invalid operator, must be one of 'and' or 'or'."
Esempio n. 7
0
    def test_default_search_operator_with_spaces_in_values(self):
        class FakeQuery:
            def __init__(self, type, must):
                self.type = type
                self.must = must

            def __getitem__(self, name):
                self.offset = name.start
                self.limit = name.stop
                self.step = name.step
                return self

            def execute(self):
                assert self.type == "bool"
                assert [q.to_dict() for q in self.must] == [{
                    'bool': {
                        'should': [{
                            'term': {
                                'summary': 'fix code'
                            }
                        }, {
                            'term': {
                                'summary': 'like this'
                            }
                        }]
                    }
                }]
                assert self.offset is None
                assert self.limit == 1000
                assert self.step is None
                return [
                    pretend.stub(
                        name="foo",
                        summary="fix code",
                        version=["1.0"],
                    ),
                    pretend.stub(
                        name="foo-bar",
                        summary="like this",
                        version=["2.0", "1.0"],
                    ),
                ]

        request = pretend.stub(es=pretend.stub(query=FakeQuery))
        results = xmlrpc.search(
            request,
            {"summary": ["fix code", "like this"]},
        )
        assert results == [
            {
                "name": "foo",
                "summary": "fix code",
                "version": "1.0"
            },
            {
                "name": "foo-bar",
                "summary": "like this",
                "version": "2.0"
            },
            {
                "name": "foo-bar",
                "summary": "like this",
                "version": "1.0"
            },
        ]
Esempio n. 8
0
    def test_fails_if_spec_not_mapping(self):
        with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
            xmlrpc.search(pretend.stub(), "a string")

        assert exc.value.faultString == \
            "TypeError: Invalid spec, must be a mapping/dictionary."
Esempio n. 9
0
    def test_fails_with_invalid_operator(self):
        with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
            xmlrpc.search(pretend.stub(), {}, "lol nope")

        assert exc.value.faultString == \
            "ValueError: Invalid operator, must be one of 'and' or 'or'."
Esempio n. 10
0
 def test_fails_with_invalid_operator(self):
     with pytest.raises(ValueError):
         xmlrpc.search(pretend.stub(), {}, "lol nope")