def test_expires_date_returns_earliest_expiry_time(alert_dict):
    alert = Alert(alert_dict)
    assert alert.expires_date.as_iso8601 == alert.cancelled_at_date.as_iso8601

    alert_dict['cancelled_at'] = None
    alert = Alert(alert_dict)
    assert alert.expires_date.as_iso8601 == alert.finishes_at_date.as_iso8601
def test_lt_compares_alerts_based_on_start_date():
    alert_dict_1 = create_alert_dict()
    alert_dict_2 = create_alert_dict()

    alert_dict_1['starts_at'] = dt_parse('2021-04-21T11:30:00Z')
    alert_dict_2['starts_at'] = dt_parse('2021-04-21T12:30:00Z')

    assert Alert(alert_dict_1) < Alert(alert_dict_2)
def test_display_areas_falls_back_to_granular_names(alert_dict):
    alert_dict['areas']['aggregate_names'] = ['aggregate name']
    alert_dict['areas']['names'] = ['granular name']

    assert Alert(alert_dict).display_areas == ['aggregate name']

    del alert_dict['areas']['aggregate_names']
    assert Alert(alert_dict).display_areas == ['granular name']

    del alert_dict['areas']['names']
    assert Alert(alert_dict).display_areas == []
def test_get_url_for_alert_consistently_sorts_by_id():
    # all have the same start time
    the_days_alerts = [
        create_alert_dict(id=UUID(int=0)),
        create_alert_dict(id=UUID(int=1)),
        create_alert_dict(id=UUID(int=2)),
        create_alert_dict(id=UUID(int=3)),
        create_alert_dict(id=UUID(int=4)),
        create_alert_dict(id=UUID(int=5)),
        create_alert_dict(id=UUID(int=6)),
    ]

    # shuffle to make sure the order that alerts go in doesn't affect anything
    alerts = Alerts(random.sample(the_days_alerts, len(the_days_alerts)))

    assert get_url_for_alert(Alert(the_days_alerts[0]), alerts) == '21-apr-2021'
    assert get_url_for_alert(Alert(the_days_alerts[3]), alerts) == '21-apr-2021-4'
    assert get_url_for_alert(Alert(the_days_alerts[6]), alerts) == '21-apr-2021-7'
def test_get_url_for_alert_skips_non_public_alerts():
    the_days_alerts = [
        create_alert_dict(starts_at=dt_parse('2021-04-21T12:00:00Z'), channel='operator'),
        create_alert_dict(starts_at=dt_parse('2021-04-21T13:00:00Z'), channel='severe'),
    ]

    alerts = Alerts(the_days_alerts)

    # doesn't have the -2 suffix as we skip the operator alert
    assert get_url_for_alert(Alert(the_days_alerts[1]), alerts) == '21-apr-2021'
def test_get_url_for_alert_returns_url_with_count_for_alerts_on_same_day(index, expected_url):
    the_days_alerts = [
        create_alert_dict(id=UUID(int=0), starts_at=dt_parse('2021-04-20T22:59:00Z')),
        create_alert_dict(id=UUID(int=1), starts_at=dt_parse('2021-04-20T23:00:00Z')),
        create_alert_dict(id=UUID(int=2), starts_at=dt_parse('2021-04-21T12:31:00Z')),
        create_alert_dict(id=UUID(int=3), starts_at=dt_parse('2021-04-21T12:31:00Z')),
        create_alert_dict(id=UUID(int=4), starts_at=dt_parse('2021-04-21T23:00:00Z')),
    ]

    alerts = Alerts(the_days_alerts)

    assert get_url_for_alert(Alert(the_days_alerts[index]), alerts) == expected_url
示例#7
0
def upload(vehiclePlate):
    vehicle=Vehicles.query.filter_by(vehiclePlate=vehiclePlate).first()
    path=vehicle.videos
    video=Video()
    alert=Alert()
    apikey=request.headers.get('Apikey')
    if vehicle and vehicle.apiKey ==apikey:
        os.chmod(path, stat.S_IWOTH)
        if request.method == 'POST':
            file = request.files['files']
            if file :
                try:
                   filename=time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+ '.mp4'
                   video.carPlate=vehiclePlate
                   video.path=path+"/"+filename
                   video.uploadDate=time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
                   video.videoName=filename
                   file.save(path+"/"+filename)
                   message = " a new Alert Video uploads at" + video.uploadDate
                   alert.userid = vehicle.uid
                   alert.Plate = vehicle.vehiclePlate
                   alert.message = message
                   vehicle.videoNumber +=1
                   user=User.query.filter_by(id=vehicle.id).first()
                   video.uid =user.id
                   user.alertNumber += 1
                   db.session.add(user)
                   db.session.add(vehicle)
                   db.session.add(alert)
                   db.session.add(video)
                   db.session.commit()
                   return jsonify("successfully upload"),redirect(url_for('web.detection',videoname=video.videoName))
                except Exception as e:
                    db.session.rollback()
                    raise e

    return jsonify("Failure")
def test_is_public(channel, is_public, alert_dict):
    alert_dict['channel'] = channel
    assert Alert(alert_dict).is_public == is_public
def test_alert_timestamps_properties_are_AlertDates(alert_dict):
    alert = Alert(alert_dict)
    assert isinstance(alert.approved_at_date, AlertDate)
    assert isinstance(alert.cancelled_at_date, AlertDate)
    assert isinstance(alert.finishes_at_date, AlertDate)
    assert isinstance(alert.starts_at_date, AlertDate)
def test_is_current_and_public(is_current, is_public, is_current_and_public,
                               mocker, alert_dict):
    mocker.patch(__name__ + '.Alert.is_current', is_current)
    mocker.patch(__name__ + '.Alert.is_public', is_public)
    assert Alert(alert_dict).is_current_and_public == is_current_and_public
def test_is_current_alert_checks_if_alert_is_current(approved_at_date,
                                                     expiry_date, is_current,
                                                     alert_dict):
    alert_dict['approved_at'] = approved_at_date
    alert_dict['cancelled_at'] = expiry_date
    assert Alert(alert_dict).is_current == is_current
def test_is_expired_alert_checks_if_alert_is_expired(expiry_date, is_expired,
                                                     alert_dict):
    alert_dict['cancelled_at'] = expiry_date
    assert Alert(alert_dict).is_expired == is_expired
def test_display_areas_shows_public_alerts_only(channel,
                                                expected_display_areas,
                                                alert_dict):
    alert_dict['channel'] = channel
    alert_dict['areas']['aggregate_names'] = ['Chipping Sodbury']
    assert Alert(alert_dict).display_areas == expected_display_areas