Exemple #1
0
def test_notifications_retrieval_range(client):
    user_id = random.randint(0, 999999)
    req = random_notification_insert_values(20, user_id)
    notifications.insert(req)

    res = client.get('/notifications/' + str(user_id) + '?range=10_20')
    assert res.status_code == 200
    assert len(res.json["notifications"]) == 10
Exemple #2
0
def test_insert():
    insert_values = [random_notification_insert_value() for _ in range(0, 20)]
    notifications.insert(insert_values)

    user_id = insert_values[0][1]

    lst = notifications.list_all(user_id, PaginatedQuery(0, 10))
    assert len(lst) >= 1
Exemple #3
0
def test_notifications_retrieval_no_range(client):
    user_id = random.randint(0, 999999)
    req = random_notification_insert_values(40, user_id)
    notifications.insert(req)

    res = client.get('/notifications/' + str(user_id))
    assert res.status_code == 200
    assert len(res.json["notifications"]) == 20
    assert res.headers['Content-Range'] == '0-20/40'
Exemple #4
0
def test_notifications_retrieval_range_limited(client):
    user_id = random.randint(0, 999999)
    req = random_notification_insert_values(15, user_id)
    notifications.insert(req)

    res = client.get('/notifications/' + str(user_id) + '?range=10_20')
    assert res.status_code == 200
    assert len(res.json["notifications"]) == 5
    assert res.headers['Content-Range'] == '10-15/15'
Exemple #5
0
def test_notifications_retrieval_daterange(client):
    user_id = random.randint(0, 999999)
    req = random_notification_insert_values(30, user_id)
    notifications.insert(req)

    dt = datetime.now()
    dt1 = dt.replace(year=dt.year + 1).date()
    dt2 = dt.replace(year=dt.year - 1).date()
    date_range = dt2.isoformat() + '_' + dt1.isoformat()

    res = client.get('/notifications/' + str(user_id) + '?date-range=' +
                     date_range)
    assert res.status_code == 200
    assert len(res.json["notifications"]) == 30
    assert res.headers['Content-Range'] == '*/30'
def generate_notifications(song: Song):
    print("Starting notification generation for " + str(song))
    t0 = datetime.now()
    user_list = users.list_by_instruments(song.instruments)
    set_instruments = set(song.instruments)
    notification_values = []
    for user in user_list:
        instruments = set(user.instruments).intersection(set_instruments)
        msg = format_message(song.title, instruments)
        notification_values.append((song.id, user.id, msg))
    notifications.insert(notification_values)
    t1 = datetime.now()
    print("Done generating " + str(len(notification_values)) +
          " notifications for " + str(song))
    print("Elapsed: " + str((t1 - t0).total_seconds()))
Exemple #7
0
def new_notification_value():
    from persist import notifications
    value = random_notification_insert_value()
    notifications.insert([value])
    yield value