|
1 | 1 | import unittest |
2 | 2 |
|
3 | | -import logging |
4 | | -logging.basicConfig(level=logging.ERROR) |
| 3 | +import httpretty |
5 | 4 |
|
6 | | -# local modules |
7 | 5 | from dataverse.connection import Connection |
8 | 6 | from dataverse.dataset import Dataset |
9 | | -from dataverse.exceptions import DataverseError |
10 | 7 | from dataverse.settings import TEST_HOST, TEST_TOKEN |
11 | | -from dataverse.test.config import PICS_OF_CATS_DATASET, ATOM_DATASET |
| 8 | +from dataverse.test.config import PICS_OF_CATS_DATASET, ATOM_DATASET, EXAMPLE_FILES |
| 9 | +from dataverse import exceptions |
12 | 10 | from dataverse import utils |
13 | 11 |
|
| 12 | +import logging |
| 13 | +logging.basicConfig(level=logging.ERROR) |
| 14 | + |
14 | 15 |
|
15 | 16 | class TestUtils(unittest.TestCase): |
16 | 17 |
|
@@ -54,6 +55,31 @@ def test_format_term_replace(self): |
54 | 55 | self.assertEqual(formatted_term, '{http://purl.org/dc/terms/}identifier') |
55 | 56 |
|
56 | 57 |
|
| 58 | +class TestConnection(unittest.TestCase): |
| 59 | + |
| 60 | + def test_connect(self): |
| 61 | + c = Connection(TEST_HOST, TEST_TOKEN) |
| 62 | + |
| 63 | + self.assertEqual(c.host, TEST_HOST) |
| 64 | + self.assertEqual(c.token, TEST_TOKEN) |
| 65 | + self.assertTrue(c.service_document) |
| 66 | + |
| 67 | + def test_connect_unauthorized(self): |
| 68 | + with self.assertRaises(exceptions.UnauthorizedError): |
| 69 | + Connection(TEST_HOST, 'wrong-token') |
| 70 | + |
| 71 | + @httpretty.activate |
| 72 | + def test_connect_unknown_failure(self): |
| 73 | + httpretty.register_uri( |
| 74 | + httpretty.GET, |
| 75 | + "https://{host}/dvn/api/data-deposit/v1.1/swordv2/service-document".format(host=TEST_HOST), |
| 76 | + status=400, |
| 77 | + ) |
| 78 | + |
| 79 | + with self.assertRaises(exceptions.ConnectionError): |
| 80 | + Connection(TEST_HOST, TEST_TOKEN) |
| 81 | + |
| 82 | + |
57 | 83 | class TestDataset(unittest.TestCase): |
58 | 84 |
|
59 | 85 | def test_init(self): |
@@ -98,7 +124,7 @@ def setUpClass(self): |
98 | 124 | print "Getting Dataverse" |
99 | 125 | dataverses = self.dvc.get_dataverses() |
100 | 126 | if not dataverses: |
101 | | - raise DataverseError( |
| 127 | + raise exceptions.DataverseError( |
102 | 128 | 'You must have a Dataverse to run these tests.' |
103 | 129 | ) |
104 | 130 |
|
@@ -136,10 +162,10 @@ def test_create_dataset_from_xml(self): |
136 | 162 | self.dv.delete_dataset(retrieved_dataset) |
137 | 163 |
|
138 | 164 | def test_add_files(self): |
139 | | - self.s.add_files(['test_dataverse.py', 'config.py']) |
| 165 | + self.s.add_files(EXAMPLE_FILES) |
140 | 166 | actual_files = [f.name for f in self.s.get_files()] |
141 | 167 |
|
142 | | - self.assertIn('test_dataverse.py', actual_files) |
| 168 | + self.assertIn('__init__.py', actual_files) |
143 | 169 | self.assertIn('config.py', actual_files) |
144 | 170 |
|
145 | 171 | def test_upload_file(self): |
|
0 commit comments