Esempio n. 1
0
 def test_get_all_cities_multiple(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://offenedaten.de/api/action/organization_list",
         body='{"success": true, "result": ["land", "berlin"]}',
         content_type="application/json")
     httpretty.register_uri(
         httpretty.POST,
         "https://offenedaten.de/api/action/organization_show?id=berlin&include_datasets=False",
         body=
         '{"success": true, "result": { "package_count": 0,"name": "berlin", "extras": [{ "key": "city_type", "value": "Stadt"}]}}',
         content_type="application/json")
     httpretty.register_uri(
         httpretty.POST,
         "https://offenedaten.de/api/action/organization_show?id=land&include_datasets=False",
         body=
         '{"success": true, "result": { "package_count": 0,"name": "land", "extras": [{ "key": "city_type", "value": "Land"}]}}',
         content_type="application/json")
     od = OffeneDaten()
     assert od.get_all_cities() == [{
         "package_count":
         0,
         "name":
         "berlin",
         "extras": [{
             "key": "city_type",
             "value": "Stadt"
         }]
     }]
Esempio n. 2
0
 def test_get_all_cities(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://offenedaten.de/api/action/organization_list",
         body='{"success": true, "result": []}',
         content_type="application/json")
     od = OffeneDaten()
     assert od.get_all_cities() == []
     assert od.org_data == []
Esempio n. 3
0
def get_all_cities(event, context):
    od = OffeneDaten()
    cities = od.get_all_cities()
    cityCount = len(cities)
    city_names = [city["name"] for city in cities]
    data = {
        'job_name': 'get_all_cities',
        'date': datetime.date.today().strftime('%Y-%m-%d'),
        'org_count': cityCount,
        'cities': city_names
    }
    with open('/tmp/get_all_cities.json', 'w') as f:
        json.dump(data, f)
    utils.upload_file_to_s3('get_all_cities.json', '/tmp/get_all_cities.json')
    # start the lambda services
    responses = [collect_cities(city) for city in city_names]
    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": event
    }

    response = {"statusCode": 200, "body": json.dumps(body)}

    return response