-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_docushare_not_authorized.py
63 lines (48 loc) · 2.65 KB
/
test_docushare_not_authorized.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import pathlib
import shutil
import tempfile
from unittest import TestCase, skipIf
from docushare import *
class DocuShareNotAuthorizedTest(TestCase):
required_envs = [
'DOCUSHARE_BASEURL',
'DOCUSHARE_USERNAME',
'DOCUSHARE_NOT_AUTHORIZED_DOCUMENT_HANDLE',
'DOCUSHARE_NOT_AUTHORIZED_VERSION_HANDLE',
]
skip = not all([env in os.environ for env in required_envs])
skip_reason = 'Following environmental variables are not defined: ' + ', '.join([env for env in required_envs if env not in os.environ])
def setUp(self):
self.base_url = os.environ['DOCUSHARE_BASEURL']
self.username = os.environ['DOCUSHARE_USERNAME']
self.not_authorized_document_handle = os.environ['DOCUSHARE_NOT_AUTHORIZED_DOCUMENT_HANDLE']
self.not_authorized_version_handle = os.environ['DOCUSHARE_NOT_AUTHORIZED_VERSION_HANDLE']
if 'DOCUSHARE_PASSWORD' in os.environ:
self.password = os.environ['DOCUSHARE_PASSWORD']
else:
self.password = PasswordOption.USE_STORED
self.ds = DocuShare(self.base_url)
self.ds.login(username = self.username, password = self.password)
self.tempdir = pathlib.Path(tempfile.mkdtemp())
def tearDown(self):
self.ds.close()
shutil.rmtree(self.tempdir)
@skipIf(skip, skip_reason)
def test_not_authorized_errors(self):
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.object(self.not_authorized_document_handle)
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds[self.not_authorized_document_handle]
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.download(self.not_authorized_document_handle, self.tempdir.joinpath('test.bin'))
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.http_get(self.base_url + 'dsweb/Services/' + self.not_authorized_document_handle)
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.object(self.not_authorized_version_handle)
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds[self.not_authorized_version_handle]
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.download(self.not_authorized_version_handle, self.tempdir.joinpath('test.bin'))
with self.assertRaises(DocuShareNotAuthorizedError) as context:
self.ds.http_get(self.base_url + 'dsweb/Services/' + self.not_authorized_version_handle)