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

Commit 9411642

Browse files
committed
Test with a basic access authenticated client
1 parent 37dbaf5 commit 9411642

File tree

6 files changed

+98
-50
lines changed

6 files changed

+98
-50
lines changed

Jenkinsfile

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
// Define the test routine for different python versions
2-
def test_python(pythonVersion)
2+
3+
def test_python_basic(pythonVersion)
4+
{
5+
node {
6+
// Unstash the source on this node
7+
unstash name: 'source'
8+
// Set up the environment and test
9+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'clientlibs-test', usernameVariable: 'DB_USER', passwordVariable: 'DB_PASSWORD']]) {
10+
try {
11+
sh """ virtualenv tmp -p /usr/local/lib/python${pythonVersion}/bin/${pythonVersion.startsWith('3') ? "python3" : "python"}
12+
. ./tmp/bin/activate
13+
echo \$DB_USER
14+
export RUN_CLOUDANT_TESTS=1
15+
export RUN_BASIC_AUTH_TESTS=1
16+
export CLOUDANT_ACCOUNT=\$DB_USER
17+
# Temporarily disable the _db_updates tests pending resolution of case 71610
18+
export SKIP_DB_UPDATES=1
19+
pip install -r requirements.txt
20+
pip install -r test-requirements.txt
21+
pylint ./src/cloudant
22+
nosetests -w ./tests/unit --with-xunit"""
23+
} finally {
24+
// Load the test results
25+
junit 'nosetests.xml'
26+
}
27+
}
28+
}
29+
}
30+
31+
32+
def test_python_cookie(pythonVersion)
333
{
434
node {
535
// Unstash the source on this node
@@ -64,8 +94,10 @@ stage('Checkout'){
6494
stage('Test'){
6595
// Run tests in parallel for multiple python versions
6696
parallel(
67-
Python2: {test_python('2.7.12')},
68-
Python3: {test_python('3.5.2')},
97+
'Python2-BASIC': {test_python_basic('2.7.12')},
98+
'Python3-BASIC': {test_python_basic('3.5.2')},
99+
'Python2-COOKIE': {test_python_cookie('2.7.12')},
100+
'Python3-COOKIE': {test_python_cookie('3.5.2')},
69101
'Python2-IAM': {test_python_iam('2.7.12')},
70102
'Python3-IAM': {test_python_iam('3.5.2')}
71103
)

tests/unit/auth_renewal_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from cloudant.client_session import CookieSession
2727

28-
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
28+
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
2929

3030
@unittest.skipIf(os.environ.get('ADMIN_PARTY') == 'true', 'Skipping - Admin Party mode')
3131
class AuthRenewalTests(UnitTestDbBase):
@@ -45,7 +45,7 @@ def tearDown(self):
4545
"""
4646
pass
4747

48-
@skip_for_iam
48+
@skip_if_not_cookie_auth
4949
def test_client_db_doc_stack_success(self):
5050
"""
5151
Ensure that auto renewal of cookie auth happens as expected and applies
@@ -110,6 +110,7 @@ def test_client_db_doc_stack_success(self):
110110
self.client.disconnect()
111111
del self.client
112112

113+
@skip_if_not_cookie_auth
113114
def test_client_db_doc_stack_failure(self):
114115
"""
115116
Ensure that when the regular requests.Session is used that

tests/unit/client_tests.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from cloudant.error import CloudantArgumentError, CloudantClientException
4040
from cloudant.feed import Feed, InfiniteFeed
4141

42-
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
42+
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
4343
from .. import bytes_, str_
4444

4545
class CloudantClientExceptionTests(unittest.TestCase):
@@ -164,7 +164,7 @@ def test_multiple_connect(self):
164164
self.client.disconnect()
165165
self.assertIsNone(self.client.r_session)
166166

167-
@skip_for_iam
167+
@skip_if_not_cookie_auth
168168
def test_auto_renew_enabled(self):
169169
"""
170170
Test that CookieSession is used when auto_renew is enabled.
@@ -179,7 +179,7 @@ def test_auto_renew_enabled(self):
179179
finally:
180180
self.client.disconnect()
181181

182-
@skip_for_iam
182+
@skip_if_not_cookie_auth
183183
def test_auto_renew_enabled_with_auto_connect(self):
184184
"""
185185
Test that CookieSession is used when auto_renew is enabled along with
@@ -194,7 +194,7 @@ def test_auto_renew_enabled_with_auto_connect(self):
194194
finally:
195195
self.client.disconnect()
196196

197-
@skip_for_iam
197+
@skip_if_not_cookie_auth
198198
def test_session(self):
199199
"""
200200
Test getting session information.
@@ -210,7 +210,7 @@ def test_session(self):
210210
finally:
211211
self.client.disconnect()
212212

213-
@skip_for_iam
213+
@skip_if_not_cookie_auth
214214
def test_session_cookie(self):
215215
"""
216216
Test getting the session cookie.
@@ -319,7 +319,7 @@ def test_change_credentials_basic(self, m_req):
319319
)
320320
self.assertEquals(all_dbs, ['animaldb'])
321321

322-
@skip_for_iam
322+
@skip_if_not_cookie_auth
323323
def test_basic_auth_str(self):
324324
"""
325325
Test getting the basic authentication string.
@@ -594,7 +594,7 @@ class CloudantClientTests(UnitTestDbBase):
594594
Cloudant specific client unit tests
595595
"""
596596

597-
@skip_for_iam
597+
@skip_if_not_cookie_auth
598598
def test_cloudant_session_login(self):
599599
"""
600600
Test that the Cloudant client session successfully authenticates.
@@ -607,7 +607,7 @@ def test_cloudant_session_login(self):
607607
self.client.session_login()
608608
self.assertNotEqual(self.client.session_cookie(), old_cookie)
609609

610-
@skip_for_iam
610+
@skip_if_not_cookie_auth
611611
def test_cloudant_session_login_with_new_credentials(self):
612612
"""
613613
Test that the Cloudant client session fails to authenticate when
@@ -620,7 +620,7 @@ def test_cloudant_session_login_with_new_credentials(self):
620620

621621
self.assertTrue(str(cm.exception).find('Name or password is incorrect'))
622622

623-
@skip_for_iam
623+
@skip_if_not_cookie_auth
624624
def test_cloudant_context_helper(self):
625625
"""
626626
Test that the cloudant context helper works as expected.
@@ -632,7 +632,7 @@ def test_cloudant_context_helper(self):
632632
except Exception as err:
633633
self.fail('Exception {0} was raised.'.format(str(err)))
634634

635-
@skip_for_iam
635+
@skip_if_not_cookie_auth
636636
def test_cloudant_bluemix_context_helper(self):
637637
"""
638638
Test that the cloudant_bluemix context helper works as expected.
@@ -697,7 +697,7 @@ def test_constructor_with_account(self):
697697
'https://{0}.cloudant.com'.format(self.account)
698698
)
699699

700-
@skip_for_iam
700+
@skip_if_not_cookie_auth
701701
def test_bluemix_constructor(self):
702702
"""
703703
Test instantiating a client object using a VCAP_SERVICES environment
@@ -730,7 +730,7 @@ def test_bluemix_constructor(self):
730730
finally:
731731
c.disconnect()
732732

733-
@skip_for_iam
733+
@skip_if_not_cookie_auth
734734
def test_bluemix_constructor_specify_instance_name(self):
735735
"""
736736
Test instantiating a client object using a VCAP_SERVICES environment
@@ -763,7 +763,7 @@ def test_bluemix_constructor_specify_instance_name(self):
763763
finally:
764764
c.disconnect()
765765

766-
@skip_for_iam
766+
@skip_if_not_cookie_auth
767767
def test_bluemix_constructor_with_multiple_services(self):
768768
"""
769769
Test instantiating a client object using a VCAP_SERVICES environment
@@ -831,7 +831,7 @@ def test_connect_headers(self):
831831
finally:
832832
self.client.disconnect()
833833

834-
@skip_for_iam
834+
@skip_if_not_cookie_auth
835835
def test_connect_timeout(self):
836836
"""
837837
Test that a connect timeout occurs when instantiating
@@ -858,7 +858,7 @@ def test_db_updates_infinite_feed_call(self):
858858
finally:
859859
self.client.disconnect()
860860

861-
@skip_for_iam
861+
@skip_if_not_cookie_auth
862862
def test_billing_data(self):
863863
"""
864864
Test the retrieval of billing data
@@ -953,7 +953,7 @@ def test_set_year_with_invalid_month_for_billing_data(self):
953953
finally:
954954
self.client.disconnect()
955955

956-
@skip_for_iam
956+
@skip_if_not_cookie_auth
957957
def test_volume_usage_data(self):
958958
"""
959959
Test the retrieval of volume usage data
@@ -1045,7 +1045,7 @@ def test_set_year_with_invalid_month_for_volume_usage_data(self):
10451045
finally:
10461046
self.client.disconnect()
10471047

1048-
@skip_for_iam
1048+
@skip_if_not_cookie_auth
10491049
def test_requests_usage_data(self):
10501050
"""
10511051
Test the retrieval of requests usage data
@@ -1137,7 +1137,7 @@ def test_set_year_with_invalid_month_for_requests_usage_data(self):
11371137
finally:
11381138
self.client.disconnect()
11391139

1140-
@skip_for_iam
1140+
@skip_if_not_cookie_auth
11411141
def test_shared_databases(self):
11421142
"""
11431143
Test the retrieval of shared database list
@@ -1148,7 +1148,7 @@ def test_shared_databases(self):
11481148
finally:
11491149
self.client.disconnect()
11501150

1151-
@skip_for_iam
1151+
@skip_if_not_cookie_auth
11521152
def test_generate_api_key(self):
11531153
"""
11541154
Test the generation of an API key for this client account
@@ -1162,7 +1162,7 @@ def test_generate_api_key(self):
11621162
finally:
11631163
self.client.disconnect()
11641164

1165-
@skip_for_iam
1165+
@skip_if_not_cookie_auth
11661166
def test_cors_configuration(self):
11671167
"""
11681168
Test the retrieval of the current CORS configuration for this client
@@ -1176,7 +1176,7 @@ def test_cors_configuration(self):
11761176
finally:
11771177
self.client.disconnect()
11781178

1179-
@skip_for_iam
1179+
@skip_if_not_cookie_auth
11801180
def test_cors_origins(self):
11811181
"""
11821182
Test the retrieval of the CORS origins list
@@ -1188,7 +1188,7 @@ def test_cors_origins(self):
11881188
finally:
11891189
self.client.disconnect()
11901190

1191-
@skip_for_iam
1191+
@skip_if_not_cookie_auth
11921192
def test_disable_cors(self):
11931193
"""
11941194
Test disabling CORS (assuming CORS is enabled)
@@ -1209,7 +1209,7 @@ def test_disable_cors(self):
12091209
finally:
12101210
self.client.disconnect()
12111211

1212-
@skip_for_iam
1212+
@skip_if_not_cookie_auth
12131213
def test_update_cors_configuration(self):
12141214
"""
12151215
Test updating CORS configuration

tests/unit/database_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from cloudant.feed import Feed, InfiniteFeed
3939
from tests.unit._test_util import LONG_NUMBER
4040

41-
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
41+
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
4242
from .. import unicode_
4343

4444
class CloudantDatabaseExceptionTests(unittest.TestCase):
@@ -151,7 +151,7 @@ def test_retrieve_db_url(self):
151151
'/'.join((self.client.server_url, self.test_dbname))
152152
)
153153

154-
@skip_for_iam
154+
@skip_if_not_cookie_auth
155155
def test_retrieve_creds(self):
156156
"""
157157
Test retrieving client credentials. The client credentials are None if
@@ -371,7 +371,7 @@ def test_retrieve_design_document(self):
371371
ddoc = self.db.get_design_document('_design/ddoc01')
372372
self.assertEqual(ddoc, local_ddoc)
373373

374-
@skip_for_iam
374+
@skip_if_not_cookie_auth
375375
def test_get_security_document(self):
376376
"""
377377
Test retrieving the database security document
@@ -997,7 +997,7 @@ def test_unshare_database_uses_custom_encoder(self):
997997
with self.assertRaises(TypeError):
998998
database.unshare_database(share)
999999

1000-
@skip_for_iam
1000+
@skip_if_not_cookie_auth
10011001
def test_security_document(self):
10021002
"""
10031003
Test the retrieval of the security document.
@@ -1007,7 +1007,7 @@ def test_security_document(self):
10071007
expected = {'cloudant': {share: ['_reader']}}
10081008
self.assertDictEqual(self.db.security_document(), expected)
10091009

1010-
@skip_for_iam
1010+
@skip_if_not_cookie_auth
10111011
def test_share_database_default_permissions(self):
10121012
"""
10131013
Test the sharing of a database applying default permissions.
@@ -1018,7 +1018,7 @@ def test_share_database_default_permissions(self):
10181018
expected = {'cloudant': {share: ['_reader']}}
10191019
self.assertDictEqual(self.db.security_document(), expected)
10201020

1021-
@skip_for_iam
1021+
@skip_if_not_cookie_auth
10221022
def test_share_database(self):
10231023
"""
10241024
Test the sharing of a database.
@@ -1029,7 +1029,7 @@ def test_share_database(self):
10291029
expected = {'cloudant': {share: ['_writer']}}
10301030
self.assertDictEqual(self.db.security_document(), expected)
10311031

1032-
@skip_for_iam
1032+
@skip_if_not_cookie_auth
10331033
def test_share_database_with_redundant_role_entries(self):
10341034
"""
10351035
Test the sharing of a database works when the list of roles contains
@@ -1072,7 +1072,7 @@ def test_share_database_empty_role_list(self):
10721072
'\'_db_updates\', \'_design\', \'_shards\', \'_security\']'
10731073
)
10741074

1075-
@skip_for_iam
1075+
@skip_if_not_cookie_auth
10761076
def test_unshare_database(self):
10771077
"""
10781078
Test the un-sharing of a database from a specified user.

tests/unit/replicator_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from cloudant.document import Document
3535
from cloudant.error import CloudantReplicatorException, CloudantClientException
3636

37-
from .unit_t_db_base import skip_for_iam, UnitTestDbBase
37+
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
3838
from .. import unicode_
3939

4040
class CloudantReplicatorExceptionTests(unittest.TestCase):
@@ -157,7 +157,7 @@ def test_replication_with_generated_id(self):
157157
clone = Replicator(self.client)
158158
clone.create_replication(self.db, self.target_db)
159159

160-
@skip_for_iam
160+
@skip_if_not_cookie_auth
161161
@flaky(max_runs=3)
162162
def test_create_replication(self):
163163
"""
@@ -301,7 +301,7 @@ def test_list_replications(self):
301301
match = [repl_id for repl_id in all_repl_ids if repl_id in repl_ids]
302302
self.assertEqual(set(repl_ids), set(match))
303303

304-
@skip_for_iam
304+
@skip_if_not_cookie_auth
305305
def test_retrieve_replication_state(self):
306306
"""
307307
Test that the replication state can be retrieved for a replication
@@ -343,7 +343,7 @@ def test_retrieve_replication_state_using_invalid_id(self):
343343
)
344344
self.assertIsNone(repl_state)
345345

346-
@skip_for_iam
346+
@skip_if_not_cookie_auth
347347
def test_stop_replication(self):
348348
"""
349349
Test that a replication can be stopped.
@@ -379,7 +379,7 @@ def test_stop_replication_using_invalid_id(self):
379379
'Replication with id {} not found.'.format(repl_id)
380380
)
381381

382-
@skip_for_iam
382+
@skip_if_not_cookie_auth
383383
def test_follow_replication(self):
384384
"""
385385
Test that follow_replication(...) properly iterates updated

0 commit comments

Comments
 (0)