|
8 | 8 | @pytest.mark.skipif( |
9 | 9 | os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES') |
10 | 10 | class Discoveryv1(TestCase): |
11 | | - def setUp(self): |
12 | | - self.discovery = watson_developer_cloud.DiscoveryV1( |
| 11 | + discovery = None |
| 12 | + environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing |
| 13 | + collection_id = None |
| 14 | + |
| 15 | + @classmethod |
| 16 | + def setup_class(cls): |
| 17 | + cls.discovery = watson_developer_cloud.DiscoveryV1( |
13 | 18 | version='2017-10-16', |
14 | 19 | username="YOUR SERVICE USERNAME", |
15 | 20 | password="YOUR SERVICE PASSWORD") |
16 | | - self.discovery.set_default_headers({ |
| 21 | + cls.discovery.set_default_headers({ |
17 | 22 | 'X-Watson-Learning-Opt-Out': '1', |
18 | 23 | 'X-Watson-Test': '1' |
19 | 24 | }) |
20 | | - self.environment_id = 'e15f6424-f887-4f50-b4ea-68267c36fc9c' # This environment is created for integration testing |
21 | | - self.collection_id = self.discovery.list_collections( |
22 | | - self.environment_id)['collections'][0]['collection_id'] |
| 25 | + cls.collection_id = cls.discovery.list_collections(cls.environment_id)['collections'][0]['collection_id'] |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def teardown_class(cls): |
| 29 | + collections = cls.discovery.list_collections(cls.environment_id)['collections'] |
| 30 | + for collection in collections: |
| 31 | + if collection['name'] != 'DO-NOT-DELETE': |
| 32 | + cls.discovery.delete_collection(cls.environment_id, collection['collection_id']) |
23 | 33 |
|
24 | 34 | def test_environments(self): |
25 | 35 | envs = self.discovery.list_environments() |
@@ -86,10 +96,7 @@ def test_documents(self): |
86 | 96 | self.environment_id, self.collection_id, add_doc['document_id']) |
87 | 97 | assert doc_status is not None |
88 | 98 |
|
89 | | - with open( |
90 | | - os.path.join( |
91 | | - os.path.dirname(__file__), '../../resources/simple.html'), |
92 | | - 'r') as fileinfo: |
| 99 | + with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo: |
93 | 100 | update_doc = self.discovery.update_document( |
94 | 101 | self.environment_id, |
95 | 102 | self.collection_id, |
|
0 commit comments