def test_new_organization_no_permissions():
    user, organization, client = setup()
    assert login(client, user)

    assert len(user.get_organizations()) == 0
    response = client.post(
        path=reverse('organizations:new_organization'),
        data={
        },
    )
    assert response.status_code == HTTP_403_FORBIDDEN

    organization = OrganizationFactory()
    organization.add_manage(user)
    assert len(user.get_organizations()) == 1
    response = client.post(
        path=reverse('organizations:new_organization'),
        data={
            'name': 'Test organization',
        },
    )
    assert response.status_code == HTTP_403_FORBIDDEN
    assert len(user.get_organizations()) == 1
def test_transfer_ownership():
    user, organization, project, client = setup()
    project.add_manage(user)
    assert login(client, user)

    # Test that the user does not have permissions yet.
    new_organization = OrganizationFactory()

    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(
        path=reverse('projects:transfer_ownership', args=[project.pk]),
        data={
            'organization': new_organization.pk,
        },
        follow=True
    )
    assert response.status_code == HTTP_200_OK
    project.refresh_from_db()
    assert project.organization.pk != new_organization.pk


    # Test that if the user does not have enough permissions, that things do not work.
    new_organization.add_create(user)
    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(
        path=reverse('projects:transfer_ownership', args=[project.pk]),
        data={
            'organization': new_organization.pk,
        },
        follow=True
    )
    assert response.status_code == HTTP_200_OK

    project.refresh_from_db()
    assert project.organization.pk == organization.pk
    new_organization.delete_create(user)

    # Test that if the user does not have enough permissions, that things do not work.
    new_organization.add_invite(user)
    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(
        path=reverse('projects:transfer_ownership', args=[project.pk]),
        data={
            'organization': new_organization.pk,
        },
        follow=True
    )
    assert response.status_code == HTTP_200_OK

    project.refresh_from_db()
    assert project.organization.pk == organization.pk
    new_organization.delete_invite(user)

    # Now test that they do.
    new_organization.add_manage(user)

    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(
        path=reverse('projects:transfer_ownership', args=[project.pk]),
        data={
            'organization': new_organization.pk,
        },
        follow=True
    )
    assert response.redirect_chain[0][0] == reverse('projects:transfer_ownership', args=[project.pk])
    assert response.redirect_chain[0][1] == HTTP_302_FOUND

    project.refresh_from_db()
    assert project.organization.pk == new_organization.pk
Example #3
0
def test_transfer_ownership():
    user, organization, project, client = setup()
    project.add_manage(user)
    assert login(client, user)

    # Test that the user does not have permissions yet.
    new_organization = OrganizationFactory()

    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(path=reverse('projects:transfer_ownership',
                                        args=[project.pk]),
                           data={
                               'organization': new_organization.pk,
                           },
                           follow=True)
    assert response.status_code == HTTP_200_OK
    project.refresh_from_db()
    assert project.organization.pk != new_organization.pk

    # Test that if the user does not have enough permissions, that things do not work.
    new_organization.add_create(user)
    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(path=reverse('projects:transfer_ownership',
                                        args=[project.pk]),
                           data={
                               'organization': new_organization.pk,
                           },
                           follow=True)
    assert response.status_code == HTTP_200_OK

    project.refresh_from_db()
    assert project.organization.pk == organization.pk
    new_organization.delete_create(user)

    # Test that if the user does not have enough permissions, that things do not work.
    new_organization.add_invite(user)
    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(path=reverse('projects:transfer_ownership',
                                        args=[project.pk]),
                           data={
                               'organization': new_organization.pk,
                           },
                           follow=True)
    assert response.status_code == HTTP_200_OK

    project.refresh_from_db()
    assert project.organization.pk == organization.pk
    new_organization.delete_invite(user)

    # Now test that they do.
    new_organization.add_manage(user)

    # Valid case
    assert project.organization.pk == organization.pk
    response = client.post(path=reverse('projects:transfer_ownership',
                                        args=[project.pk]),
                           data={
                               'organization': new_organization.pk,
                           },
                           follow=True)
    assert response.redirect_chain[0][0] == reverse(
        'projects:transfer_ownership', args=[project.pk])
    assert response.redirect_chain[0][1] == HTTP_302_FOUND

    project.refresh_from_db()
    assert project.organization.pk == new_organization.pk