Klaus Demo ~jonashaag/klaus / 2aa6553
Move test utils into separate module Jonas Haag 7 years ago
3 changed file(s) with 43 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
33 .idea
44 *.swp
55 tests/repos/
6 *.egg-info
7 build/
8 dist/
9 .DS_Store
00 import os
1 import time
2 import contextlib
31 import subprocess
42 import tempfile
53 import shutil
86 import pytest
97 import requests
108 import requests.auth
11 import werkzeug.serving
12 import threading
139
14
15 TEST_REPO = os.path.abspath("tests/repos/test_repo")
16 TEST_REPO_URL = "test_repo/"
17 TEST_SITE_NAME = "Some site"
18 HTDIGEST_FILE = "tests/credentials.htdigest"
19 UNAUTH_TEST_SERVER = "http://invalid:password@localhost:9876/"
20 UNAUTH_TEST_REPO_URL = UNAUTH_TEST_SERVER + TEST_REPO_URL
21 AUTH_TEST_SERVER = "http://testuser:testpassword@localhost:9876/"
22 AUTH_TEST_REPO_URL = AUTH_TEST_SERVER + TEST_REPO_URL
23
24
25 def testserver_require_auth(*args, **kwargs):
26 kwargs['htdigest_file'] = open(HTDIGEST_FILE)
27 kwargs['require_browser_auth'] = True
28 return testserver(*args, **kwargs)
10 from .utils import *
2911
3012
3113 def test_htdigest_file_without_smarthttp_or_require_browser_auth():
9274 )
9375
9476
95 @contextlib.contextmanager
96 def testserver(*args, **kwargs):
97 app = klaus.make_app([TEST_REPO], TEST_SITE_NAME, *args, **kwargs)
98 server = werkzeug.serving.make_server("localhost", 9876, app)
99 thread = threading.Thread(target=server.serve_forever)
100 thread.start()
101 try:
102 yield
103 finally:
104 server.server_close()
105 if 'TRAVIS' in os.environ:
106 # This fixes some "Address already in use" cases on Travis.
107 time.sleep(1)
108
109
11077 # Reach
11178 def can_reach_unauth():
11279 return _check_http200(_GET_unauth, "test_repo")
0 import os
1 import time
2 import contextlib
3 import werkzeug.serving
4 import threading
5
6 import klaus
7
8
9 TEST_REPO = os.path.abspath("tests/repos/test_repo")
10 TEST_REPO_URL = "test_repo/"
11 TEST_SITE_NAME = "Some site"
12 HTDIGEST_FILE = "tests/credentials.htdigest"
13 UNAUTH_TEST_SERVER = "http://invalid:password@localhost:9876/"
14 UNAUTH_TEST_REPO_URL = UNAUTH_TEST_SERVER + TEST_REPO_URL
15 AUTH_TEST_SERVER = "http://testuser:testpassword@localhost:9876/"
16 AUTH_TEST_REPO_URL = AUTH_TEST_SERVER + TEST_REPO_URL
17
18
19 @contextlib.contextmanager
20 def testserver(*args, **kwargs):
21 app = klaus.make_app([TEST_REPO], TEST_SITE_NAME, *args, **kwargs)
22 server = werkzeug.serving.make_server("localhost", 9876, app)
23 thread = threading.Thread(target=server.serve_forever)
24 thread.start()
25 try:
26 yield
27 finally:
28 server.server_close()
29 if 'TRAVIS' in os.environ:
30 # This fixes some "Address already in use" cases on Travis.
31 time.sleep(1)
32
33
34 def testserver_require_auth(*args, **kwargs):
35 kwargs['htdigest_file'] = open(HTDIGEST_FILE)
36 kwargs['require_browser_auth'] = True
37 return testserver(*args, **kwargs)