コード例 #1
0
 def test_empty_file(self):
     """Test for empty file."""
     data = e.get_alert_info('/tmp/temporary_file.csv')
     self.assertFalse(data)
コード例 #2
0
 def test_no_alert(self):
     """Test for incorrect color level."""
     alert_info = e.get_alert_info('random_color_that_nobody_knows',
                                   file_path=path_to_csv)
     self.assertFalse(alert_info)
コード例 #3
0
 def test_no_datafile(self):
     """Test for non existing file."""
     alert_info = e.get_alert_info('green',
                                   file_path="/tmp/random_name.csv")
     self.assertFalse(alert_info)
コード例 #4
0
 def test_alert_info(self):
     """Test that info about a correct alert level is retrieved."""
     alert_info = e.get_alert_info('green', file_path=path_to_csv)
     self.assertIsInstance(alert_info, list)
コード例 #5
0

if __name__ == "__main__":
    args = parse_arguments()
    # See first if the user is allowed to perform the action
    dbmanager.open_and_create(db_abs_path)
    if args.v:
        print('Checking user credentials ...')
    if not dbmanager.is_allowed(args.username, args.password):
        print("Invalid credentials, please check username and password")
        exit()

    # IF THE USER IS ALLOWED ...
    days = int(args.days)
    # If the alert level is made explicit by the user verbosity is set to true
    # describe the alert level to the user
    if args.alertlevel and args.v:
        level_info = earthquakes.get_alert_info(args.alertlevel)
        if level_info:
            print('The {} level is described as having {} estimated '
                  'fatalities and {} estimated losses in USD'
                  .format(level_info[0], level_info[1], level_info[2]))
    # search for the earthquakes
    mag, place = earthquakes.get_earthquake(days, args.alertlevel, args.v)
    if mag and place:
        print('The largest earthquake of last {} days had magnitude {} '
              'and was located at {}'.format(days, mag, place))
    else:
        print('No earthquake found with the specified parameters! Please '
              'choose a larger timespan or a lower alertlevel')