def testShouldRecognizeWhenSessionHasExpiredWhileFetchingLocProfiles(self): from strings_for_testing import EXPIRED_PASSWORD_LOGIN_FORM source = LocationsScreenscrapeSource() @patch(source) def get_preferences_response(self, conn, sessionid): return EXPIRED_PASSWORD_LOGIN_FORM, None expected_code = 'invalid_session' try: sessionid = None source.fetch_location_profiles(sessionid) except ScreenscrapeFetchError, sfe: self.assertEqual(sfe.code, expected_code, 'Fetch has incorrect code: %r, expected %r' % (sfe.code, expected_code)) return
def testShouldConstructExpectedLocationProfilesFromPcsConnectionContent(self): # Given... class StubConnection (object): def request(self, url, method, data, headers): import StringIO response = StringIO.StringIO(r'''<table><thead><tr id="dpref_driver_pk__preferences_pk__driver_locations_pk__header"><th>Default</th><th>Name</th><th>Description</th><th></th></tr></thead><tbody id="dpref_driver_pk__preferences_pk__driver_locations_pk__noprofiles" style="display: none; "><tr><td colspan="4">You have no saved locations.</td></tr></tbody><tbody id="dpref_driver_pk__preferences_pk__driver_locations_pk__profiles"><tr class=""><td><input type="radio" class="profile_default" value="18065565" checked="checked"></td><td class="profile_name">My House</td><td class="profile_descr"></td><td><a href="javascript:void(0);" class="profile_name">Edit</a> <a href="javascript:void(0);" class="delete_profile">Delete</a></td></tr><tr class="zebra"><td><input type="radio" class="profile_default" value="25782103"></td><td class="profile_name">My Job</td><td class="profile_descr">Walnut St & S 33rd St, Philadelphia, PA 19104, USA</td><td><a href="javascript:void(0);" class="profile_name">Edit</a> <a href="javascript:void(0);" class="delete_profile">Delete</a></td></tr><tr class=""><td><input type="radio" class="profile_default" value="17966898"></td><td class="profile_name">Sprucemont</td><td class="profile_descr"></td><td><a href="javascript:void(0);" class="profile_name">Edit</a> <a href="javascript:void(0);" class="delete_profile">Delete</a></td></tr><tr class="zebra"><td><input type="radio" class="profile_default" value="25618502"></td><td class="profile_name">UPenn Library</td><td class="profile_descr">Walnut St & S 36th St, Philadelphia, PA 19104, USA</td><td><a href="javascript:void(0);" class="profile_name">Edit</a> <a href="javascript:void(0);" class="delete_profile">Delete</a></td></tr></tbody><tbody id="dpref_driver_pk__preferences_pk__driver_locations_pk__favourites"><tr class=""><td><input type="radio" class="profile_default" value="0"></td><td colspan="2">Favorites</td><td></td></tr><tr class="zebra"><td><input type="hidden" value="2041034"></td><td colspan="2"> 47th & Baltimore - Scion xB</td><td><a href="javascript:void(0);" class="delete_favourite">Delete</a></td></tr><tr class=""><td><input type="hidden" value="4756298"></td><td colspan="2"> 47th & Baltimore - Sienna Minivan</td><td><a href="javascript:void(0);" class="delete_favourite">Delete</a></td></tr></tbody></table>''') response.getheaders = lambda: {'h1':1} return response StubConnection = Stub(PcsConnection)(StubConnection) source = LocationsScreenscrapeSource() @patch(source) def create_connection(self): return StubConnection() # When... locations = source.fetch_location_profiles(sessionid='123abc') # Then... self.assertEqual(locations[0].name, 'My House') self.assertEqual(len(locations), 4) self.assertEqual(locations[3].name, 'UPenn Library')