Skip to content

Commit ba81d3b

Browse files
committed
Fix pypi#212 - Allow configuration of the search index
1 parent 7497455 commit ba81d3b

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

tests/search/test_indexes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_reindex(self, monkeypatch):
3232
monkeypatch.setattr(os, "urandom", urandom)
3333

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

3737
index = Index(models, config)
3838
index.es = pretend.stub(
@@ -69,7 +69,7 @@ def test_reindex_no_alias(self, monkeypatch):
6969
monkeypatch.setattr(os, "urandom", urandom)
7070

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

7474
index = Index(models, config)
7575
index.es = pretend.stub(
@@ -101,7 +101,7 @@ def test_reindex_no_alias(self, monkeypatch):
101101

102102
def test_update_alias(self):
103103
models = pretend.stub()
104-
config = pretend.stub(hosts=[], get=lambda *a: {})
104+
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})
105105

106106
index = Index(models, config)
107107
index.es = pretend.stub(
@@ -134,7 +134,7 @@ def test_update_alias(self):
134134

135135
def test_update_alias_no_old_index(self):
136136
models = pretend.stub()
137-
config = pretend.stub(hosts=[], get=lambda *a: {})
137+
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})
138138

139139
def _get_alias(idx):
140140
raise TransportError(404, "Fake 404")
@@ -160,7 +160,7 @@ def _get_alias(idx):
160160

161161
def test_update_alias_exception(self):
162162
models = pretend.stub()
163-
config = pretend.stub(hosts=[], get=lambda *a: {})
163+
config = pretend.stub(index="warehouse", hosts=[], get=lambda *a: {})
164164

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

tests/test_application.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_basic_instantiation():
4141
"url": "redis://localhost:6379/0"
4242
},
4343
"search": {
44+
"index": "warehouse",
4445
"hosts": [],
4546
},
4647
"logging": {

warehouse/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ site:
44
name: Warehouse
55
url: /
66

7+
search:
8+
index: warehouse
9+
710
paths:
811
documentation: data/packagedocs
912

warehouse/search/indexes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
class Index(object):
2727

28-
_index = "warehouse"
29-
3028
def __init__(self, db, config):
3129
self.db = db
3230
self.config = config
@@ -37,14 +35,16 @@ def __init__(self, db, config):
3735

3836
self.types = AttributeDict()
3937

38+
self._index = config.index
39+
4040
def register(self, type_):
4141
obj = type_(self)
4242
self.types[obj._type] = obj
4343

44-
def reindex(self, index=None, alias=True, keep_old=False):
44+
def reindex(self, alias=True, keep_old=False):
4545
# Generate an Index Name for Warehouse
4646
index = "".join([
47-
index if index is not None else self._index,
47+
self._index,
4848
hashlib.md5(os.urandom(16)).hexdigest()[:8],
4949
])
5050

0 commit comments

Comments
 (0)