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

Commit cdffb88

Browse files
authored
Merge pull request #407 from cloudant/test-attributes
Added test attributes
2 parents a54349d + 48b10c7 commit cdffb88

19 files changed

+149
-148
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ before_script:
3030
# command to run tests
3131
script:
3232
- pylint ./src/cloudant
33-
- nosetests -w ./tests/unit
33+
- nosetests -A 'not db or ((db is "couch" or "couch" in db) and (not couchapi or couchapi <='${COUCHDB_VERSION:0:1}'))' -w ./tests/unit
3434

3535
notifications:
3636
email: false

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ test behaviour:
8282
This user is deleted at the end of the test run, but beware it'll
8383
break other applications using the CouchDB instance that rely on
8484
admin party mode being in effect while the tests are running.
85+
86+
### Test attributes
87+
88+
Database tests also have node attributes. Currently there are these attributes:
89+
`db` - `cloudant` and/or `couch`
90+
`couchapi` - Apache CouchDB major version number (i.e. API level) e.g. `2`
91+
92+
Example to run database tests that require CouchDB version 1 API and no Cloudant features:
93+
`nosetests -A 'db and ((db is "couch" or "couch" in db) and (not couchapi or couchapi <=1))' -w ./tests/unit`

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def setupPythonAndTest(pythonVersion, testSuite) {
3737
pip install -r requirements.txt
3838
pip install -r test-requirements.txt
3939
pylint ./src/cloudant
40-
nosetests -w ./tests/unit --with-xunit
40+
nosetests -A 'not db or (db is "cloudant" or "cloudant" in db)' -w ./tests/unit --with-xunit
4141
"""
4242
} finally {
4343
// Load the test results

tests/unit/auth_renewal_tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2016, 2017 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.
@@ -18,15 +18,18 @@
1818
See configuration options for environment variables in unit_t_db_base
1919
module docstring.
2020
"""
21-
import unittest
2221
import os
23-
import requests
2422
import time
23+
import unittest
2524

25+
import requests
2626
from cloudant._client_session import CookieSession
27+
from nose.plugins.attrib import attr
2728

2829
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
2930

31+
32+
@attr(db=['cloudant','couch'])
3033
@unittest.skipIf(os.environ.get('ADMIN_PARTY') == 'true', 'Skipping - Admin Party mode')
3134
class AuthRenewalTests(UnitTestDbBase):
3235
"""

tests/unit/changes_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@
1616
Unit tests for _changes feed
1717
"""
1818

19-
import unittest
20-
from requests import Session
2119
import json
2220
import os
21+
import unittest
2322

24-
from cloudant.feed import Feed
25-
from cloudant.document import Document
23+
from cloudant._2to3 import unicode_
2624
from cloudant.design_document import DesignDocument
25+
from cloudant.document import Document
2726
from cloudant.error import CloudantArgumentError
28-
from cloudant._2to3 import unicode_
27+
from cloudant.feed import Feed
28+
from nose.plugins.attrib import attr
29+
from requests import Session
2930

3031
from .unit_t_db_base import UnitTestDbBase
3132
from .. import BYTETYPE
3233

34+
35+
@attr(db=['cloudant','couch'])
3336
class ChangesTests(UnitTestDbBase):
3437
"""
3538
_changes feed unit tests
@@ -41,7 +44,6 @@ def setUp(self):
4144
"""
4245
super(ChangesTests, self).setUp()
4346
self.db_set_up()
44-
self.cloudant_test = os.environ.get('RUN_CLOUDANT_TESTS') is not None
4547

4648
def tearDown(self):
4749
"""
@@ -448,8 +450,6 @@ def test_get_feed_using_conflicts_false(self):
448450
self.assertSetEqual(set([x['id'] for x in changes]), expected)
449451
self.assertTrue(str(feed.last_seq).startswith('3'))
450452

451-
@unittest.skipIf(os.environ.get('RUN_CLOUDANT_TESTS') is not None,
452-
'Skipping since _doc_ids filter is not supported on all Cloudant clusters')
453453
def test_get_feed_using_doc_ids(self):
454454
"""
455455
Test getting content back for a feed using doc_ids

tests/unit/client_tests.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2015, 2017 IBM Corp. All rights reserved.
2+
# Copyright (C) 2015, 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.
@@ -20,28 +20,29 @@
2020
2121
"""
2222

23-
import unittest
24-
import requests
25-
import json
2623
import base64
27-
import sys
28-
import os
2924
import datetime
30-
import mock
31-
32-
from requests import ConnectTimeout, HTTPError
25+
import json
26+
import os
27+
import sys
28+
import unittest
3329
from time import sleep
3430

31+
import mock
32+
import requests
3533
from cloudant import cloudant, cloudant_bluemix, couchdb, couchdb_admin_party
36-
from cloudant.client import Cloudant, CouchDB
3734
from cloudant._client_session import BasicSession, CookieSession
35+
from cloudant.client import Cloudant, CouchDB
3836
from cloudant.database import CloudantDatabase
3937
from cloudant.error import CloudantArgumentError, CloudantClientException
4038
from cloudant.feed import Feed, InfiniteFeed
39+
from nose.plugins.attrib import attr
40+
from requests import ConnectTimeout, HTTPError
4141

4242
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase
4343
from .. import bytes_, str_
4444

45+
4546
class CloudantClientExceptionTests(unittest.TestCase):
4647
"""
4748
Ensure CloudantClientException functions as expected.
@@ -86,10 +87,10 @@ class ClientTests(UnitTestDbBase):
8687
"""
8788

8889
@unittest.skipIf(
89-
(os.environ.get('RUN_CLOUDANT_TESTS') is not None or
90-
(os.environ.get('ADMIN_PARTY') and os.environ.get('ADMIN_PARTY') == 'true')),
90+
((os.environ.get('ADMIN_PARTY') and os.environ.get('ADMIN_PARTY') == 'true')),
9191
'Skipping couchdb context manager test'
9292
)
93+
@attr(db='couch')
9394
def test_couchdb_context_helper(self):
9495
"""
9596
Test that the couchdb context helper works as expected.
@@ -102,10 +103,10 @@ def test_couchdb_context_helper(self):
102103
self.fail('Exception {0} was raised.'.format(str(err)))
103104

104105
@unittest.skipUnless(
105-
(os.environ.get('RUN_CLOUDANT_TESTS') is None and
106-
(os.environ.get('ADMIN_PARTY') and os.environ.get('ADMIN_PARTY') == 'true')),
106+
((os.environ.get('ADMIN_PARTY') and os.environ.get('ADMIN_PARTY') == 'true')),
107107
'Skipping couchdb_admin_party context manager test'
108108
)
109+
@attr(db='couch')
109110
def test_couchdb_admin_party_context_helper(self):
110111
"""
111112
Test that the couchdb_admin_party context helper works as expected.
@@ -599,10 +600,7 @@ def test_db_updates_feed_call(self):
599600
finally:
600601
self.client.disconnect()
601602

602-
@unittest.skipUnless(
603-
os.environ.get('RUN_CLOUDANT_TESTS') is not None,
604-
'Skipping Cloudant client specific tests'
605-
)
603+
@attr(db='cloudant')
606604
class CloudantClientTests(UnitTestDbBase):
607605
"""
608606
Cloudant specific client unit tests

tests/unit/database_tests.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@
2222
2323
"""
2424

25-
import unittest
26-
import mock
27-
import requests
2825
import os
26+
import unittest
2927
import uuid
3028

29+
import mock
30+
import requests
3131
from cloudant._2to3 import UNICHR
32-
from cloudant.result import Result, QueryResult
33-
from cloudant.error import CloudantArgumentError, CloudantDatabaseException
34-
from cloudant.document import Document
3532
from cloudant.design_document import DesignDocument
36-
from cloudant.security_document import SecurityDocument
37-
from cloudant.index import Index, TextIndex, SpecialIndex
33+
from cloudant.document import Document
34+
from cloudant.error import CloudantArgumentError, CloudantDatabaseException
3835
from cloudant.feed import Feed, InfiniteFeed
39-
from tests.unit._test_util import LONG_NUMBER
36+
from cloudant.index import Index, TextIndex, SpecialIndex
37+
from cloudant.result import Result, QueryResult
38+
from cloudant.security_document import SecurityDocument
39+
from nose.plugins.attrib import attr
4040

41+
from tests.unit._test_util import LONG_NUMBER
4142
from .unit_t_db_base import skip_if_not_cookie_auth, UnitTestDbBase, skip_if_iam
4243
from .. import unicode_
4344

45+
4446
class CloudantDatabaseExceptionTests(unittest.TestCase):
4547
"""
4648
Ensure CloudantDatabaseException functions as expected.
@@ -79,6 +81,7 @@ def test_raise_with_proper_code_and_args(self):
7981
raise CloudantDatabaseException(400, 'foo')
8082
self.assertEqual(cm.exception.status_code, 400)
8183

84+
@attr(db=['cloudant','couch'])
8285
class DatabaseTests(UnitTestDbBase):
8386
"""
8487
CouchDatabase/CloudantDatabase unit tests
@@ -780,8 +783,7 @@ def test_get_set_revision_limit(self):
780783
self.assertNotEqual(new_limit, limit)
781784
self.assertEqual(new_limit, 1234)
782785

783-
@unittest.skipIf(os.environ.get('RUN_CLOUDANT_TESTS'),
784-
'Skipping since view cleanup is automatic in Cloudant.')
786+
@attr(db='couch')
785787
def test_view_clean_up(self):
786788
"""
787789
Test cleaning up old view files
@@ -968,10 +970,7 @@ def test_database_request_fails_after_client_disconnects(self):
968970
finally:
969971
self.client.connect()
970972

971-
@unittest.skipIf(not os.environ.get('RUN_CLOUDANT_TESTS') or
972-
(os.environ.get('COUCHDB_VERSION') and
973-
os.environ.get('COUCHDB_VERSION').startswith('1')),
974-
'Skipping test_create_json_index test')
973+
@attr(couchapi=2)
975974
def test_create_json_index(self):
976975
"""
977976
Ensure that a JSON index is created as expected.
@@ -995,10 +994,7 @@ def test_create_json_index(self):
995994
self.assertEquals(index['options']['def']['fields'], ['name', 'age'])
996995
self.assertEquals(index['reduce'], '_count')
997996

998-
@unittest.skipIf(not os.environ.get('RUN_CLOUDANT_TESTS') or
999-
(os.environ.get('COUCHDB_VERSION') and
1000-
os.environ.get('COUCHDB_VERSION').startswith('1')),
1001-
'Skipping test_create_json_index test')
997+
@attr(couchapi=2)
1002998
def test_delete_json_index(self):
1003999
"""
10041000
Ensure that a JSON index is deleted as expected.
@@ -1013,10 +1009,7 @@ def test_delete_json_index(self):
10131009
self.db.delete_query_index('ddoc001', 'json', 'index001')
10141010
self.assertFalse(ddoc.exists())
10151011

1016-
@unittest.skipUnless(
1017-
os.environ.get('RUN_CLOUDANT_TESTS') is not None,
1018-
'Skipping Cloudant specific Database tests'
1019-
)
1012+
@attr(db='cloudant')
10201013
class CloudantDatabaseTests(UnitTestDbBase):
10211014
"""
10221015
Cloudant specific Database unit tests

tests/unit/db_updates_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
Unit tests for _db_updates feed
1717
"""
1818

19-
import unittest
20-
from requests import Session
2119
import json
2220
import os
21+
import unittest
2322

24-
from cloudant.feed import Feed
25-
from cloudant.error import CloudantArgumentError
2623
from cloudant._2to3 import unicode_
24+
from cloudant.error import CloudantArgumentError
25+
from cloudant.feed import Feed
26+
from nose.plugins.attrib import attr
27+
from requests import Session
2728

2829
from .unit_t_db_base import UnitTestDbBase
2930
from .. import BYTETYPE
@@ -104,8 +105,7 @@ def assert_changes_in_db_updates_feed(self, changes):
104105
self.assertDictEqual(
105106
changes[2], {'db_name': self.new_dbs[2].database_name, 'type': 'created'})
106107

107-
@unittest.skipIf(os.environ.get('RUN_CLOUDANT_TESTS'),
108-
'Skipping CouchDB _db_updates feed tests')
108+
@attr(db='couch')
109109
class CouchDbUpdatesTests(DbUpdatesTestsBase):
110110
"""
111111
CouchDB _db_updates feed unit tests
@@ -276,8 +276,8 @@ def test_invalid_feed_value(self):
276276
self.assertTrue(str(cm.exception).startswith(
277277
'Invalid value (normal) for feed option.'))
278278

279-
@unittest.skipIf(not os.environ.get('RUN_CLOUDANT_TESTS') or
280-
os.environ.get('SKIP_DB_UPDATES'), 'Skipping Cloudant _db_updates feed tests')
279+
@attr(db='cloudant')
280+
@unittest.skipIf(os.environ.get('SKIP_DB_UPDATES'), 'Skipping Cloudant _db_updates feed tests')
281281
class CloudantDbUpdatesTests(DbUpdatesTestsBase):
282282
"""
283283
Cloudant _db_updates feed unit tests

0 commit comments

Comments
 (0)