Example #1
0
def test_delete_shift(client):
    congregation = Congregation.objects().first()
    cong_id = str(congregation.id)
    shift = Shift.objects().first()
    assert len(Shift.objects()) == 1
    shift_id = str(shift.id)
    response = client.delete(f'/congregations/{cong_id}/shifts/{shift_id}')
    assert response.status_code == 200
    assert len(Shift.objects()) == 0
Example #2
0
def test_create_shift(client):
    shift = Shift(
        location="Dam Trail",
        start_time=datetime(2021, 1, 1, 14, 0),
        end_time=datetime(2021, 1, 1, 15, 30),
    )
    assert shift.location == "Dam Trail"
    shift.save()
    assert (Shift.objects().order_by('-id').first()
            .location == "Dam Trail")
Example #3
0
def test_put_shift(client):
    congregation = Congregation.objects().first()
    cong_id = str(congregation.id)
    shift = Shift.objects().first()
    shift_id = str(shift.id)
    response = client.put(f'/congregations/{cong_id}/shifts/{shift_id}',
                          json={"location": "Dam trail"})
    assert response.status_code == 200
    data = response.get_json()
    assert data["location"] == "Dam trail"
Example #4
0
def test_get_shift(client):
    congregation = Congregation.objects().first()
    cong_id = str(congregation.id)
    shift = Shift.objects().first()
    shift_id = str(shift.id)
    response = client.get(f'/congregations/{cong_id}/shifts/{shift_id}')
    assert response.status_code == 200
    # Create a new congregation - should return 401
    # if shift doesn't belong to congregation
    congregation = Congregation(name="sneaky").save()
    cong_id = str(congregation.id)
    response = client.get(f'/congregations/{cong_id}/shifts/{shift_id}')
    assert response.status_code == 401
Example #5
0
def test_request_shift(client):
    congregation = Congregation.objects().first()
    cong_id = str(congregation.id)
    shift = Shift.objects().first()
    shift_id = str(shift.id)
    user = User.objects().first()
    user_id = str(user.id)
    response = client.put(
        f'/congregations/{cong_id}/shifts/{shift_id}'
        '/request',
        json={"userId": user_id})
    assert response.status_code == 200
    data = response.get_json()
    assert len(data["requested_by"]) == 1
Example #6
0
def test_post_shifts(client):
    congregation = Congregation.objects().first()
    cong_id = str(congregation.id)
    payload = {
        "location": "Dam trail",
        "date": "2017-06-01",
        "startTime": "14:00",
        "endTime": "15:30"
    }
    response = client.post(f'/congregations/{cong_id}/shifts/', json=payload)
    assert response.status_code == 200
    # Check that shift is created in db w appropriate associations
    shift = Shift.objects().order_by('-id').first()
    assert shift.location == "Dam trail"
    assert shift.congregation.name == "English - Willimantic"
    # Check that response contains correct shift data
    data = response.get_json()
    assert data["location"] == "Dam trail"
    assert len(data["volunteers"]) == 0
    assert len(data["requested_by"]) == 0
def test_create_shift(client):
    shift = Shift(location="UConn", datetime=datetime.now)
    assert shift.location == "UConn"
    shift.save()
    assert (Shift.objects().order_by('-id').first().location == "UConn")