Exemplo n.º 1
0
 def get_valid_auth(self):
     """
     Function to login using a dummy account with all permissions set true
     :return: jwt for user with all permissions
     """
     user = Environ().get_test_creds('user', True)
     pwd = Environ().get_test_creds('password', True)
     token = self.mock_login(user, pwd)
     if token:
         return token
     else:
         raise Exception('Wrong credentials for valid test')
Exemplo n.º 2
0
 def get_geo_pollution_data(lat, lng):
     BREEZOMETER_KEY = Environ().get_breezometer_api_key()
     BASE_URL = Environ().get_breezometer_base_url()
     features = "breezometer_aqi,dominant_pollutant_concentrations,pollutants_concentrations,all_pollutants_concentrations"
     if lat is None or lng is None:
         return status.HTTP_400_BAD_REQUEST
     url = BASE_URL + BREEZOMETER_KEY + \
         '&metadata=true&features=' + features + \
         '&lat=' + str(lat) + '&lon=' + str(lng)
     response = requests.get(url)
     if response.status_code == 200:
         return response.json()
     else:
         return status.HTTP_500_INTERNAL_SERVER_ERROR
Exemplo n.º 3
0
 def run_job(self):
     headers = {"Authorization": TestUtils().get_valid_auth()}
     url = Environ().get_base_bus_stop_url()
     stops = busstop_util.BusStopUtil().get_bus_stop_coordinates()
     if (stops is not None):
         data = busstop_util.BusStopUtil.format_data(stops)
         response = requests.post(url, json={"data": json.dumps(data)}, headers=headers)
Exemplo n.º 4
0
 def test_bus_tt_retrieval(self):
     params = {"stopid": 4518}
     response = requests.get(url=Environ().get_base_bus_internal_tt_url(),
                             params=params,
                             headers=headers)
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      response.status_code)
 def run_job(self):
     headers = {"Authorization": TestUtils().get_valid_auth()}
     timestamp = str(datetime.datetime.now())
     sections = pollution_util.PollutionUtil.get_city_sections()
     data = []
     url = Environ().get_base_pollution_url()
     for section in sections:
         response = pollution_util.PollutionUtil.get_geo_pollution_data(
             section[0], section[1])
         if (response is None):
             continue
         else:
             lat = section[0]
             lng = section[1]
             location = "{} {}".format(lat, lng)
             TimeSeriesUtils.update_model(
                 response['data']['indexes']['baqi']['aqi'], location,
                 'pollution')
             response = pollution_util.PollutionUtil.sanitize_data(
                 response, section[0], section[1])
             response["timestamp"] = timestamp
             data.append(response)
     response = requests.post(url,
                              json={"data": json.dumps(data)},
                              headers=headers)
 def test_retrieval_by_lat_long_function(self):
     valid_token = TestUtils().get_valid_auth()
     headers = {"Authorization": valid_token}
     response = requests.get(url=Environ().get_base_traffic_url(),
                             headers=headers)
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      response.status_code)
Exemplo n.º 7
0
 def test_insertion_api(self):
     data = open('./static/data/json/test_data_bike.json', 'r')
     request_json = data.read()
     response = requests.post(url=Environ().get_base_bike_url(),
                              data={"data": request_json},
                              headers=headers)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 8
0
 def run_job(self):
     headers = {"Authorization": TestUtils().get_valid_auth()}
     url = Environ().get_base_bike_url()
     bikes_data = bike_util.BikeUtil.get_dublin_bikes_data()
     response = bike_util.BikeUtil.format_dublin_bikes_data(bikes_data)
     for stop in response:
         TimeSeriesUtils.update_model(stop['available_bikes'], stop['name'], 'bikes')
     response = requests.post(url, json={"data": json.dumps(response)}, headers=headers)
Exemplo n.º 9
0
 def mock_login(self, user, pwd):
     url = Environ().get_localhost()
     url += '/mongo_auth/login/'
     response = requests.post(url=url, data={"username": user, "password": pwd})
     resp = response.json()
     token = ''
     if resp.get('data') and resp.get('data').get('token'):
         token = resp.get('data').get('token')
     return token
 def test_insertion_api(self):
     data = open('./test_data_traffic.json', 'r')
     request_json = data.read()
     print(request_json)
     valid_token = TestUtils().get_valid_auth()
     headers = {"Authorization": valid_token}
     response = requests.post(url=Environ().get_base_traffic_url(),
                              data={"data": request_json},
                              headers=headers)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 11
0
 def run_job(self):
     headers = {"Authorization": TestUtils().get_valid_auth()}
     url_stops = Environ().get_base_traffic_url()
     url_traffic_analysis = url_stops + "/analysis"
     timestamp = datetime.datetime.now()
     response_array = []
     response_analysis_array = []
     signals = traffic_util.TrafficUtil().get_signal_coordinates()
     for s in range(signals.shape[0]):
         response = traffic_util.TrafficUtil.get_traffic_data(signals.iloc[s,0], signals.iloc[s,1])
         response["timestamp"] = timestamp
         response_for_analysis = response
         response = traffic_util.TrafficUtil.sanitize_data(response, signals.iloc[s,0], signals.iloc[s,1])
         response_for_analysis = traffic_util.TrafficUtil.sanitize_data_for_analysis(response_for_analysis, signals.iloc[s,0], signals.iloc[s,1])
         response_array.append(response)
         response_analysis_array.append(response_for_analysis)
     response = requests.post(url_stops, json={"data": json.dumps(response_array)}, headers = headers)
     response_for_analysis = requests.post(url_traffic_analysis, json={"data": json.dumps(response_analysis_array)}, headers=headers)
 def test_retrieval_by_lat_long_function(self):
     response = requests.get(url=Environ().get_base_luas_stop_url(), headers=headers)
     self.assertEqual(response.status_code, status.HTTP_200_OK, response.status_code)
 def get_busstop_timetable(self, stopid):
     params = {'stopid': stopid}
     timetable = requests.get(url=Environ().get_base_bus_stop_tt_url(),
                              params=params)
     return timetable.text