コード例 #1
0
ファイル: test_xmlrpc.py プロジェクト: KamodaP/warehouse
    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"},
        ]
コード例 #2
0
ファイル: test_xmlrpc.py プロジェクト: zooba/warehouse
    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"},
        ]
コード例 #3
0
ファイル: test_xmlrpc.py プロジェクト: ewdurbin/warehouse
    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"},
        ]
コード例 #4
0
ファイル: test_xmlrpc.py プロジェクト: KamodaP/warehouse
 def test_fails_with_invalid_operator(self):
     with pytest.raises(ValueError):
         xmlrpc.search(pretend.stub(), {}, "lol nope")
コード例 #5
0
ファイル: test_xmlrpc.py プロジェクト: sethmlarson/warehouse
    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."
コード例 #6
0
ファイル: test_xmlrpc.py プロジェクト: sethmlarson/warehouse
    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'."
コード例 #7
0
ファイル: test_xmlrpc.py プロジェクト: sethmlarson/warehouse
    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"
            },
        ]
コード例 #8
0
ファイル: test_xmlrpc.py プロジェクト: ewdurbin/warehouse
    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."
コード例 #9
0
ファイル: test_xmlrpc.py プロジェクト: ewdurbin/warehouse
    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'."
コード例 #10
0
 def test_fails_with_invalid_operator(self):
     with pytest.raises(ValueError):
         xmlrpc.search(pretend.stub(), {}, "lol nope")