Exemplo n.º 1
0
    def test_postCode(self):
        ah = ApiHandler()
        result = ah.get_postcode("liverpool")
        self.assertTrue(result.isnumeric(), msg="postcode is not numeric.")
        self.assertEqual(len(result),
                         4,
                         msg="postcode length is not equal to 4.")

        result = ah.get_postcode("urumqi")
        self.assertIsNone(result, msg="for wrong suburb should return None.")
Exemplo n.º 2
0
def ask_region():
    '''
    User Input:
        Either NSW Suburb name or Postcode (Delivery Area)
    Returns:
        Postal Code of NSW Delivery Area
    Example: 2000, 2170
    '''
    # Create ApiHandler Class instance
    # This class handles all API calls and data collections
    api = ApiHandler()
    print("This app will find petrol stations around you")
    print("based on the 'suburb' or 'postcode' provided.\n")
    print("press 'q' to quit.\n")

    user_input = input('Please Enter your Postcode or Suburb: (q to exit)\n')
    while True:
        clear()
        if user_input.lower() == 'q':
            print('Thanks for using this app, Bye!')
            sys.exit()
        if user_input.isnumeric():
            if postcode_exists(user_input):
                return user_input
            else:
                print(
                    'Entered Postcode is not valid NSW Delivery Area Postal Code'
                )
                print(
                    'Please make sure the postcode is a valid postcode (e.g.: starts with 2 and 4 digit long)'
                )
        else:
            postcode = api.get_postcode(user_input)
            if postcode:
                return postcode
            else:
                print(
                    "The system cannot match the entered suburb to a valid NSW postal code."
                )
                print("Please enter valided or nearby adjacent suburbs...")
        user_input = input('Please Enter Postcode or Suburb: \n')