1313import pycaching
1414from pycaching import Geocaching , Point , Rectangle
1515from pycaching .errors import NotLoggedInException , LoginFailedException , PMOnlyException
16- from . import username as _username , password as _password , recorder , session , NetworkedTest
16+ from . import username as _username , password as _password , NetworkedTest
1717
1818
1919class TestMethods (NetworkedTest ):
2020 def test_search (self ):
2121 with self .subTest ("normal" ):
2222 tolerance = 2
2323 expected = {"GC5VJ0P" , "GC41FJC" , "GC17E8Y" , "GC14AV5" , "GC50AQ6" , "GC167Y7" }
24- with recorder .use_cassette ('geocaching_search' ):
24+ with self . recorder .use_cassette ('geocaching_search' ):
2525 found = {cache .wp for cache in self .gc .search (Point (49.733867 , 13.397091 ), 20 )}
2626 self .assertGreater (len (expected & found ), len (expected ) - tolerance )
2727
2828 with self .subTest ("pagging" ):
29- with recorder .use_cassette ('geocaching_search_pagination' ):
29+ with self . recorder .use_cassette ('geocaching_search_pagination' ):
3030 caches = list (self .gc .search (Point (49.733867 , 13.397091 ), 100 ))
3131 self .assertNotEqual (caches [0 ], caches [50 ])
3232
@@ -39,7 +39,7 @@ def test_search_quick(self):
3939 rect = Rectangle (Point (49.73 , 13.38 ), Point (49.74 , 13.40 ))
4040
4141 with self .subTest ("normal" ):
42- with recorder .use_cassette ('geocaching_quick_normal' ):
42+ with self . recorder .use_cassette ('geocaching_quick_normal' ):
4343 # Once this feature is fixed, the corresponding cassette will have to be deleted
4444 # and re-recorded.
4545 res = [c .wp for c in self .gc .search_quick (rect )]
@@ -50,13 +50,13 @@ def test_search_quick(self):
5050 self .assertGreater (len (res ), 90 )
5151
5252 with self .subTest ("strict handling of cache coordinates" ):
53- with recorder .use_cassette ('geocaching_quick_strictness' ):
53+ with self . recorder .use_cassette ('geocaching_quick_strictness' ):
5454 res = list (self .gc .search_quick (rect , strict = True ))
5555 self .assertLess (len (res ), expected_cache_num + tolerance )
5656 self .assertGreater (len (res ), expected_cache_num - tolerance )
5757
5858 with self .subTest ("larger zoom - more precise" ):
59- with recorder .use_cassette ('geocaching_quick_zoom' ):
59+ with self . recorder .use_cassette ('geocaching_quick_zoom' ):
6060 res1 = list (self .gc .search_quick (rect , strict = True , zoom = 15 ))
6161 res2 = list (self .gc .search_quick (rect , strict = True , zoom = 14 ))
6262 for res in res1 , res2 :
@@ -69,7 +69,7 @@ def test_search_quick(self):
6969 def test_search_quick_match_load (self ):
7070 """Test if quick search results matches exact cache locations."""
7171 rect = Rectangle (Point (49.73 , 13.38 ), Point (49.74 , 13.39 ))
72- with recorder .use_cassette ('geocaching_matchload' ):
72+ with self . recorder .use_cassette ('geocaching_matchload' ):
7373 # at commit time, this test is an allowed failure. Once this feature is fixed, the
7474 # corresponding cassette will have to be deleted and re-recorded.
7575 caches = list (self .gc .search_quick (rect , strict = True , zoom = 15 ))
@@ -83,7 +83,8 @@ def test_search_quick_match_load(self):
8383
8484class TestLoginOperations (NetworkedTest ):
8585 def setUp (self ):
86- self .gc = Geocaching (session = session )
86+ super ().setUp ()
87+ self .gc = Geocaching (session = self .session )
8788
8889 def test_request (self ):
8990 with self .subTest ("login needed" ):
@@ -92,24 +93,24 @@ def test_request(self):
9293
9394 def test_login (self ):
9495 with self .subTest ("bad credentials" ):
95- with recorder .use_cassette ('geocaching_badcreds' ):
96- session .cookies .clear ()
96+ with self . recorder .use_cassette ('geocaching_badcreds' ):
97+ self . session .cookies .clear ()
9798 with self .assertRaises (LoginFailedException ):
9899 self .gc .login ("0" , "0" )
99100
100101 with self .subTest ("good credentials twice" ):
101102 self .gc .logout ()
102- session .cookies .clear ()
103- self .gc ._session = session # gotta reattach so we can keep listening
104- with recorder .use_cassette ('geocaching_2login' ):
103+ self . session .cookies .clear ()
104+ self .gc ._session = self . session # gotta reattach so we can keep listening
105+ with self . recorder .use_cassette ('geocaching_2login' ):
105106 self .gc .login (_username , _password )
106107 self .gc .login (_username , _password )
107108
108109 with self .subTest ("bad credentials automatic logout" ):
109- with recorder .use_cassette ('geocaching_badcreds_logout' ):
110+ with self . recorder .use_cassette ('geocaching_badcreds_logout' ):
110111 self .gc .logout ()
111- session .cookies .clear ()
112- self .gc ._session = session # gotta reattach so we can keep listening
112+ self . session .cookies .clear ()
113+ self .gc ._session = self . session # gotta reattach so we can keep listening
113114 with self .assertRaises (LoginFailedException ):
114115 self .gc .login ("0" , "0" )
115116
@@ -144,16 +145,16 @@ def test_login(self):
144145 self .gc .login ()
145146
146147 def test_get_logged_user (self ):
147- with recorder .use_cassette ('geocaching_loggeduser' ):
148+ with self . recorder .use_cassette ('geocaching_loggeduser' ):
148149 self .gc .login (_username , _password )
149150 self .assertEqual (self .gc .get_logged_user (), _username )
150151
151152 def test_logout (self ):
152- with recorder .use_cassette ('geocaching_logout' ):
153+ with self . recorder .use_cassette ('geocaching_logout' ):
153154 self .gc .login (_username , _password )
154155 self .gc .logout ()
155- session .cookies .clear ()
156- self .gc ._session = session # gotta reattach so we can keep listening
156+ self . session .cookies .clear ()
157+ self .gc ._session = self . session # gotta reattach so we can keep listening
157158 self .assertIsNone (self .gc .get_logged_user ())
158159
159160 def test_load_credentials (self ):
@@ -262,25 +263,25 @@ def test_login(self):
262263 real_init = Geocaching .__init__
263264
264265 def fake_init (self_ , unused_argument = None ):
265- real_init (self_ , session = session )
266+ real_init (self_ , session = self . session )
266267
267268 # patching with the fake init method above to insert our session into the Geocaching object for testing
268269 with patch .object (Geocaching , '__init__' , new = fake_init ):
269- with recorder .use_cassette ('geocaching_shortcut_login' ):
270+ with self . recorder .use_cassette ('geocaching_shortcut_login' ):
270271 pycaching .login (_username , _password )
271272
272273 def test_geocode (self ):
273274 ref_point = Point (50.08746 , 14.42125 )
274- with recorder .use_cassette ('geocaching_shortcut_geocode' ):
275+ with self . recorder .use_cassette ('geocaching_shortcut_geocode' ):
275276 self .assertLess (great_circle (self .gc .geocode ("Prague" ), ref_point ).miles , 10 )
276277
277278 def test_get_cache (self ):
278- with recorder .use_cassette ('geocaching_shortcut_getcache' ):
279+ with self . recorder .use_cassette ('geocaching_shortcut_getcache' ):
279280 c = self .gc .get_cache ("GC4808G" )
280281 self .assertEqual ("Nekonecne ticho" , c .name )
281282
282283 def test_get_trackable (self ):
283- with recorder .use_cassette ('geocaching_shortcut_gettrackable' ):
284+ with self . recorder .use_cassette ('geocaching_shortcut_gettrackable' ):
284285 t = self .gc .get_trackable ("TB1KEZ9" )
285286 self .assertEqual ("Lilagul #2: SwedenHawk Geocoin" , t .name )
286287
0 commit comments