Beispiel #1
0
    def test_reindex_no_alias(self, monkeypatch):
        urandom = pretend.call_recorder(lambda s: b"0" * s)
        monkeypatch.setattr(os, "urandom", urandom)

        models = pretend.stub()
        config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

        index = Index(models, config)
        index.es = pretend.stub(
            indices=pretend.stub(
                create=pretend.call_recorder(lambda idx, body: None),
            ),
        )
        index.types = {
            "fake": pretend.stub(
                _type="fake",
                get_mapping=pretend.call_recorder(lambda: {"foo": "bar"}),
                index_all=pretend.call_recorder(lambda index: None),
            ),
        }
        index.update_alias = pretend.call_recorder(lambda *a, **kw: None)

        index.reindex(alias=False)

        assert index.es.indices.create.calls == [
            pretend.call(
                "warehouse30303030",
                {"mappings": {"fake": {"foo": "bar"}}},
            ),
        ]
        assert index.update_alias.calls == []
        assert index.types["fake"].index_all.calls == [
            pretend.call(index="warehouse30303030"),
        ]
Beispiel #2
0
    def test_update_alias_no_old_index(self):
        models = pretend.stub()
        config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

        def _get_alias(idx):
            raise TransportError(404, "Fake 404")

        index = Index(models, config)
        index.es = pretend.stub(
            indices=pretend.stub(
                get_alias=pretend.call_recorder(_get_alias),
                update_aliases=pretend.call_recorder(lambda actions: None),
                delete=pretend.call_recorder(lambda idx: None)
            ),
        )

        index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]
        assert index.es.indices.update_aliases.calls == [
            pretend.call({"actions": [
                {"add": {"index": "warehouse7654321", "alias": "warehouse"}}
            ]}),
        ]
        assert index.es.indices.delete.calls == []
Beispiel #3
0
    def test_update_alias(self):
        models = pretend.stub()
        config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

        index = Index(models, config)
        index.es = pretend.stub(
            indices=pretend.stub(
                get_alias=pretend.call_recorder(
                    lambda idx: {"warehouse1234567": "warehouse"},
                ),
                update_aliases=pretend.call_recorder(lambda actions: None),
                delete=pretend.call_recorder(lambda idx: None)
            ),
        )

        index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]
        assert index.es.indices.update_aliases.calls == [
            pretend.call({"actions": [
                {
                    "remove": {
                        "index": "warehouse1234567",
                        "alias": "warehouse",
                    },
                },
                {"add": {"index": "warehouse7654321", "alias": "warehouse"}}
            ]}),
        ]
        assert index.es.indices.delete.calls == [
            pretend.call("warehouse1234567"),
        ]
Beispiel #4
0
    def test_update_alias_no_old_index(self):
        models = pretend.stub()
        config = pretend.stub(hosts=[], get=lambda *a: {})

        def _get_alias(idx):
            raise TransportError(404, "Fake 404")

        index = Index(models, config)
        index.es = pretend.stub(indices=pretend.stub(
            get_alias=pretend.call_recorder(_get_alias),
            update_aliases=pretend.call_recorder(lambda actions: None),
            delete=pretend.call_recorder(lambda idx: None)), )

        index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]
        assert index.es.indices.update_aliases.calls == [
            pretend.call({
                "actions": [{
                    "add": {
                        "index": "warehouse7654321",
                        "alias": "warehouse"
                    }
                }]
            }),
        ]
        assert index.es.indices.delete.calls == []
Beispiel #5
0
    def test_update_alias(self):
        models = pretend.stub()
        config = pretend.stub(hosts=[], get=lambda *a: {})

        index = Index(models, config)
        index.es = pretend.stub(indices=pretend.stub(
            get_alias=pretend.call_recorder(
                lambda idx: {"warehouse1234567": "warehouse"}, ),
            update_aliases=pretend.call_recorder(lambda actions: None),
            delete=pretend.call_recorder(lambda idx: None)), )

        index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]
        assert index.es.indices.update_aliases.calls == [
            pretend.call({
                "actions": [{
                    "remove": {
                        "index": "warehouse1234567",
                        "alias": "warehouse",
                    },
                }, {
                    "add": {
                        "index": "warehouse7654321",
                        "alias": "warehouse"
                    }
                }]
            }),
        ]
        assert index.es.indices.delete.calls == [
            pretend.call("warehouse1234567"),
        ]
Beispiel #6
0
    def test_reindex_no_alias(self, monkeypatch):
        urandom = pretend.call_recorder(lambda s: b"0" * s)
        monkeypatch.setattr(os, "urandom", urandom)

        models = pretend.stub()
        config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

        index = Index(models, config)
        index.es = pretend.stub(
            indices=pretend.stub(
                create=pretend.call_recorder(lambda idx, body: None),
            ),
        )
        index.types = {
            "fake": pretend.stub(
                _type="fake",
                get_mapping=pretend.call_recorder(lambda: {"foo": "bar"}),
                index_all=pretend.call_recorder(lambda index: None),
            ),
        }
        index.update_alias = pretend.call_recorder(lambda *a, **kw: None)

        index.reindex(alias=False)

        assert index.es.indices.create.calls == [
            pretend.call(
                "warehouse30303030",
                {"mappings": {"fake": {"foo": "bar"}}},
            ),
        ]
        assert index.update_alias.calls == []
        assert index.types["fake"].index_all.calls == [
            pretend.call(index="warehouse30303030"),
        ]
Beispiel #7
0
    def test_update_alias_exception(self):
        models = pretend.stub()
        config = pretend.stub(hosts=[], get=lambda *a: {})

        def _get_alias(idx):
            raise TransportError(500, "Fake 500")

        index = Index(models, config)
        index.es = pretend.stub(indices=pretend.stub(
            get_alias=pretend.call_recorder(_get_alias), ), )

        with pytest.raises(TransportError):
            index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]
Beispiel #8
0
    def test_update_alias_exception(self):
        models = pretend.stub()
        config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})

        def _get_alias(idx):
            raise TransportError(500, "Fake 500")

        index = Index(models, config)
        index.es = pretend.stub(
            indices=pretend.stub(
                get_alias=pretend.call_recorder(_get_alias),
            ),
        )

        with pytest.raises(TransportError):
            index.update_alias("warehouse", "warehouse7654321")

        assert index.es.indices.get_alias.calls == [pretend.call("warehouse")]