|
2 | 2 | Test Collections |
3 | 3 | """ |
4 | 4 | import random |
5 | | -from six.moves import range |
6 | 5 | from contextlib import closing |
| 6 | + |
| 7 | +import pytest |
| 8 | +from scrapinghub import HubstorageClient |
| 9 | +from six.moves import range |
| 10 | + |
7 | 11 | from .hstestcase import HSTestCase |
8 | 12 | from .testutil import failing_downloader |
9 | 13 |
|
@@ -121,3 +125,31 @@ def test_invalid_collection_name(self): |
121 | 125 | self.assertRaises(ValueError, cols.new_store, '/foo') |
122 | 126 | self.assertRaises(ValueError, cols.create_writer, 'invalidtype', 'n') |
123 | 127 | self.assertRaises(ValueError, cols.create_writer, 's', 'foo-bar') |
| 128 | + |
| 129 | + |
| 130 | +@pytest.mark.parametrize('msgpack_available', [True, False]) |
| 131 | +@pytest.mark.parametrize('path,expected_result', [ |
| 132 | + ('s/foo', True), |
| 133 | + ('s/foo/', True), |
| 134 | + (('s', 'foo'), True), |
| 135 | + ('s/foo/bar', True), |
| 136 | + ('s/foo/bar/', True), |
| 137 | + (('s', 'foo', 'bar'), True), |
| 138 | + ('vs/foo/bar/', True), |
| 139 | + ('cs/foo/bar/', True), |
| 140 | + ('vcs/foo/bar/', True), |
| 141 | + ('s/foo/scan', True), |
| 142 | + ('s/foo/bar/baz', False), |
| 143 | + ('s/foo/count', False), |
| 144 | + (('s', 'foo', 'count'), False), |
| 145 | + ('x/foo', False), |
| 146 | + (('x', 'foo'), False), |
| 147 | + ('list', False), |
| 148 | + (None, False), |
| 149 | +]) |
| 150 | +def test_allows_msgpack(monkeypatch, msgpack_available, path, expected_result): |
| 151 | + monkeypatch.setattr( |
| 152 | + 'scrapinghub.hubstorage.collectionsrt.MSGPACK_AVAILABLE', msgpack_available) |
| 153 | + hsclient = HubstorageClient() |
| 154 | + collections = hsclient.get_project(2222000).collections |
| 155 | + assert collections._allows_mpack(path) is (msgpack_available and expected_result) |
0 commit comments