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

Commit 89cba5a

Browse files
committed
Updated test suite
1 parent 4ea7539 commit 89cba5a

4 files changed

Lines changed: 204 additions & 31 deletions

File tree

tests/test_DirectorySyncService.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""Tests for DirectorySyncService."""
5+
6+
import os
7+
import sys
8+
9+
import pytest
10+
11+
curpath = os.path.dirname(os.path.abspath(__file__))
12+
sys.path[:0] = [os.path.join(curpath, os.pardir)]
13+
14+
from pancloud.directorysync import DirectorySyncService
15+
from pancloud.httpclient import HTTPClient
16+
from pancloud.exceptions import RequiredKwargsError, \
17+
UnexpectedKwargsError
18+
19+
20+
TARPIT = os.environ.get('TARPIT', 'http://10.255.255.1')
21+
22+
23+
class TestLoggingService:
24+
25+
def test_entry_points(self):
26+
27+
DirectorySyncService(url=TARPIT).session
28+
DirectorySyncService(url=TARPIT).kwargs
29+
DirectorySyncService(url=TARPIT).url
30+
DirectorySyncService(url=TARPIT).attributes
31+
DirectorySyncService(url=TARPIT).query
32+
DirectorySyncService(url=TARPIT).domains
33+
DirectorySyncService(url=TARPIT).count
34+
35+
def test_required_kwargs(self):
36+
with pytest.raises(RequiredKwargsError):
37+
DirectorySyncService()
38+
39+
with pytest.raises(RequiredKwargsError):
40+
DirectorySyncService(session=None)
41+
42+
def test_unexpected_kwargs(self):
43+
with pytest.raises(UnexpectedKwargsError):
44+
DirectorySyncService(url=TARPIT, foo='foo')
45+
46+
def test_session(self):
47+
session = HTTPClient(url=TARPIT)
48+
DirectorySyncService(session=session)

tests/test_EventService.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""Tests for EventService."""
5+
6+
import os
7+
import sys
8+
9+
import pytest
10+
11+
curpath = os.path.dirname(os.path.abspath(__file__))
12+
sys.path[:0] = [os.path.join(curpath, os.pardir)]
13+
14+
from pancloud.event import EventService
15+
from pancloud.httpclient import HTTPClient
16+
from pancloud.exceptions import RequiredKwargsError, \
17+
UnexpectedKwargsError
18+
19+
20+
TARPIT = os.environ.get('TARPIT', 'http://10.255.255.1')
21+
22+
23+
class TestLoggingService:
24+
25+
def test_entry_points(self):
26+
27+
EventService(url=TARPIT).session
28+
EventService(url=TARPIT).kwargs
29+
EventService(url=TARPIT).url
30+
EventService(url=TARPIT).get_filters
31+
EventService(url=TARPIT).set_filters
32+
EventService(url=TARPIT).poll
33+
EventService(url=TARPIT).ack
34+
EventService(url=TARPIT).nack
35+
36+
def test_required_kwargs(self):
37+
with pytest.raises(RequiredKwargsError):
38+
EventService()
39+
40+
with pytest.raises(RequiredKwargsError):
41+
EventService(session=None)
42+
43+
def test_unexpected_kwargs(self):
44+
with pytest.raises(UnexpectedKwargsError):
45+
EventService(url=TARPIT, foo='foo')
46+
47+
def test_session(self):
48+
session = HTTPClient(url=TARPIT)
49+
EventService(session=session)

tests/test_HTTPClient.py

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,76 @@
33

44
"""Tests for Requests HTTPClient wrapper."""
55

6-
from __future__ import division
7-
import json
86
import os
9-
import pickle
10-
import collections
11-
import contextlib
12-
import warnings
7+
import sys
138

14-
import io
159
import pytest
16-
import os
17-
import sys
1810

1911
curpath = os.path.dirname(os.path.abspath(__file__))
2012
sys.path[:0] = [os.path.join(curpath, os.pardir)]
2113

22-
from pancloud import httpclient
23-
24-
# from .compat import StringIO, u
25-
# from .utils import override_environ
26-
from urllib3.util import Timeout as Urllib3Timeout
27-
import socket
14+
from pancloud.httpclient import HTTPClient
15+
from pancloud.exceptions import HTTPError, RequiredKwargsError, \
16+
UnexpectedKwargsError
2817

