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)]
Exemplo n.º 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_convert_string_json_to_python_dict_with_valid_json(self):
     self.assertEqual({u'id': 1, u'name': u'test'}, convert_string_json_to_python_dict('{"id": 1, "name": "test"}'))
 def test_convert_string_json_to_python_dict_with_invalid_json(self):
     self.assertRaises(ValueError, lambda: convert_string_json_to_python_dict("{'id': 1, 'name': 'test'}"))
 def test_convert_string_json_to_python_dict_with_valid_json(self):
     self.assertEqual({
         u'id': 1,
         u'name': u'test'
     }, convert_string_json_to_python_dict('{"id": 1, "name": "test"}'))
 def test_convert_string_json_to_python_dict_with_invalid_json(self):
     self.assertRaises(
         ValueError, lambda: convert_string_json_to_python_dict(
             "{'id': 1, 'name': 'test'}"))