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

Commit b563aa4

Browse files
committed
Updated Travis CI and unit tests to run against CouchDB 2.1.1
1 parent da26eb2 commit b563aa4

File tree

6 files changed

+135
-91
lines changed

6 files changed

+135
-91
lines changed

.travis.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
sudo: required
2+
13
language: python
24

35
python:
@@ -9,9 +11,20 @@ env:
911
- ADMIN_PARTY=false
1012

1113
services:
12-
- couchdb
14+
- docker
15+
16+
before_install:
17+
- docker pull apache/couchdb:2.1.1
18+
- docker run -d -it -p 5984:5984 apache/couchdb:2.1.1 --with-admin-party-please --with-haproxy
1319

1420
install: "pip install -r requirements.txt && pip install -r test-requirements.txt"
21+
22+
before_script:
23+
# Make sure CouchDB is up
24+
- while [ $? -ne 0 ]; do sleep 1 && curl -v http://localhost:5984; done
25+
- curl -X PUT http://localhost:5984/_users
26+
- curl -X PUT http://localhost:5984/_replicator
27+
1528
# command to run tests
1629
script:
1730
- pylint ./src/cloudant

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [IMPROVED] Updated Travis CI and unit tests to run against CouchDB 2.1.1.
4+
35
# 2.8.1 (2018-02-16)
46

57
- [FIXED] Installation failures of 2.8.0 caused by missing VERSION file in distribution.

tests/unit/changes_tests.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2016 IBM. All rights reserved.
2+
# Copyright (C) 2016, 2018 IBM Corp. All rights reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
from cloudant.feed import Feed
2525
from cloudant.document import Document
2626
from cloudant.design_document import DesignDocument
27-
from cloudant.error import CloudantArgumentError, CloudantException
27+
from cloudant.error import CloudantArgumentError
2828
from cloudant._2to3 import unicode_
2929

3030
from .unit_t_db_base import UnitTestDbBase
@@ -100,12 +100,7 @@ def test_get_raw_content(self):
100100
self.assertIsInstance(raw_line, BYTETYPE)
101101
raw_content.append(raw_line)
102102
changes = json.loads(''.join([unicode_(x) for x in raw_content]))
103-
if self.cloudant_test:
104-
self.assertSetEqual(
105-
set(changes.keys()), set(['results', 'last_seq', 'pending']))
106-
else:
107-
self.assertSetEqual(
108-
set(changes.keys()), set(['results', 'last_seq']))
103+
self.assertSetEqual(set(changes.keys()), set(['results', 'last_seq', 'pending']))
109104
results = list()
110105
for result in changes['results']:
111106
self.assertSetEqual(set(result.keys()), set(['seq', 'changes', 'id']))
@@ -223,29 +218,25 @@ def test_get_raw_feed_with_heartbeat(self):
223218

224219
def test_get_feed_descending(self):
225220
"""
226-
Test getting content back for a descending feed. When testing with
227-
Cloudant the sequence identifier is in the form of
228-
<number prefix>-<random char seq>. Often times the number prefix sorts
229-
as expected when using descending but sometimes the number prefix is
230-
repeated. In these cases the check is to see if the following random
231-
character sequence suffix is longer than its predecessor.
221+
Test getting content back for a descending feed. When testing, the sequence
222+
identifier is in the form of <number prefix>-<random char seq>. Often times
223+
the number prefix sorts as expected when using descending but sometimes the
224+
number prefix is repeated. In these cases the check is to see if the following
225+
random character sequence suffix is longer than its predecessor.
232226
"""
233227
self.populate_db_with_documents(50)
234228
feed = Feed(self.db, descending=True)
235229
seq_list = list()
236230
last_seq = None
237231
for change in feed:
238232
if last_seq:
239-
if self.cloudant_test:
240-
current = int(change['seq'][0: change['seq'].find('-')])
241-
last = int(last_seq[0:last_seq.find('-')])
242-
try:
243-
self.assertTrue(current < last)
244-
except AssertionError:
245-
self.assertEqual(current, last)
246-
self.assertTrue(len(change['seq']) > len(last_seq))
247-
else:
248-
self.assertTrue(change['seq'] < last_seq)
233+
current = int(change['seq'][0: change['seq'].find('-')])
234+
last = int(last_seq[0:last_seq.find('-')])
235+
try:
236+
self.assertTrue(current < last)
237+
except AssertionError:
238+
self.assertEqual(current, last)
239+
self.assertTrue(len(change['seq']) > len(last_seq))
249240
seq_list.append(change['seq'])
250241
last_seq = change['seq']
251242
self.assertEqual(len(seq_list), 50)
@@ -303,8 +294,6 @@ def test_get_feed_using_style_all_docs(self):
303294
changes = list()
304295
for change in feed:
305296
self.assertSetEqual(set(change.keys()), set(['seq', 'changes', 'id']))
306-
if not self.cloudant_test:
307-
self.assertEqual(len(change['changes']), 2)
308297
changes.append(change)
309298
expected = set(['julia000', 'julia001', 'julia002'])
310299
self.assertSetEqual(set([x['id'] for x in changes]), expected)