29-
# Requests to this URL should always fail with a connection timeout (nothing
30-
# listening on that port)
31-
TARPIT = 'http://10.255.255.1'
3218

33-
try:
34-
from ssl import SSLContext
35-
del SSLContext
36-
HAS_MODERN_SSL = True
37-
except ImportError:
38-
HAS_MODERN_SSL = False
39-
40-
try:
41-
httpclient.pyopenssl
42-
HAS_PYOPENSSL = True
43-
except AttributeError:
44-
HAS_PYOPENSSL = False
19+
HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org')
20+
TARPIT = os.environ.get('TARPIT', 'http://10.255.255.1')
4521

4622

4723
class TestHTTPClient:
4824

4925
def test_entry_points(self):
50-
pass
26+
27+
HTTPClient(url=TARPIT).request
28+
HTTPClient(url=TARPIT).pyopenssl
29+
30+
def test_invalid_url(self):
31+
with pytest.raises(HTTPError):
32+
HTTPClient(url='asdaksjhdakjsdh').request(method='GET')
33+
with pytest.raises(HTTPError):
34+
HTTPClient(url='http://').request(method='GET')
35+
36+
def test_required_kwargs(self):
37+
with pytest.raises(RequiredKwargsError):
38+
HTTPClient().request()
39+
40+
def test_connection_timeout(self):
41+
with pytest.raises(HTTPError):
42+
HTTPClient(url=TARPIT).request(
43+
method='GET', timeout=(.1, None)
44+
)
45+
46+
def test_read_timeout(self):
47+
with pytest.raises(HTTPError):
48+
HTTPClient(url=HTTPBIN, port=80).request(
49+
method='GET', timeout=(None, .0001), path='/'
50+
)
51+
52+
def test_httpclient_unexpected_kwargs(self):
53+
with pytest.raises(UnexpectedKwargsError):
54+
HTTPClient(url=TARPIT, foo='foo').request(method='GET')
55+
56+
def test_request_unexpected_kwargs(self):
57+
with pytest.raises(UnexpectedKwargsError):
58+
HTTPClient(url=TARPIT).request(method='GET', foo='foo')
59+
60+
def test_enforce_json(self):
61+
with pytest.raises(HTTPError):
62+
HTTPClient(
63+
url=HTTPBIN,
64+
port=80,
65+
enforce_json=True,
66+
headers={'Accept': 'application/json'}
67+
).request(method='GET', path='/')
68+
69+
def test_raise_for_status(self):
70+
with pytest.raises(HTTPError):
71+
HTTPClient(
72+
url=HTTPBIN,
73+
port=80,
74+
raise_for_status=True
75+
).request(method='GET', path='/status/400')
76+
5177

5278

tests/test_LoggingService.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""Tests for LoggingService."""
5+
6+
import os
7+
import sys
8+
9+
import pytest
10+
11+
curpath = os.path.dirname(os.path.abspath(__file__))
12+
sys.path[:0] = [os.path.join(curpath, os.pardir)]
13+
14+
from pancloud.logging import LoggingService
15+
from pancloud.httpclient import HTTPClient
16+
from pancloud.exceptions import RequiredKwargsError, \
17+
UnexpectedKwargsError
18+
19+
20+
TARPIT = os.environ.get('TARPIT', 'http://10.255.255.1')
21+
22+
23+
class TestLoggingService:
24+
25+
def test_entry_points(self):
26+
27+
LoggingService(url=TARPIT).session
28+
LoggingService(url=TARPIT).kwargs
29+
LoggingService(url=TARPIT).url
30+
LoggingService(url=TARPIT).poll
31+
LoggingService(url=TARPIT).query
32+
LoggingService(url=TARPIT).delete
33+
LoggingService(url=TARPIT).iter_poll
34+
LoggingService(url=TARPIT).poll_all
35+
LoggingService(url=TARPIT).xpoll
36+
37+
def test_required_kwargs(self):
38+
with pytest.raises(RequiredKwargsError):
39+
LoggingService()
40+
41+
with pytest.raises(RequiredKwargsError):
42+
LoggingService(session=None)
43+
44+
def test_unexpected_kwargs(self):
45+
with pytest.raises(UnexpectedKwargsError):
46+
LoggingService(url=TARPIT, foo='foo')
47+
48+
def test_session(self):
49+
session = HTTPClient(url=TARPIT)
50+
LoggingService(session=session)

0 commit comments

Comments
 (0)