예제 #1
0
def group_create():
    """Create new group based on post request from network page modal."""
    form = GroupCreateForm()
    code = 200
    if current_user.email_verified and request.method == 'POST':
        if form.validate():
            group = Group.create(
                name=form.name.data, description=form.description.data,
                admin_id=current_user.id
            )
            current_user.add(group)
            flash(
                f"Successfully created {group.name} and added you as member."
            )
            return redirect(url_for('relationship.network_groups'))
        else:
            flash(
                "Group creation failed.  Please correct errors and resubmit."
            )
            code = 422
    elif not current_user.email_verified:
        disableForm(form)
        flash("Create new group disabled. Please verify email to unlock.")
    return render_template("relationship/groupcreate.html", form=form,
                           title="Create Group"), code
예제 #2
0
def create_group():
    request_dict = GroupSchema.validate_request()
    group = Group()
    new_group = group.create(request_dict)
    record = new_group.to_dict()
    return jsonify(record), 201
예제 #3
0
파일: conftest.py 프로젝트: dleister77/Ask
def test_db(app):
    db.drop_all()
    db.create_all()
    # define categories
    State.create(id=1, name="North Carolina", state_short="NC")
    State.create(id=2, name="New York", state_short="NY")
    Sector.create(id=1, name="Home Services")
    Sector.create(id=2, name="Food & Drink")
    c1 = Category.create(id=1, name="Electrician", sector_id=1)
    c2 = Category.create(id=2, name="Plumber", sector_id=1)
    Category.create(id=3, name="Mexican Restaurant", sector_id=2)
    a1 = Address.create(
        line1="13 Brook St", city="Lakewood", zip="14750", state_id=2,
        latitude=42.100201, longitude=-79.340303
    )

    # add test users
    u1 = User.create(
        id=1, username="******", first_name="Sarah", last_name="Smith",
        email="*****@*****.**", address=a1
    )
    u2 = User.create(
        id=2, username="******", first_name="John", last_name="Jones",
        email="*****@*****.**",
        address=Address(
            line1="7708 covey chase Dr", line2='', city="Charlotte",
            zip="28210", state_id=1, latitude=35.123949, longitude=-80.864783
        )
    )
    u3 = User.create(
        id=3, username="******", first_name="Mark", last_name="Johnson",
        email="*****@*****.**",
        address=Address(
            line1="7718 Covey Chase Dr", line2='', city="Charlotte",
            zip="28210", state_id=1, latitude=35.123681, longitude=-80.865045
        )
    )
    User.create(
        id=4, username="******", first_name="Hyman",
        last_name="Rickover", email="*****@*****.**",
        address=Address(
            line1="7920 Covey Chase Dr", line2='', city="Charlotte",
            zip="28210", state_id=1, latitude=35.120759, longitude=-80.865781
        )
    )

    # add test providers
    p1 = Provider.create(
        id=1, name="Douthit Electrical", telephone="704-726-3329",
        email="*****@*****.**",
        website='https://www.douthitelectrical.com/', categories=[c1, c2],
        address=Address(
            line1="6000 Fairview Rd", line2="suite 1200", city="Charlotte",
            zip="28210", state_id=1, latitude=35.150495, longitude=-80.838958
        )
    )
    Provider.create(
        id=2, name="Evers Electric", telephone="7048431910", email='',
        website='http://www.everselectric.com/', categories=[c1],
        address=Address(
            line1="3924 Cassidy Drive", line2="", city="Waxhaw", zip="28173",
            state_id=1, latitude=34.938645, longitude=-80.760691
        )
    )
    p3 = Provider.create(
        id=3, name="Preferred Electric Co", telephone="7043470446",
        email="*****@*****.**", categories=[c1],
        address=Address(
            line1="4113 Yancey Rd", line2='', city="charlotte", zip="28217",
            state_id=1, latitude=35.186947, longitude=-80.880459
        )
    )
    p4 = Provider.create(
        id=4, name="Basic Electric Co", telephone="7044070077",
        email="*****@*****.**", is_active=False, categories=[c1],
        address=Address(
            line1="7708 Covey Chase Dr", line2='', city="Charlotte",
            zip="28217", state_id=1, latitude=35.123949, longitude=-80.865781
        )
    )

    # add test groups
    g1 = Group.create(
        id=1, name="QHIV HOA", description="Hoa for the neighborhood",
        admin_id=2
    )
    Group.create(
        id=2, name="Shannon's Bees",
        description="Insects that like to make honey", admin_id=2
    )
    Group.create(
        id=3, name="Shawshank Redemption Fans", description="test", admin_id=3
    )

    # add test reviews
    Review.create(
        id=1, user=u2, provider=p1, category=c1, rating=3, cost=3,
        description="fixed a light bulb", comments="satisfactory work.",
        pictures=[
            Picture(
                path=os.path.join(
                    app.config['MEDIA_FOLDER'], '2', 'test1.jpg'
                ),
                name='test1.jpg'
            )
        ]
    )
    Review.create(
        id=2, user=u3, provider=p1, category=c1, rating=5, cost=5,
        price_paid="", description="installed breaker box",
        comments="very clean"
    )
    Review.create(
        id=3, user=u1, provider=p1, category=c1, rating=1, cost=5,
        price_paid="", description="test", comments="Test"
    )
    Review.create(
        id=4, user=u2, provider=p3, category=c1, rating=5, cost=2,
        price_paid="", description="test", comments="Test123",
        service_date=date(2019, 5, 1)
    )
    Review.create(
        id=5, user=u2, provider=p3, category=c1, rating=4, cost=3,
        price_paid="", description="moretest", comments="Test123456",
        service_date=date(2019, 5, 1)
    )
    Review.create(
        id=6, user=u1, provider=p1, category=c1, rating=1, cost=5,
        price_paid="", description="yetanothertest", comments="Testing"
    )

    Review.create(
        id=7, user=u2, provider=p4, category=c1, rating=1, cost=1,
        price_paid=100, description="getting electrocuted",
        comments="terrible"
    )

    # add test relationships
    u2.add(u1)
    u2.add(g1)
    u3.add(g1)

    # set user passwords
    u1.set_password("password1234")
    u2.set_password("password")
    u3.set_password("password5678")

    # set starting messages
    Message.send_new(
        dict(user_id=1), dict(user_id=2), "test subject", "test body"
    )
    time.sleep(1)
    Message.send_new(
        dict(user_id=2), dict(full_name="admin"), "test admin subject",
        "test adminbody", msg_type="admin"
    )
    Message.send_new(
        dict(user_id=1), dict(user_id=2), "yet another test subject",
        " yet another test body"
    )

    yield db

    db.session.remove()
    db.drop_all()
예제 #4
0
 def test_newRepeatName(self):
     with pytest.raises(IntegrityError):
         Group.create(name="QHIV HOA", description="test", admin_id=2)