1313import pycaching
1414from pycaching import Cache , 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_my_finds (self ):
21- with recorder .use_cassette ('geocaching_my_finds' ):
21+ with self . recorder .use_cassette ('geocaching_my_finds' ):
2222 finds = list (self .gc .my_finds (20 ))
2323 self .assertEqual (20 , len (finds ))
2424 for cache in finds :
@@ -37,12 +37,12 @@ def test_search(self):
3737 with self .subTest ("normal" ):
3838 tolerance = 2
3939 expected = {"GC5VJ0P" , "GC41FJC" , "GC17E8Y" , "GC14AV5" , "GC50AQ6" , "GC167Y7" }
40- with recorder .use_cassette ('geocaching_search' ):
40+ with self . recorder .use_cassette ('geocaching_search' ):
4141 found = {cache .wp for cache in self .gc .search (Point (49.733867 , 13.397091 ), 20 )}
4242 self .assertGreater (len (expected & found ), len (expected ) - tolerance )
4343
4444 with self .subTest ("pagging" ):
45- with recorder .use_cassette ('geocaching_search_pagination' ):
45+ with self . recorder .use_cassette ('geocaching_search_pagination' ):
4646 caches = list (self .gc .search (Point (49.733867 , 13.397091 ), 100 ))
4747 self .assertNotEqual (caches [0 ], caches [50 ])
4848
@@ -55,7 +55,7 @@ def test_search_quick(self):
5555 rect = Rectangle (Point (49.73 , 13.38 ), Point (49.74 , 13.40 ))
5656
5757 with self .subTest ("normal" ):
58- with recorder .use_cassette ('geocaching_quick_normal' ):
58+ with self . recorder .use_cassette ('geocaching_quick_normal' ):
5959 # Once this feature is fixed, the corresponding cassette will have to be deleted
6060 # and re-recorded.
6161 res = [c .wp for c in self .gc .search_quick (rect )]
@@ -66,13 +66,13 @@ def test_search_quick(self):
6666 self .assertGreater (len (res ), 90 )
6767
6868 with self .subTest ("strict handling of cache coordinates" ):
69- with recorder .use_cassette ('geocaching_quick_strictness' ):
69+ with self . recorder .use_cassette ('geocaching_quick_strictness' ):
7070 res = list (self .gc .search_quick (rect , strict = True ))
7171 self .assertLess (len (res ), expected_cache_num + tolerance )
7272 self .assertGreater (len (res ), expected_cache_num - tolerance )
7373
7474 with self .subTest ("larger zoom - more precise" ):
75- with recorder .use_cassette ('geocaching_quick_zoom' ):
75+ with self . recorder .use_cassette ('geocaching_quick_zoom' ):
7676 res1 = list (self .gc .search_quick (rect , strict = True , zoom = 15 ))
7777 res2 = list (self .gc .search_quick (rect , strict = True , zoom = 14 ))
7878 for res in res1 , res2 :
@@ -85,7 +85,7 @@ def test_search_quick(self):
8585 def test_search_quick_match_load (self ):
8686 """Test if quick search results matches exact cache locations."""
8787 rect = Rectangle (Point (49.73 , 13.38 ), Point (49.74 , 13.39 ))
88- with recorder .use_cassette ('geocaching_matchload' ):
88+ with self . recorder .use_cassette ('geocaching_matchload' ):
8989 # at commit time, this test is an allowed failure. Once this feature is fixed, the
9090 # corresponding cassette will have to be deleted and re-recorded.
9191 caches = list (self .gc .search_quick (rect , strict = True , zoom = 15 ))
@@ -100,7 +100,7 @@ def test_search_quick_match_load(self):
100100class TestLoginOperations (NetworkedTest ):
101101 def setUp (self ):
102102 super ().setUp ()
103- self .gc = Geocaching (session = session )
103+ self .gc = Geocaching (session = self . session )
104104
105105 def test_request (self ):
106106 with self .subTest ("login needed" ):
@@ -109,24 +109,24 @@ def test_request(self):
109109
110110 def test_login (self ):
111111 with self .subTest ("bad credentials" ):
112- with recorder .use_cassette ('geocaching_badcreds' ):
113- session .cookies .clear ()
112+ with self . recorder .use_cassette ('geocaching_badcreds' ):
113+ self . session .cookies .clear ()
114114 with self .assertRaises (LoginFailedException ):
115115 self .gc .login ("0" , "0" )
116116
117117 with self .subTest ("good credentials twice" ):
118118 self .gc .logout ()
119- session .cookies .clear ()
120- self .gc ._session = session # gotta reattach so we can keep listening
121- with recorder .use_cassette ('geocaching_2login' ):
119+ self . session .cookies .clear ()
120+ self .gc ._session = self . session # gotta reattach so we can keep listening
121+ with self . recorder .use_cassette ('geocaching_2login' ):
122122 self .gc .login (_username , _password )
123123 self .gc .login (_username , _password )
124124
125125 with self .subTest ("bad credentials automatic logout" ):
126- with recorder .use_cassette ('geocaching_badcreds_logout' ):
126+ with self . recorder .use_cassette ('geocaching_badcreds_logout' ):
127127 self .gc .logout ()
128- session .cookies .clear ()
129- self .gc ._session = session # gotta reattach so we can keep listening
128+ self . session .cookies .clear ()
129+ self .gc ._session = self . session # gotta reattach so we can keep listening
130130 with self .assertRaises (LoginFailedException ):
131131 self .gc .login ("0" , "0" )
132132
@@ -161,16 +161,16 @@ def test_login(self):
161161 self .gc .login ()
162162
163163 def test_get_logged_user (self ):
164- with recorder .use_cassette ('geocaching_loggeduser' ):
164+ with self . recorder .use_cassette ('geocaching_loggeduser' ):
165165 self .gc .login (_username , _password )
166166 self .assertEqual (self .gc .get_logged_user (), _username )
167167
168168 def test_logout (self ):
169- with recorder .use_cassette ('geocaching_logout' ):
169+ with self . recorder .use_cassette ('geocaching_logout' ):
170170 self .gc .login (_username , _password )
171171 self .gc .logout ()
172- session .cookies .clear ()
173- self .gc ._session = session # gotta reattach so we can keep listening
172+ self . session .cookies .clear ()
173+ self .gc ._session = self . session # gotta reattach so we can keep listening
174174 self .assertIsNone (self .gc .get_logged_user ())
175175
176176 def test_load_credentials (self ):
@@ -279,30 +279,30 @@ def test_login(self):
279279 real_init = Geocaching .__init__
280280
281281 def fake_init (self_ , unused_argument = None ):
282- real_init (self_ , session = session )
282+ real_init (self_ , session = self . session )
283283
284284 # patching with the fake init method above to insert our session into the Geocaching object for testing
285285 with patch .object (Geocaching , '__init__' , new = fake_init ):
286- with recorder .use_cassette ('geocaching_shortcut_login' ):
286+ with self . recorder .use_cassette ('geocaching_shortcut_login' ):
287287 pycaching .login (_username , _password )
288288
289289 def test_geocode (self ):
290290 ref_point = Point (50.08746 , 14.42125 )
291- with recorder .use_cassette ('geocaching_shortcut_geocode' ):
291+ with self . recorder .use_cassette ('geocaching_shortcut_geocode' ):
292292 self .assertLess (great_circle (self .gc .geocode ("Prague" ), ref_point ).miles , 10 )
293293
294294 def test_get_cache (self ):
295- with recorder .use_cassette ('geocaching_shortcut_getcache' ):
295+ with self . recorder .use_cassette ('geocaching_shortcut_getcache' ):
296296 c = self .gc .get_cache ("GC4808G" )
297297 self .assertEqual ("Nekonecne ticho" , c .name )
298298
299299 def test_get_cache__by_guid (self ):
300- with recorder .use_cassette ('geocaching_shortcut_getcache__by_guid' ):
300+ with self . recorder .use_cassette ('geocaching_shortcut_getcache__by_guid' ):
301301 cache = self .gc .get_cache (guid = '15ad3a3d-92c1-4f7c-b273-60937bcc2072' )
302302 self .assertEqual ("Nekonecne ticho" , cache .name )
303303
304304 def test_get_trackable (self ):
305- with recorder .use_cassette ('geocaching_shortcut_gettrackable' ):
305+ with self . recorder .use_cassette ('geocaching_shortcut_gettrackable' ):
306306 t = self .gc .get_trackable ("TB1KEZ9" )
307307 self .assertEqual ("Lilagul #2: SwedenHawk Geocoin" , t .name )
308308
0 commit comments