Exemple #1
0
def test_oauth_insert_oauth_same_user(db_session):
    with pytest.raises(IntegrityError):
        test_user = UserFactory()
        test_oauth = OAuthFactory.create()
        test_oauth.user = test_user
        db_session.commit()
        test_oauth_2 = OAuthFactory.create(provider_user_id="1")
        test_oauth_2.user = test_user
        db_session.commit()
Exemple #2
0
def test_user_insert_same_uuid(db_session):
    test_uuid = uuid4()

    with pytest.raises(IntegrityError):
        test_user = UserFactory()
        test_oauth = OAuthFactory.create(uuid=test_uuid)
        test_oauth.user = test_user
        db_session.commit()
        test_user_2 = UserFactory()
        test_oauth_2 = OAuthFactory.create(uuid=test_uuid)
        test_oauth_2.user = test_user_2
        db_session.commit()
Exemple #3
0
def test_user_service_get_create_oauth(service, db_perm_session):
    assert len(service.db_session.query(User).all()) == 0
    assert len(service.db_session.query(OAuth).all()) == 0

    obj = service.get_create_oauth(provider="google",
                                   provider_user_id="test",
                                   token={})

    assert obj.provider_user_id == "test"
    assert obj.user is None

    test_user = UserFactory.create()
    obj = OAuthFactory.create()
    obj.user = test_user
    db_perm_session.commit()

    assert len(service.db_session.query(User).all()) == 1
    assert len(service.db_session.query(OAuth).all()) == 1

    obj = service.get_create_oauth(
        provider=test_user.oauth.provider,
        provider_user_id=test_user.oauth.provider_user_id,
        token={})

    assert obj.id == test_user.oauth.id
    assert obj.uuid == test_user.oauth.uuid
    assert obj.user == test_user
Exemple #4
0
def test_user_insert_oauth(db_session):
    user = UserFactory.create()
    oauth = OAuthFactory.create()
    oauth.user = user
    db_session.commit()

    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()
    assert db_session.query(User).filter(User.oauth == oauth).one()
Exemple #5
0
def test_user_delete(db_session):
    obj = UserFactory.create()
    obj.oauth = OAuthFactory.create()
    db_session.commit()

    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()

    result = db_session.query(User).filter(User.id == obj.id).delete()
    assert result == 1
    db_session.commit()

    assert db_session.query(User).one_or_none() is None
    assert db_session.query(OAuth).one_or_none() is None
Exemple #6
0
def test_user_update_oauth(db_session):
    user = UserFactory.create()
    db_session.commit()
    assert db_session.query(User).one()
    assert db_session.query(OAuth).one_or_none() is None

    oauth = OAuthFactory.create()
    oauth.user = user
    db_session.commit()
    assert db_session.query(User).one()
    assert db_session.query(OAuth).one()
    assert db_session.query(User).filter(User.oauth == oauth).one()

    result = db_session.query(OAuth).filter(OAuth.id == oauth.id).delete()
    db_session.commit()
    assert result == 1
    assert db_session.query(User).one()
    assert db_session.query(User).one().oauth is None
    assert db_session.query(OAuth).one_or_none() is None
Exemple #7
0
def test_user_single_parent_constraint(db_session):
    obj = UserFactory.create()
    obj2 = UserFactory.create()

    assert obj.oauth is None
    assert obj2.oauth is None

    test_oauth = OAuthFactory.create()
    obj.oauth = test_oauth
    db_session.commit()

    assert obj.oauth is not None
    assert obj2.oauth is None

    res = obj.oauth
    obj2.oauth = res
    db_session.commit()

    assert obj.oauth is None
    assert obj2.oauth is not None
    assert obj2.oauth == res
Exemple #8
0
def test_oauth_insert_without_user(db_session):
    with pytest.raises(IntegrityError):
        OAuthFactory.create()
        db_session.commit()