def get_all_customers_from_file(file_path):
    """
    This function takes the file path that contains a json with
    a list of customers in the following format:
    {"latitude": "52.986375", "user_id": 12, "name": "Christina McArdle", "longitude": "-6.043701"}
    {"latitude": "51.92893", "user_id": 1, "name": "Alice Cahill", "longitude": "-10.27699"}
    {"latitude": "51.8856167", "user_id": 2, "name": "Ian McArdle", "longitude": "-10.4240951"}
    
    And return a list of customers in this format:
    [{u'latitude': u'52.986375', u'user_id': 12, u'name': u'Christina McArdle', u'longitude': u'-6.043701'},
     {u'latitude': u'51.92893', u'user_id': 1, u'name': u'Alice Cahill', u'longitude': u'-10.27699'},
     {u'latitude': u'51.8856167', u'user_id': 2, u'name': u'Ian McArdle', u'longitude': u'-10.4240951'}]

    It raise a IOError in case the file_path parameter are wrong
    """
    return [convert_string_json_to_python_dict(customer)
            for customer in read_file_generator(file_path)]
Example #2
0
def get_all_customers_from_file(file_path):
    """
    This function takes the file path that contains a json with
    a list of customers in the following format:
    {"latitude": "52.986375", "user_id": 12, "name": "Christina McArdle", "longitude": "-6.043701"}
    {"latitude": "51.92893", "user_id": 1, "name": "Alice Cahill", "longitude": "-10.27699"}
    {"latitude": "51.8856167", "user_id": 2, "name": "Ian McArdle", "longitude": "-10.4240951"}
    
    And return a list of customers in this format:
    [{u'latitude': u'52.986375', u'user_id': 12, u'name': u'Christina McArdle', u'longitude': u'-6.043701'},
     {u'latitude': u'51.92893', u'user_id': 1, u'name': u'Alice Cahill', u'longitude': u'-10.27699'},
     {u'latitude': u'51.8856167', u'user_id': 2, u'name': u'Ian McArdle', u'longitude': u'-10.4240951'}]

    It raise a IOError in case the file_path parameter are wrong
    """
    return [
        convert_string_json_to_python_dict(customer)
        for customer in read_file_generator(file_path)
    ]
 def test_read_file_generator_with_wrong_path(self):
     self.assertRaises(IOError, lambda: list(read_file_generator("wrong_path")))
 def test_read_file_generator_right_path(self):
     self.assertEqual(
         list(islice(read_file_generator("customers.json"), 1)),
         ['{"latitude": "52.986375", "user_id": 12, "name": "Christina McArdle", "longitude": "-6.043701"}\n'])
 def test_read_file_generator_with_wrong_path(self):
     self.assertRaises(IOError,
                       lambda: list(read_file_generator("wrong_path")))
 def test_read_file_generator_right_path(self):
     self.assertEqual(
         list(islice(read_file_generator("customers.json"), 1)), [
             '{"latitude": "52.986375", "user_id": 12, "name": "Christina McArdle", "longitude": "-6.043701"}\n'
         ])