Beispiel #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
Beispiel #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")
Beispiel #3
0
def app():
    db = MongoEngine()
    crypt = Bcrypt()
    mongo = PyMongo()
    mail = Mail()

    login_manager = LoginManager()
    login_manager.login_view = None
    login_manager.login_message_category = 'info'

    app = create_app({
        "SECRET_KEY": 'testsecret',
        "SECURITY_PASSWORD_SALT": 'testsalt',
        "SECURITY_CSRF_COOKIE": {
            "key": "XSRF-TOKEN"
        },
        "SECURITY_CSRF_IGNORE_UNAUTH_ENDPOINTS": True,
        "WTF_CSRF_TIME_LIMIT": None,
        "WTF_CSRF_CHECK_DEFAULT": False,
        "MONGODB_SETTINGS": {
            'host': 'mongodb://localhost/pwsched-test'
        },
        "MONGO_URI": 'mongodb://localhost/pwsched-test',
        "TESTING": True
    })

    db.init_app(app)
    crypt.init_app(app)
    login_manager.init_app(app)
    mongo.init_app(app)
    mail.init_app(app)

    Shift.drop_collection()
    Congregation.drop_collection()
    User.drop_collection()

    congregation = Congregation(name="English - Willimantic").save()
    shift = Shift(location="UConn",
                  start_time=datetime(2021, 1, 1, 14, 0),
                  end_time=datetime(2021, 1, 1, 15, 30),
                  congregation=congregation.to_dbref()).save()
    hashed_password = crypt.generate_password_hash('password').decode('utf-8')
    User(
        name="Brother Service Overseer",
        email="*****@*****.**",
        password=hashed_password,
        congregation=(
            Congregation.objects().order_by('-id').first().to_dbref())).save()

    yield app

    Shift.drop_collection()
    Congregation.drop_collection()
    User.drop_collection()
Beispiel #4
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"
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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")