Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 75a8236

Browse files
authored
Merge pull request #342 from cloudant/341-remove-replicator-src-trg-parameters
Removed source and target optional parameters from replicator API
2 parents 8f262c9 + bc7cc41 commit 75a8236

4 files changed

Lines changed: 23 additions & 78 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.8.0 (Unreleased)
22
==================
3+
- [REMOVED] Removed broken source and target parameters that constantly threw ``AttributeError`` when creating a replication document.
34

45
2.7.0 (2017-10-31)
56
==================

src/cloudant/replicator.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ def create_replication(self, source_db=None, target_db=None,
5050
``CouchDatabase`` or ``CloudantDatabase`` instance.
5151
:param str repl_id: Optional replication id. Generated internally if
5252
not explicitly set.
53-
:param source: Optional ``str`` or ``dict`` representing the source
54-
database, along with authentication info, if any. Composed
55-
internally if not explicitly set and not in CouchDB Admin Party
56-
mode.
57-
:param target: Optional ``str`` or ``dict`` representing the
58-
target database, possibly including authentication info. Composed
59-
internally if not explicitly set and not in CouchDB Admin Party
60-
mode.
6153
:param dict user_ctx: Optional user to act as. Composed internally
6254
if not explicitly set and not in CouchDB Admin Party
6355
mode.
@@ -74,26 +66,25 @@ def create_replication(self, source_db=None, target_db=None,
7466
**kwargs
7567
)
7668

77-
if not data.get('source'):
78-
if source_db is None:
79-
raise CloudantReplicatorException(101)
80-
data['source'] = {'url': source_db.database_url}
81-
if not source_db.admin_party:
82-
data['source'].update(
83-
{'headers': {'Authorization': source_db.creds['basic_auth']}}
84-
)
85-
86-
if not data.get('target'):
87-
if target_db is None:
88-
raise CloudantReplicatorException(102)
89-
data['target'] = {'url': target_db.database_url}
90-
if not target_db.admin_party:
91-
data['target'].update(
92-
{'headers': {'Authorization': target_db.creds['basic_auth']}}
93-
)
69+
if source_db is None:
70+
raise CloudantReplicatorException(101)
71+
data['source'] = {'url': source_db.database_url}
72+
if not source_db.admin_party:
73+
data['source'].update(
74+
{'headers': {'Authorization': source_db.creds['basic_auth']}}
75+
)
76+
77+
if target_db is None:
78+
raise CloudantReplicatorException(102)
79+
data['target'] = {'url': target_db.database_url}
80+
if not target_db.admin_party:
81+
data['target'].update(
82+
{'headers': {'Authorization': target_db.creds['basic_auth']}}
83+
)
9484

9585
if not data.get('user_ctx'):
96-
if not target_db.admin_party:
86+
if (target_db and not target_db.admin_party or
87+
self.database.creds):
9788
data['user_ctx'] = self.database.creds['user_ctx']
9889

9990
return self.database.create_document(data, throw_on_exists=True)

tests/integration/replicator_test.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -190,57 +190,6 @@ def test_follow_replication(self):
190190
self.assertTrue(len(updates) > 0)
191191
self.assertEqual(updates[-1]['_replication_state'], 'completed')
192192

193-
@unittest.skip("Doesn't reliably get into error state on couch side.")
194-
def test_follow_replication_with_errors(self):
195-
"""
196-
_test_follow_replication_with_errors_
197-
198-
Test to make sure that we exit the follow loop when we submit
199-
a bad replication.
200-
201-
"""
202-
dbsource = unicode_("test_follow_replication_source_error_{}".format(
203-
unicode_(uuid.uuid4())))
204-
dbtarget = unicode_("test_follow_replication_target_error_{}".format(
205-
unicode_(uuid.uuid4())))
206-
207-
self.dbs = [dbsource, dbtarget]
208-
209-
with cloudant(self.user, self.passwd, account=self.user) as c:
210-
dbs = c.create_database(dbsource)
211-
dbt = c.create_database(dbtarget)
212-
213-
doc1 = dbs.create_document(
214-
{"_id": "doc1", "testing": "document 1"}
215-
)
216-
doc2 = dbs.create_document(
217-
{"_id": "doc2", "testing": "document 1"}
218-
)
219-
doc3 = dbs.create_document(
220-
{"_id": "doc3", "testing": "document 1"}
221-
)
222-
223-
replicator = Replicator(c)
224-
repl_id = unicode_("test_follow_replication_{}".format(
225-
unicode_(uuid.uuid4())))
226-
self.replication_ids.append(repl_id)
227-
228-
ret = replicator.create_replication(
229-
source_db=dbs,
230-
target_db=dbt,
231-
# Deliberately override these good params with bad params
232-
source=dbsource + "foo",
233-
target=dbtarget + "foo",
234-
repl_id=repl_id,
235-
continuous=False,
236-
)
237-
updates = [
238-
update for update in replicator.follow_replication(repl_id)
239-
]
240-
self.assertTrue(len(updates) > 0)
241-
self.assertEqual(updates[-1]['_replication_state'], 'error')
242-
243-
244193
def test_replication_state(self):
245194
"""
246195
_test_replication_state_

tests/unit/replicator_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ def test_constructor_failure(self):
155155

156156
def test_replication_with_generated_id(self):
157157
clone = Replicator(self.client)
158-
clone.create_replication(self.db, self.target_db)
158+
repl_id = clone.create_replication(
159+
self.db,
160+
self.target_db
161+
)
162+
self.replication_ids.append(repl_id['_id'])
159163

160164
@skip_if_not_cookie_auth
161165
@flaky(max_runs=3)

0 commit comments

Comments
 (0)