Beispiel #1
0
def check_group_exists(group_id):
    group = get_group_by_id(group_id)

    if group is None:
        abort(401, "Group does not exist")

    return group
def test_add_not_registered_user_to_group_if_user_already_created(
        test_client, api_headers_bearer, insert_tokens):
    password = "******"

    user1 = User(first_name="Max",
                 last_name="Muster",
                 email="*****@*****.**",
                 password=password)
    user1 = insert_user(user1)
    user1_tokens = insert_tokens(user1.email)

    new_user_email = "*****@*****.**"
    insert_user(User(email=new_user_email))

    group_member1 = GroupMember(user=user1)
    group = Group(name="Muster", group_members=[group_member1])
    insert_group(group)

    group_add_user_data = {"email": new_user_email}

    response = test_client.post("/groups/{}/members".format(group.id),
                                headers=api_headers_bearer(
                                    user1_tokens["access_token"]["token"]),
                                data=json.dumps(group_add_user_data))
    json_response = json.loads(response.get_data(as_text=True))

    assert response.status_code == 201
    assert json_response["message"] == "Added user to group"

    group = get_group_by_id(group.id)

    assert len(group.group_members) == 2
Beispiel #3
0
def _create_new_bill(data):
    bill = Bill(description=data["description"],
                date=data.get("date", None),
                date_created=data.get("date_created", None))

    for member in data["members"]:
        user = get_user_by_id(member["user_id"])
        bill_member = BillMember(user=user,
                                 bill=bill,
                                 amount=member["amount"])
        bill.members.append(bill_member)

    if "group_id" in data:
        bill.group = get_group_by_id(data["group_id"])

    insert_bill(bill)

    return bill
Beispiel #4
0
def test_create_group_with_not_registered_group_member_that_was_already_created(test_client, api_headers_bearer, insert_tokens):
    password = "******"

    user = User(first_name="Max",
                last_name="Muster",
                email="*****@*****.**",
                password=password)
    user = insert_user(user)
    tokens = insert_tokens(user.email)

    new_user_email = "*****@*****.**"
    insert_user(User(email=new_user_email))

    group_data = {
        "name": "Muster",
        "members": [
            {
                "id": user.id,
            },
            {
                "email": new_user_email
            }
        ]
    }

    response = test_client.post("/groups",
                                headers=api_headers_bearer(
                                    tokens["access_token"]["token"]),
                                data=json.dumps(group_data))
    json_response = json.loads(response.get_data(as_text=True))

    assert response.status_code == 201

    assert json_response["message"] == "Created new group"
    assert json_response["group"]["id"] == 1
    assert json_response["group"]["name"] == group_data["name"]
    assert json_response["group"]["valid"] is True

    group = get_group_by_id(json_response["group"]["id"])

    assert group is not None
    assert len(group.group_members) == 2