forked from faif/python-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_proxy.py
More file actions
37 lines (30 loc) · 1.05 KB
/
test_proxy.py
File metadata and controls
37 lines (30 loc) · 1.05 KB
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
import sys
import unittest
from io import StringIO
from patterns.structural.proxy import Proxy, client
class ProxyTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Class scope setup."""
cls.proxy = Proxy()
def setUp(cls):
"""Function/test case scope setup."""
cls.output = StringIO()
cls.saved_stdout = sys.stdout
sys.stdout = cls.output
def tearDown(cls):
"""Function/test case scope teardown."""
cls.output.close()
sys.stdout = cls.saved_stdout
def test_do_the_job_for_admin_shall_pass(self):
client(self.proxy, "admin")
assert self.output.getvalue() == (
"[log] Doing the job for admin is requested.\n"
"I am doing the job for admin\n"
)
def test_do_the_job_for_anonymous_shall_reject(self):
client(self.proxy, "anonymous")
assert self.output.getvalue() == (
"[log] Doing the job for anonymous is requested.\n"
"[log] I can do the job just for `admins`.\n"
)