tests/unit/db_updates_tests.py

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2016 IBM. All rights reserved.
2+
# Copyright (C) 2016, 2018 IBM Corp. All rights reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -22,9 +22,7 @@
2222
import os
2323

2424
from cloudant.feed import Feed
25-
from cloudant.document import Document
26-
from cloudant.design_document import DesignDocument
27-
from cloudant.error import CloudantArgumentError, CloudantException
25+
from cloudant.error import CloudantArgumentError
2826
from cloudant._2to3 import unicode_
2927

3028
from .unit_t_db_base import UnitTestDbBase
@@ -34,25 +32,63 @@ class DbUpdatesTestsBase(UnitTestDbBase):
3432
"""
3533
Common _db_updates tests methods
3634
"""
37-
35+
3836
def setUp(self):
3937
"""
4038
Set up test attributes
4139
"""
4240
super(DbUpdatesTestsBase, self).setUp()
4341
self.client.connect()
42+
self.db_names = list()
4443
self.new_dbs = list()
44+
self.create_db_updates()
45+
self.create_dbs()
4546

4647
def tearDown(self):
4748
"""
4849
Reset test attributes
4950
"""
51+
test_dbs_deleted = False
52+
changes = list()
5053
[db.delete() for db in self.new_dbs]
54+
# Check the changes in the _db_updates feed to assert that the test databases are deleted
55+
while not test_dbs_deleted:
56+
feed = Feed(self.client, timeout=1000)
57+
for change in feed:
58+
if change['db_name'] in self.db_names and change['type'] == 'deleted':
59+
changes.append(change)
60+
if len(changes) == 2:
61+
test_dbs_deleted = True
62+
feed.stop()
63+
self.delete_db_updates()
5164
self.client.disconnect()
5265
super(DbUpdatesTestsBase, self).tearDown()
5366

54-
def create_dbs(self, count=3):
55-
self.new_dbs += [(self.client.create_database(self.dbname())) for x in range(count)]
67+
def create_dbs(self):
68+
self.db_names = [self.dbname() for x in range(2)]
69+
self.new_dbs += [self.client.create_database(dbname) for dbname in self.db_names]
70+
# Verify that all created databases are listed in _db_updates
71+
all_dbs_exist = False
72+
while not all_dbs_exist:
73+
changes = list()
74+
feed = Feed(self.client, timeout=1000)
75+
for change in feed:
76+
changes.append(change)
77+
if len(changes) == 3:
78+
all_dbs_exist = True
79+
feed.stop()
80+
81+
def assert_changes_in_db_updates_feed(self, changes):
82+
"""
83+
Assert that databases created in setup for db_updates_tests exist when looping through _db_updates feed
84+
Note: During the creation of _global_changes database, a doc called '_dbs' is created and seen in _db_updates
85+
"""
86+
self.dbs = ['_dbs', self.new_dbs[0].database_name, self.new_dbs[1].database_name]
87+
types = ['created', 'updated']
88+
for doc in changes:
89+
self.assertIsNotNone(doc['seq'])
90+
self.assertTrue(doc['db_name'] in self.dbs)
91+
self.assertTrue(doc['type'] in types)
5692

5793
@unittest.skipIf(os.environ.get('RUN_CLOUDANT_TESTS'),
5894
'Skipping CouchDB _db_updates feed tests')
@@ -80,45 +116,25 @@ def test_stop_iteration_of_continuous_feed_with_heartbeat(self):
80116
feed = Feed(self.client, feed='continuous', timeout=100)
81117
changes = list()
82118
for change in feed:
83-
if not change:
84-
if not self.new_dbs:
85-
self.create_dbs(5)
86-
else:
87-
continue
88-
else:
89-
changes.append(change)
90-
if len(changes) == 3:
91-
feed.stop()
92-
self.assertEqual(len(self.new_dbs), 5)
119+
changes.append(change)
120+
if len(changes) == 3:
121+
feed.stop()
122+
self.assert_changes_in_db_updates_feed(changes)
93123
self.assertEqual(len(changes), 3)
94-
self.assertDictEqual(
95-
changes[0], {'db_name': self.new_dbs[0].database_name, 'type': 'created'})
96-
self.assertDictEqual(
97-
changes[1], {'db_name': self.new_dbs[1].database_name, 'type': 'created'})
98-
self.assertDictEqual(
99-
changes[2], {'db_name': self.new_dbs[2].database_name, 'type': 'created'})
100124

