Exemple #1
0
def test_get_users_organizations_200(client, user, user_auth_token):
    """/users/:user_uuid/organizations HTTP 200"""

    organization = create_organization("test org", user)
    organization_two = create_organization("test org2", user)
    organization_three = create_organization("test org3", user)

    # create the test org as an admin
    response = client.get(
        f"/users/{user.uuid}/organizations",
        headers={
            "Content-Type": "application/json",
            "Authorization": user_auth_token,
        },
    )
    assert response.status_code == 200
    assert len(response.json) == 3
    assert response.json[0]["name"] == organization.name
    assert response.json[1]["name"] == organization_two.name
    assert response.json[2]["name"] == organization_three.name

    delete_organization(organization)
    response = client.get(
        f"/users/{user.uuid}/organizations",
        headers={
            "Content-Type": "application/json",
            "Authorization": user_auth_token,
        },
    )
    assert response.status_code == 200
    assert len(response.json) == 2
Exemple #2
0
def test_reject_organization_invitation(client, user):
    organization = create_organization("New Org")
    invitation = create_invitation(organization, user.email)

    result = client.post(
        f"/organizations/invitations/reject",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_token": "incorrecttoken"},
    )
    assert result.status_code == 400

    result = client.post(
        f"/organizations/invitations/reject",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_token": invitation.invitation_token},
    )
    assert result.status_code == 200

    result = client.post(
        f"/organizations/invitations/accept",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_token": invitation.invitation_token},
    )
    assert result.status_code == 400

    assert not user in [om.user for om in user.organization_memberships]
Exemple #3
0
def create_organization(c, name, email):
    """ Create an organization for a user with 'email'. Returns the UUID of the organization. """
    from app import create_app, models, services, queries

    (app, db, _) = create_app()
    with app.app_context():
        user = queries.find_user_by_email(email)
        organization = services.create_organization(name, user)
        models.db.session.commit()
        print(organization.uuid)
Exemple #4
0
def test_remove_organization_member_200(client, user, organization_admin,
                                        organization_admin_auth_token):
    organization = create_organization("test org", organization_admin)
    invitation = create_invitation(organization, user.email)
    accept_invitation(invitation.invitation_token)

    response = client.delete(
        f"/organizations/{organization.uuid}"
        f"/members/{user.uuid}",
        headers={
            "Content-Type": "application/json",
            "Authorization": organization_admin_auth_token,
        },
    )

    assert response.status_code == 200
    members = queries.find_organization_members(organization)
    assert user not in [om.user for om in members]
Exemple #5
0
def test_cancel_organization_invitation(client, user, admin, admin_auth_token):
    organization = create_organization("New Org", admin)
    invitation = create_invitation(organization, user.email)

    result = client.post(
        f"/organizations/invitations/cancel",
        headers={
            "Content-Type": "application/json",
            "Authorization": admin_auth_token,
        },
        json={"invitation_uuid": "incorrectuuid"},
    )
    assert result.status_code == 400

    result = client.post(
        f"/organizations/invitations/cancel",
        headers={
            "Content-Type": "application/json",
            "Authorization": "invalidbearertoken",
        },
        json={"invitation_uuid": invitation.uuid},
    )
    assert result.status_code == 401

    result = client.post(
        f"/organizations/invitations/cancel",
        headers={
            "Content-Type": "application/json",
            "Authorization": admin_auth_token,
        },
        json={"invitation_uuid": invitation.uuid},
    )
    assert result.status_code == 200

    result = client.post(
        f"/organizations/invitations/accept",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_uuid": invitation.uuid},
    )
    assert result.status_code == 400

    assert not user in [om.user for om in user.organization_memberships]
Exemple #6
0
def test_list_organization_invitaions_200(client, user, organization,
                                          organization_admin,
                                          organization_admin_auth_token):
    invitation = create_invitation(organization, user.email)
    org2 = create_organization("org2", organization_admin)
    invitation2 = create_invitation(org2, user.email)

    result = client.get(
        f"/organizations/{organization.uuid}/invitations",
        headers={
            "Content-Type": "application/json",
            "Authorization": organization_admin_auth_token,
        },
    )

    assert result.status_code == 200
    assert (len(
        list(filter(lambda i: i["email_address"] == user.email,
                    result.json))) == 1)
    assert user.email in [i["email_address"] for i in result.json]
Exemple #7
0
def test_remove_organization_member(organization, user, admin):
    organization.organization_members.append(
        OrganizationMember(
            user=user,
            organization=organization,
            organization_role=find_organization_role(ROLE_USER_CODE),
        ))
    organization_two = services.create_organization("test two")
    organization_two.organization_members.append(
        OrganizationMember(
            user=user,
            organization=organization_two,
            organization_role=find_organization_role(ROLE_USER_CODE),
        ))
    db.session.commit()

    assert user in [om.user for om in organization.organization_members]

    services.remove_organization_member(organization, user)

    members = find_organization_members(organization)
    assert user not in [om.user for om in members]
Exemple #8
0
def test_accept_organization_invitation(client, user):
    organization = create_organization("New Org")
    invitation = create_invitation(organization, user.email)

    result = client.post(
        f"/organizations/invitations/accept",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_token": "incorrecttoken"},
    )
    assert result.status_code == 400

    result = client.post(
        f"/organizations/invitations/accept",
        headers={
            "Content-Type": "application/json",
        },
        json={"invitation_token": invitation.invitation_token},
    )
    # admin is already in organization invited to
    assert result.json["organization_uuid"] == organization.uuid
    assert result.status_code == 200
    assert user in [om.user for om in user.organization_memberships]