def test_calls_events_system_error_throws(self): session = LeapSession() with (open(sampledatadir + "journeys_page_invalid_account.html", "r")) as f: page = f.read() with self.assertRaises(Exception) as context: session._LeapSession__handle_events_response(page) expected = Exception( u"System Error", u"The application experienced unexpected problems completing your request (Code E002). We're sorry for the inconvenience. Please try again later." ) self.assertEqual(str(context.exception), str(expected))
def test_calls_events_returns_expected(self): session = LeapSession() with (open(sampledatadir + "journeys_page.html", "r")) as f: page = f.read() result = session._LeapSession__handle_events_response(page) resultStr = "" for item in result: resultStr += str(item.__dict__) expected = "" if sys.version_info[0] < 3: expected = "{'event_type': u'Travel Credit Deduction', 'price': -1.96, 'time': u'6:02 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'11/02/2020'}{'event_type': u'Travel Credit Deduction', 'price': -1.96, 'time': u'8:30 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'08/02/2020'}{'event_type': u'Travel Credit Top-Up', 'price': 20.0, 'time': u'12:50 PM', 'was_topup': True, 'provider': u'Leap Top-Up App', 'date': u'08/02/2020'}{'event_type': u'Travel Credit Deduction', 'price': -1.96, 'time': u'6:22 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'05/07/2019'}" else: expected = "{'date': '11/02/2020', 'time': '6:02 PM', 'provider': 'Bus Eireann', 'price': -1.96, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '08/02/2020', 'time': '8:30 PM', 'provider': 'Bus Eireann', 'price': -1.96, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '08/02/2020', 'time': '12:50 PM', 'provider': 'Leap Top-Up App', 'price': 20.0, 'event_type': 'Travel Credit Top-Up', 'was_topup': True}{'date': '05/07/2019', 'time': '6:22 PM', 'provider': 'Bus Eireann', 'price': -1.96, 'event_type': 'Travel Credit Deduction', 'was_topup': False}" self.assertEqual(resultStr, expected)
def test_calls_events_returns_expected(self): session = LeapSession() with (open(pickledir + "journeys_page.dat", "rb")) as f: page = pickle.load(f) result = session._LeapSession__handle_events_response(page) resultStr = "" for item in result: resultStr += str(item.__dict__) expected = "" if sys.version_info[0] < 3: expected = "{'event_type': u'Travel Credit Deduction', 'price': -2.64, 'time': u'9:11 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'17/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -2.64, 'time': u'5:37 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'17/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'10:28 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'15/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'12:46 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'15/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'6:47 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'09/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'5:40 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'08/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'4:18 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'06/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'11:45 AM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'06/09/2017'}{'event_type': u'Travel Credit Top-Up', 'price': 50.0, 'time': u'10:00 AM', 'was_topup': True, 'provider': u'Leap Top-Up App', 'date': u'06/09/2017'}{'event_type': u'Travel Credit Deduction', 'price': -3.52, 'time': u'12:16 PM', 'was_topup': False, 'provider': u'Bus Eireann', 'date': u'02/09/2017'}" else: expected = "{'date': '17/09/2017', 'time': '9:11 PM', 'provider': 'Bus Eireann', 'price': -2.64, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '17/09/2017', 'time': '5:37 PM', 'provider': 'Bus Eireann', 'price': -2.64, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '15/09/2017', 'time': '10:28 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '15/09/2017', 'time': '12:46 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '09/09/2017', 'time': '6:47 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '08/09/2017', 'time': '5:40 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '06/09/2017', 'time': '4:18 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '06/09/2017', 'time': '11:45 AM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}{'date': '06/09/2017', 'time': '10:00 AM', 'provider': 'Leap Top-Up App', 'price': 50.0, 'event_type': 'Travel Credit Top-Up', 'was_topup': True}{'date': '02/09/2017', 'time': '12:16 PM', 'provider': 'Bus Eireann', 'price': -3.52, 'event_type': 'Travel Credit Deduction', 'was_topup': False}" self.assertEqual(resultStr, expected)