Skip to content

Commit 6a9ee58

Browse files
committed
(utils/tap/conn) Prefer pytest-style tests -- Refs astropy#861
1 parent 4845203 commit 6a9ee58

1 file changed

Lines changed: 93 additions & 127 deletions

File tree

‎astroquery/utils/tap/conn/tests/test_conn.py‎

Lines changed: 93 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
1515
1616
"""
17-
import unittest
1817
import os
1918

2019
from astroquery.utils.tap.conn.tapconn import TapConn
@@ -26,132 +25,99 @@ def data_path(filename):
2625
return os.path.join(data_dir, filename)
2726

2827

29-
class ConnTest(unittest.TestCase):
28+
def test_get():
29+
conn = DummyConn("http")
30+
conn.response.status = 222
31+
host = "testHost"
32+
serverContext = "testServerContext"
33+
tapContext = "testTapContext"
34+
connPort = 90
35+
connPortSsl = 943
36+
# TapConn
37+
tap = TapConn(ishttps=False,
38+
host=host,
39+
server_context=serverContext,
40+
tap_context=tapContext,
41+
port=connPort,
42+
sslport=connPortSsl,
43+
connhandler=conn)
44+
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
45+
+ tapContext + "/"
46+
assert tap.get_host_url() == hostUrl
47+
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
48+
+ "/" + tapContext + "/"
49+
assert tap.get_host_url_secure() == hostUrlSecure
50+
# GET
51+
subContext = "testSubContextGet"
52+
context = "/" + serverContext + "/" + tapContext + "/" + subContext
53+
r = tap.execute_tapget(subcontext=subContext)
54+
assert r.status == 222
55+
assert r.get_method() == 'GET'
56+
assert r.get_context() == context
57+
assert r.get_body() is None
3058

31-
def test_get(self):
32-
conn = DummyConn("http")
33-
conn.response.status = 222
34-
host = "testHost"
35-
serverContext = "testServerContext"
36-
tapContext = "testTapContext"
37-
connPort = 90
38-
connPortSsl = 943
39-
# TapConn
40-
tap = TapConn(ishttps=False,
41-
host=host,
42-
server_context=serverContext,
43-
tap_context=tapContext,
44-
port=connPort,
45-
sslport=connPortSsl,
46-
connhandler=conn)
47-
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
48-
+ tapContext + "/"
49-
assert tap.get_host_url() == hostUrl, \
50-
"Tap host. Expected %s, found %s" % (hostUrl, tap.get_host_url())
51-
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
52-
+ "/" + tapContext + "/"
53-
assert tap.get_host_url_secure() == hostUrlSecure, \
54-
"Tap host secure. Expected %s, found %s" % (hostUrlSecure,
55-
tap.get_host_url_secure())
56-
# GET
57-
subContext = "testSubContextGet"
58-
context = "/" + serverContext + "/" + tapContext + "/" + subContext
59-
r = tap.execute_tapget(subcontext=subContext)
60-
assert r.status == 222, \
61-
"Status code, expected: %d, found: %d" % (222,
62-
r.status)
63-
assert r.get_method() == 'GET', \
64-
"Request method. Expected %s, found %s" % ('GET',
65-
r.get_method())
66-
assert r.get_context() == context, \
67-
"Request context. Expected %s, found %s" % (context,
68-
r.get_context())
69-
assert r.get_body() is None, \
70-
"Request body. Expected %s, found %s" % ('None',
71-
str(r.get_body()))
7259

73-
def test_post(self):
74-
conn = DummyConn('http')
75-
conn.response.status = 111
76-
host = "testHost"
77-
serverContext = "testServerContext"
78-
tapContext = "testTapContext"
79-
connPort = 90
80-
connPortSsl = 943
81-
# TapConn
82-
tap = TapConn(ishttps=False,
83-
host=host,
84-
server_context=serverContext,
85-
tap_context=tapContext,
86-
port=connPort,
87-
sslport=connPortSsl,
88-
connhandler=conn)
89-
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
90-
+ tapContext + "/"
91-
assert tap.get_host_url() == hostUrl, \
92-
"Tap host. Expected %s, found %s" % (hostUrl, tap.get_host_url())
93-
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
94-
+ "/" + tapContext + "/"
95-
assert tap.get_host_url_secure() == hostUrlSecure, \
96-
"Tap host secure. Expected %s, found %s" % (hostUrlSecure,
97-
tap.get_host_url_secure())
98-
# GET
99-
subContext = "testSubContextGet"
100-
context = "/" + serverContext + "/" + tapContext + "/" + subContext
101-
data = "postData"
102-
r = tap.execute_tappost(subcontext=subContext, data=data)
103-
assert r.status == 111, \
104-
"Status code, expected: %d, found: %d" % (111,
105-
r.status)
106-
assert r.get_method() == 'POST', \
107-
"Request method. Expected %s, found %s" % ('POST',
108-
r.get_method())
109-
assert r.get_context() == context, \
110-
"Request context. Expected %s, found %s" % (context,
111-
r.get_context())
112-
assert r.get_body() == data, \
113-
"Request body. Expected %s, found %s" % (data,
114-
str(r.get_body()))
60+
def test_post():
61+
conn = DummyConn('http')
62+
conn.response.status = 111
63+
host = "testHost"
64+
serverContext = "testServerContext"
65+
tapContext = "testTapContext"
66+
connPort = 90
67+
connPortSsl = 943
68+
# TapConn
69+
tap = TapConn(ishttps=False,
70+
host=host,
71+
server_context=serverContext,
72+
tap_context=tapContext,
73+
port=connPort,
74+
sslport=connPortSsl,
75+
connhandler=conn)
76+
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
77+
+ tapContext + "/"
78+
assert tap.get_host_url() == hostUrl
79+
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
80+
+ "/" + tapContext + "/"
81+
assert tap.get_host_url_secure() == hostUrlSecure
82+
# GET
83+
subContext = "testSubContextGet"
84+
context = "/" + serverContext + "/" + tapContext + "/" + subContext
85+
data = "postData"
86+
r = tap.execute_tappost(subcontext=subContext, data=data)
87+
assert r.status == 111
88+
assert r.get_method() == 'POST'
89+
assert r.get_context() == context
90+
assert r.get_body() == data
11591

116-
def test_login(self):
117-
connSecure = DummyConn("https")
118-
connSecure.response.status = 333
119-
host = "testHost"
120-
serverContext = "testServerContext"
121-
tapContext = "testTapContext"
122-
connPort = 90
123-
connPortSsl = 943
124-
# TapConn
125-
tap = TapConn(ishttps=False,
126-
host=host,
127-
server_context=serverContext,
128-
tap_context=tapContext,
129-
port=connPort,
130-
sslport=connPortSsl,
131-
connhandler=connSecure)
132-
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
133-
+ tapContext + "/"
134-
assert tap.get_host_url() == hostUrl, \
135-
"Tap host. Expected %s, found %s" % (hostUrl, tap.get_host_url())
136-
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
137-
+ "/" + tapContext + "/"
138-
assert tap.get_host_url_secure() == hostUrlSecure, \
139-
"Tap host secure. Expected %s, found %s" % (hostUrlSecure,
140-
tap.get_host_url_secure())
141-
# POST SECURE
142-
subContext = "testSubContextPost"
143-
context = "/" + serverContext + "/" + subContext
144-
data = "testData"
145-
r = tap.execute_secure(subcontext=subContext, data=data)
146-
assert r.status == 333, \
147-
"Status code, expected: %d, found: %d" % (333,
148-
r.status)
149-
assert r.get_method() == 'POST', \
150-
"Request method. Expected %s, found %s" % ('POST',
151-
r.get_method())
152-
assert r.get_context() == context, \
153-
"Request context. Expected %s, found %s" % (context,
154-
r.get_context())
155-
assert r.get_body() == data, \
156-
"Request body. Expected %s, found %s" % (data,
157-
str(r.get_body()))
92+
93+
def test_login():
94+
connSecure = DummyConn("https")
95+
connSecure.response.status = 333
96+
host = "testHost"
97+
serverContext = "testServerContext"
98+
tapContext = "testTapContext"
99+
connPort = 90
100+
connPortSsl = 943
101+
# TapConn
102+
tap = TapConn(ishttps=False,
103+
host=host,
104+
server_context=serverContext,
105+
tap_context=tapContext,
106+
port=connPort,
107+
sslport=connPortSsl,
108+
connhandler=connSecure)
109+
hostUrl = host + ":" + str(connPort) + "/" + serverContext + "/" \
110+
+ tapContext + "/"
111+
assert tap.get_host_url() == hostUrl
112+
hostUrlSecure = host + ":" + str(connPortSsl) + "/" + serverContext \
113+
+ "/" + tapContext + "/"
114+
assert tap.get_host_url_secure() == hostUrlSecure
115+
# POST SECURE
116+
subContext = "testSubContextPost"
117+
context = "/" + serverContext + "/" + subContext
118+
data = "testData"
119+
r = tap.execute_secure(subcontext=subContext, data=data)
120+
assert r.status == 333
121+
assert r.get_method() == 'POST'
122+
assert r.get_context() == context
123+
assert r.get_body() == data

0 commit comments

Comments
 (0)