101125
def test_get_raw_content(self):
102126
"""
103127
Test getting raw feed content
104128
"""
105-
feed = Feed(self.client, raw_data='True', feed='continuous', timeout=100)
129+
feed = Feed(self.client, raw_data=True, feed='continuous', timeout=100)
106130
raw_content = list()
107131
for raw_line in feed:
108132
self.assertIsInstance(raw_line, BYTETYPE)
109-
if not raw_line:
110-
self.create_dbs(3)
111-
else:
112-
raw_content.append(raw_line)
113-
if len(raw_content) == 3:
114-
feed.stop()
133+
raw_content.append(raw_line)
134+
if len(raw_content) == 3:
135+
feed.stop()
115136
changes = [json.loads(unicode_(x)) for x in raw_content]
116-
self.assertDictEqual(
117-
changes[0], {'db_name': self.new_dbs[0].database_name, 'type': 'created'})
118-
self.assertDictEqual(
119-
changes[1], {'db_name': self.new_dbs[1].database_name, 'type': 'created'})
120-
self.assertDictEqual(
121-
changes[2], {'db_name': self.new_dbs[2].database_name, 'type': 'created'})
137+
self.assert_changes_in_db_updates_feed(changes)
122138

123139
def test_get_longpoll_feed_as_default(self):
124140
"""
@@ -127,10 +143,10 @@ def test_get_longpoll_feed_as_default(self):
127143
feed = Feed(self.client, timeout=1000)
128144
changes = list()
129145
for change in feed:
130-
self.assertIsNone(change)
146+
self.assertIsNotNone(change)
131147
changes.append(change)
132-
self.assertEqual(len(changes), 1)
133-
self.assertIsNone(changes[0])
148+
self.assert_changes_in_db_updates_feed(changes)
149+
self.assertEqual(len(changes), 3)
134150

135151
def test_get_longpoll_feed_explicit(self):
136152
"""
@@ -140,18 +156,25 @@ def test_get_longpoll_feed_explicit(self):
140156
feed = Feed(self.client, timeout=1000, feed='longpoll')
141157
changes = list()
142158
for change in feed:
143-
self.assertIsNone(change)
159+
self.assertIsNotNone(change)
144160
changes.append(change)
145-
self.assertEqual(len(changes), 1)
146-
self.assertIsNone(changes[0])
161+
self.assert_changes_in_db_updates_feed(changes)
162+
self.assertEqual(len(changes), 3)
147163

148164
def test_get_continuous_with_timeout(self):
149165
"""
150166
Test getting content back for a "continuous" feed with timeout set
151167
and no heartbeat
152168
"""
153169
feed = Feed(self.client, feed='continuous', heartbeat=False, timeout=1000)
154-
self.assertListEqual([x for x in feed], [])
170+
changes = list()
171+
for change in feed:
172+
self.assertIsNotNone(change)
173+
changes.append(change)
174+
if len(changes) == 3:
175+
feed.stop()
176+
self.assert_changes_in_db_updates_feed(changes)
177+
self.assertEqual(len(changes), 3)
155178

156179
def test_invalid_argument(self):
157180
"""
@@ -249,7 +272,6 @@ def test_stop_iteration_of_continuous_feed_using_since_now(self):
249272
feed = Feed(self.client, feed='continuous', since='now')
250273
count = 0
251274
changes = list()
252-
self.create_dbs(3)
253275
for change in feed:
254276
self.assertTrue(all(x in change for x in ('seq', 'type')))
255277
changes.append(change)
@@ -281,7 +303,6 @@ def test_get_normal_feed_default(self):
281303
Test getting content back for a "normal" feed without feed option. Also
282304
using limit since we don't know how many updates have occurred on client.
283305
"""
284-
self.create_dbs(3)
285306
feed = Feed(self.client, limit=3)
286307
changes = list()
287308
for change in feed:
@@ -296,7 +317,6 @@ def test_get_normal_feed_explicit(self):
296317
Test getting content back for a "normal" feed using feed option. Also
297318
using limit since we don't know how many updates have occurred on client.
298319
"""
299-
self.create_dbs(3)
300320
feed = Feed(self.client, feed='normal', limit=3)
301321
changes = list()
302322
for change in feed:
@@ -310,7 +330,6 @@ def test_get_longpoll_feed(self):
310330
"""
311331
Test getting content back for a "longpoll" feed
312332
"""
313-
self.create_dbs(3)
314333
feed = Feed(self.client, feed='longpoll', limit=3)
315334
changes = list()
316335
for change in feed:

0 commit comments

Comments
 (0)