Exemplo n.º 1
0
def test_dashboard_project_invite(client, project):
    url = reverse('dashboard-project-invite', kwargs={
        'organisation_slug': project.organisation.slug,
        'slug': project.slug,
    })

    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    initiator = project.organisation.initiators.first()
    client.login(username=initiator.email, password='******')
    response = client.get(url)
    assert response.status_code == 200

    response = client.post(url, {
        'emails': 'Jimmy Hendrix <*****@*****.**>, [email protected]'
    })
    assert redirect_target(response) == 'dashboard-project-users'
    assert len(project.invite_set.all()) == 2
    assert project.invite_set.all()[0].email == '*****@*****.**'
    assert project.invite_set.all()[1].email == '*****@*****.**'
    assert len(mail.outbox) == 2

    response = client.post(url, {
        'emails': '*****@*****.**'
    })

    errors = response.context_data['form']['emails'].errors
    assert errors == ['[email protected] already invited']
Exemplo n.º 2
0
def test_dashboard_project_invite(client, project):
    url = reverse('dashboard-project-invite',
                  kwargs={
                      'project_slug': project.slug,
                  })

    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    initiator = project.organisation.initiators.first()
    client.login(username=initiator.email, password='******')
    response = client.get(url)
    assert response.status_code == 200

    response = client.post(url, {'emails': '[email protected], [email protected]'})
    assert redirect_target(response) == 'dashboard-project-users'
    assert len(project.invite_set.all()) == 2
    assert project.invite_set.all()[0].email == '*****@*****.**'
    assert project.invite_set.all()[1].email == '*****@*****.**'
    assert len(mail.outbox) == 2

    response = client.post(url, {'emails': '*****@*****.**'})

    errors = response.context_data['form']['emails'].errors
    assert errors == ['[email protected] already invited']
Exemplo n.º 3
0
def test_paragraph_private_detail_view(client, paragraph_factory, user):
    paragraph = paragraph_factory(document__module__project__is_public=False)

    url = reverse('paragraph-detail', kwargs={'pk': paragraph.pk})

    response = client.get(url)
    redirect_target(response) == 'login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    response.status_code = 403

    paragraph.project.participants.add(user)
    response = client.get(url)
    response.status_code = 200
Exemplo n.º 4
0
def test_detail_private_project(client, project, user):
    project_url = reverse('project-detail', args=[project.slug])
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'memberships-request'

    project.participants.add(user)
    response = client.get(project_url)
    assert response.status_code == 200
    assert response.context_data['view'].project == project
Exemplo n.º 5
0
def test_detail_private_project(client, project, user):
    project_url = reverse('project-detail', args=[project.slug])
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'memberships-request'

    project.participants.add(user)
    response = client.get(project_url)
    assert response.status_code == 200
    assert response.context_data['view'].project == project
Exemplo n.º 6
0
def test_detail_view_private(client, idea, user):
    idea.module.project.is_public = False
    idea.module.project.save()
    url = reverse('idea-detail', kwargs={'slug': idea.slug})
    response = client.get(url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    idea.module.project.participants.add(user)
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200

    user = idea.project.moderators.first()
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200

    user = idea.project.organisation.initiators.first()
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200
Exemplo n.º 7
0
def test_detail_view_private(client, idea, user):
    idea.module.project.is_public = False
    idea.module.project.save()
    url = reverse('idea-detail', kwargs={'slug': idea.slug})
    response = client.get(url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    idea.module.project.participants.add(user)
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200

    user = idea.project.moderators.first()
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200

    user = idea.project.organisation.initiators.first()
    client.login(username=user.email,
                 password='******')
    response = client.get(url)
    assert response.status_code == 200
Exemplo n.º 8
0
def test_register_with_next(client, signup_url):
    assert EmailAddress.objects.count() == 0
    email = '*****@*****.**'
    response = client.post(
        signup_url, {
            'username': '******',
            'email': email,
            'password1': 'password',
            'password2': 'password',
            'terms_of_use': 'on',
            'next': '/en/projects/pppp/',
        }
    )
    assert response.status_code == 302
    assert EmailAddress.objects.filter(
        email=email, verified=False
    ).count() == 1
    assert len(mail.outbox) == 1
    confirmation_url = re.search(
        r'(http://testserver/.*/?next=/en/projects/pppp/)',
        str(mail.outbox[0].body)
    ).group(0)
    confirm_email_response = client.get(confirmation_url)
    assert confirm_email_response.status_code == 200
    assert EmailAddress.objects.filter(
        email=email, verified=False
    ).count() == 1
    confirm_email_response = client.post(confirmation_url)
    assert confirm_email_response.status_code == 302
    assert redirect_target(confirm_email_response) == "project-detail"
    assert EmailAddress.objects.filter(
        email=email, verified=True
    ).count() == 1
Exemplo n.º 9
0
def test_initiator_create_flashpoll_project(client, organisation):
    user = organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-create', kwargs={
        'organisation_slug': organisation.slug,
        'blueprint_slug': 'flashpoll'
    })
    response = client.get(url)
    assert response.status_code == 200

    response = client.post(url, {
        'phases-TOTAL_FORMS': '2',
        'phases-INITIAL_FORMS': '0',
        'phases-0-id': '',
        'phases-0-start_date': '2016-10-01 16:12',
        'phases-0-end_date': '2016-10-01 16:13',
        'phases-0-name': 'Name 0',
        'phases-0-description': 'Description 0',
        'phases-1-id': '',
        'phases-1-start_date': '2016-10-01 16:14',
        'phases-1-end_date': '2016-10-01 16:15',
        'phases-1-name': 'Name 1',
        'phases-1-description': 'Description 1',
        'project-description': 'Project description',
        'project-name': 'Project name Flashpoll',
        'project-information': 'Project info',
        'save_draft': '',
        'module_settings-key': '32a34235ba14df2de',
    })
    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    project = organisation.project_set.first()
    assert project.is_draft
    assert project.name == 'Project name Flashpoll'
    assert len(project.module_set.first().phase_set.all()) == 1
Exemplo n.º 10
0
def test_detail_draft_project(client, project, user):
    project_url = reverse('project-detail', args=[project.slug])
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(project_url)
    assert response.status_code == 403
    assert (
        'euth_projects/project_membership_request.html'
        not in templates_used(response)
    )

    project.participants.add(user)
    response = client.get(project_url)
    assert response.status_code == 403
    assert (
        'euth_projects/project_membership_request.html'
        not in templates_used(response)
    )

    project.organisation.initiators.add(user)
    response = client.get(project_url)
    assert response.status_code == 200
    assert response.context_data['view'].project == project
Exemplo n.º 11
0
def test_detail_draft_project(client, project, user):
    project_url = reverse('project-detail', args=[project.slug])
    response = client.get(project_url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(project_url)
    assert response.status_code == 403
    assert (
        'euth_projects/project_membership_request.html'
        not in templates_used(response)
    )

    project.participants.add(user)
    response = client.get(project_url)
    assert response.status_code == 403
    assert (
        'euth_projects/project_membership_request.html'
        not in templates_used(response)
    )

    project.organisation.initiators.add(user)
    response = client.get(project_url)
    assert response.status_code == 200
    assert response.context_data['view'].project == project
Exemplo n.º 12
0
def test_paragraph_private_detail_view(client, paragraph_factory, user):
    paragraph = paragraph_factory(document__module__project__is_public=False)

    url = reverse('paragraph-detail', kwargs={
        'pk': paragraph.pk
    })

    response = client.get(url)
    redirect_target(response) == 'login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    response.status_code = 403

    paragraph.project.participants.add(user)
    response = client.get(url)
    response.status_code = 200
Exemplo n.º 13
0
def test_create_view(client, phase, user):
    module = phase.module
    with freeze_time(phase.start_date):
        count = models.Idea.objects.all().count()
        assert count == 0
        url = reverse('idea-create', kwargs={'slug': module.slug})
        response = client.get(url)
        assert response.status_code == 302
        assert redirect_target(response) == 'account_login'
        client.login(username=user.email, password='******')
        response = client.get(url)
        assert response.status_code == 200
        idea = {'name': 'Idea', 'description': 'description'}
        response = client.post(url, idea)
        assert response.status_code == 302
        assert redirect_target(response) == 'idea-detail'
        count = models.Idea.objects.all().count()
        assert count == 1
Exemplo n.º 14
0
def test_create_view(client, phase, user):
    module = phase.module
    with freeze_time(phase.start_date):
        count = models.Idea.objects.all().count()
        assert count == 0
        url = reverse('idea-create', kwargs={'slug': module.slug})
        response = client.get(url)
        assert response.status_code == 302
        assert redirect_target(response) == 'account_login'
        client.login(username=user.email, password='******')
        response = client.get(url)
        assert response.status_code == 200
        idea = {'name': 'Idea', 'description': 'description'}
        response = client.post(url, idea)
        assert response.status_code == 302
        assert redirect_target(response) == 'idea-detail'
        count = models.Idea.objects.all().count()
        assert count == 1
Exemplo n.º 15
0
def test_accept_invite(client, invite, user):
    url = reverse('membership-invite-update',
                  kwargs={'invite_token': invite.token})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert (
        'euth_projects/includes/project_hero_unit.html'
        in templates_used(response)
    )
    assert 'euth_memberships/invite_form.html' in templates_used(response)

    response = client.post(url, data={'accept': ''})
    assert redirect_target(response) == 'project-detail'
    assert user in invite.project.participants.all()
Exemplo n.º 16
0
def test_project_delete(client, project):
    user = project.organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-delete',
                  kwargs={'project_slug': project.slug})
    response = client.post(url, {})
    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    assert mail.outbox[0].to == [project.organisation.initiators.first().email]
Exemplo n.º 17
0
def test_accept_invite(client, invite, user):
    url = reverse('membership-invite-accept',
                  kwargs={'invite_token': invite.token})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert (
        'euth_projects/includes/project_hero_unit.html'
        in templates_used(response)
    )
    assert 'euth_memberships/invite_form.html' in templates_used(response)

    response = client.post(url, data={'accept': ''})
    assert redirect_target(response) == 'project-detail'
    assert user in invite.project.participants.all()
Exemplo n.º 18
0
def test_project_delete(client, project):
    user = project.organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-delete', kwargs={
        'organisation_slug': project.organisation.slug,
        'slug': project.slug
    })
    response = client.post(url, {})
    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    assert mail.outbox[0].to == [project.organisation.initiators.first().email]
Exemplo n.º 19
0
def test_dashboard_blueprint(client, organisation):
    from euth.blueprints.blueprints import blueprints
    url = reverse('dashboard-blueprint-list',
                  kwargs={'organisation_slug': organisation.slug})
    user = organisation.initiators.first()
    response = client.get(url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'
    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert response.context_data['view'].blueprints == blueprints
Exemplo n.º 20
0
def running_project(organisation, client):
    user = organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-create',
                  kwargs={
                      'organisation_slug': organisation.slug,
                      'blueprint_slug': 'brainstorming'
                  })
    response = client.get(url)
    assert response.status_code == 200

    # Create project
    response = client.post(
        url, {
            'phases-TOTAL_FORMS': '2',
            'phases-INITIAL_FORMS': '0',
            'phases-0-id': '',
            'phases-0-start_date': '2016-10-01 16:12',
            'phases-0-end_date': '2016-10-01 16:13',
            'phases-0-name': 'Name 0',
            'phases-0-description': 'Description 0',
            'phases-0-type': 'euth_offlinephases:000:offline',
            'phases-0-weight': '0',
            'phases-0-delete': '0',
            'phases-1-id': '',
            'phases-1-start_date': '2016-10-01 16:14',
            'phases-1-end_date': '2099-10-01 16:15',
            'phases-1-name': 'Name 1',
            'phases-1-description': 'Description 1',
            'phases-1-type': 'euth_ideas:020:collect',
            'phases-1-weight': '1',
            'phases-1-delete': '0',
            'project-description': 'Project description',
            'project-name': 'Project name',
            'project-information': 'Project info',
            'categories-TOTAL_FORMS': '2',
            'categories-INITIAL_FORMS': '0',
            'categories-MIN_NUM_FORMS': '0',
            'categories-MAX_NUM_FORMS': '1000',
            'categories-0-name': 'foo',
            'categories-0-id': '',
            'categories-1-name': 'bar',
            'categories-1-id': '',
        })
    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    project = organisation.project_set.first()
    assert not project.is_archived
    assert project.name == 'Project name'
    assert list(project.moderators.all()) == [user]
    assert len(project.module_set.first().phase_set.all()) == 2
    return project
Exemplo n.º 21
0
def test_create_request(client, project, user):
    url = reverse('memberships-request', kwargs={'project_slug': project.slug})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert (
        'euth_projects/includes/project_hero_unit.html'
        in templates_used(response)
    )
    assert 'euth_memberships/request_detail.html' in templates_used(response)

    response = client.post(url, data={})
    assert redirect_target(response) == 'memberships-request'
    assert bool(models.Request.objects.filter(creator=user, project=project))
    assert mail.outbox[0].to == [project.moderators.first().email]

    project.participants.add(user)
    response = client.get(url)
    assert redirect_target(response) == 'project-detail'
Exemplo n.º 22
0
def test_create_request(client, project, user):
    url = reverse('memberships-request', kwargs={'project_slug': project.slug})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert (
        'euth_projects/includes/project_hero_unit.html'
        in templates_used(response)
    )
    assert 'euth_memberships/request_detail.html' in templates_used(response)

    response = client.post(url, data={})
    assert redirect_target(response) == 'memberships-request'
    assert bool(models.Request.objects.filter(creator=user, project=project))
    assert mail.outbox[0].to == [project.moderators.first().email]

    project.participants.add(user)
    response = client.get(url)
    assert redirect_target(response) == 'project-detail'
Exemplo n.º 23
0
def test_dashboard_blueprint(client, organisation):
    from euth.dashboard.blueprints import blueprints
    url = reverse('dashboard-blueprint-list', kwargs={
        'organisation_slug': organisation.slug
    })
    user = organisation.initiators.first()
    response = client.get(url)
    assert response.status_code == 302
    assert redirect_target(response) == 'account_login'
    client.login(username=user.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    assert response.context_data['view'].blueprints == blueprints
Exemplo n.º 24
0
def test_view_invite(client, invite, user):
    url = reverse('membership-invite-detail',
                  kwargs={'invite_token': invite.token})
    response = client.get(url)
    assert response.status_code == 200
    assert (
        'euth_projects/includes/project_hero_unit.html'
        in templates_used(response)
    )
    assert 'euth_memberships/invite_detail.html' in templates_used(response)

    client.login(username=user.email, password='******')
    response = client.get(url)
    assert redirect_target(response) == 'membership-invite-update'
Exemplo n.º 25
0
def test_initiator_create_and_update_project(client, organisation):
    user = organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-create',
                  kwargs={
                      'organisation_slug': organisation.slug,
                      'blueprint_slug': 'brainstorming'
                  })
    response = client.get(url)
    assert response.status_code == 200

    response = client.post(
        url, {
            'phases-TOTAL_FORMS': '2',
            'phases-INITIAL_FORMS': '0',
            'phases-0-id': '',
            'phases-0-start_date': '2016-10-01 16:12',
            'phases-0-end_date': '2016-10-01 16:13',
            'phases-0-name': 'Name 0',
            'phases-0-description': 'Description 0',
            'phases-0-type': 'euth_offlinephases:000:offline',
            'phases-0-weight': '0',
            'phases-0-delete': '0',
            'phases-1-id': '',
            'phases-1-start_date': '2016-10-01 16:14',
            'phases-1-end_date': '2016-10-01 16:15',
            'phases-1-name': 'Name 1',
            'phases-1-description': 'Description 1',
            'phases-1-type': 'euth_ideas:020:collect',
            'phases-1-weight': '1',
            'phases-1-delete': '0',
            'project-description': 'Project description',
            'project-name': 'Project name',
            'project-information': 'Project info',
            'categories-TOTAL_FORMS': '2',
            'categories-INITIAL_FORMS': '0',
            'categories-MIN_NUM_FORMS': '0',
            'categories-MAX_NUM_FORMS': '1000',
            'categories-0-name': 'foo',
            'categories-0-id': '',
            'categories-1-name': 'bar',
            'categories-1-id': '',
            'save_draft': ''
        })
    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    project = organisation.project_set.first()
    assert project.is_draft
    assert project.name == 'Project name'
    assert list(project.moderators.all()) == [user]
    assert len(project.module_set.first().phase_set.all()) == 2

    update_url = reverse('dashboard-project-edit',
                         kwargs={'project_slug': project.slug})

    module = project.module_set.first()

    phase_1 = module.phase_set.first().pk
    phase_2 = module.phase_set.all()[1].pk

    cat_0 = module.category_set.first().pk
    cat_1 = module.category_set.all()[1].pk

    response = client.post(
        update_url, {
            'phases-TOTAL_FORMS': '2',
            'phases-INITIAL_FORMS': '0',
            'phases-0-id': str(phase_1),
            'phases-0-start_date': '2016-10-01 16:12',
            'phases-0-end_date': '2016-10-01 16:13',
            'phases-0-name': 'Name 0',
            'phases-0-description': 'Description 0',
            'phases-0-type': 'euth_offlinephases:000:offline',
            'phases-0-weight': '0',
            'phases-0-delete': '1',
            'phases-1-id': str(phase_2),
            'phases-1-start_date': '2016-10-01 16:14',
            'phases-1-end_date': '2016-10-01 16:15',
            'phases-1-name': 'Name 1',
            'phases-1-description': 'Description 1',
            'phases-1-type': 'euth_maps:020:collect',
            'phases-1-weight': '1',
            'phases-1-delete': '0',
            'project-description': 'Project description',
            'project-name': 'Project name',
            'project-information': 'Project info',
            'categories-TOTAL_FORMS': '2',
            'categories-INITIAL_FORMS': '2',
            'categories-MIN_NUM_FORMS': '0',
            'categories-MAX_NUM_FORMS': '1000',
            'categories-0-name': 'foo',
            'categories-0-id': str(cat_0),
            'categories-1-name': 'bar',
            'categories-1-id': str(cat_1),
            'save_draft': ''
        })
    assert response.status_code == 302
    assert len(project.module_set.first().phase_set.all()) == 1
Exemplo n.º 26
0
def test_dashboard_project_users(client, project, user_factory,
                                 request_factory, invite_factory):
    url = reverse('dashboard-project-users',
                  kwargs={
                      'project_slug': project.slug,
                  })
    request0 = request_factory(project=project)
    request1 = request_factory(project=project)
    request2 = request_factory(project=project)
    invite0 = invite_factory(project=project)
    invite1 = invite_factory(project=project)
    user0 = user_factory(email='*****@*****.**')
    user1 = user_factory(email='*****@*****.**')
    project.participants.add(user0)
    project.participants.add(user1)

    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    initiator = project.organisation.initiators.first()
    client.login(username=initiator.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    multiform = response.context['form']
    assert len(multiform['requests'].forms) == 3
    assert multiform['requests'].forms[0].instance == request0
    assert multiform['requests'].forms[1].instance == request1
    assert multiform['requests'].forms[2].instance == request2
    assert multiform['requests'].extra == 0
    assert len(multiform['invites'].forms) == 2
    assert multiform['invites'].forms[0].instance == invite0
    assert multiform['invites'].forms[1].instance == invite1
    assert len(multiform['users'].forms) == 2
    assert multiform['users'].forms[0].instance == user0
    assert multiform['users'].forms[1].instance == user1

    response = client.post(
        url, {
            'requests-0-id': request0.pk,
            'requests-0-action': 'accept',
            'requests-1-id': request1.pk,
            'requests-1-action': 'decline',
            'requests-2-id': request2.pk,
            'requests-2-action': '',
            'requests-TOTAL_FORMS': '3',
            'requests-INITIAL_FORMS': '3',
            'requests-MAX_NUM_FORMS': '',
            'invites-TOTAL_FORMS': '2',
            'invites-INITIAL_FORMS': '2',
            'invites-MAX_NUM_FORMS': '',
            'invites-0-id': invite0.pk,
            'invites-0-delete': 'on',
            'invites-1-id': invite1.pk,
            'users-TOTAL_FORMS': '2',
            'users-INITIAL_FORMS': '2',
            'users-MAX_NUM_FORMS': '',
            'users-0-id': user0.id,
            'users-0-delete': 'on',
            'users-1-id': user1.id,
            'users-1-delete': '',
        })
    assert redirect_target(response) == 'dashboard-project-users'
    assert len(project.request_set.all()) == 1
    assert project.request_set.first() == request2
    assert len(project.invite_set.all()) == 1
    assert project.invite_set.first() == invite1
    assert len(project.participants.all()) == 2
    assert not project.participants.filter(username=user0.username).exists()
    assert User.objects.filter(username=user0.username).exists()
Exemplo n.º 27
0
def test_authenticated_user_can_upload_avatar(client, user, login_url):
    url = reverse('dashboard-profile')
    client.post(login_url, {'email': user.email, 'password': '******'})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'
Exemplo n.º 28
0
def test_initiator_create_flashpoll_project(client, organisation):
    user = organisation.initiators.first()
    client.login(username=user.email, password='******')
    url = reverse('dashboard-project-create',
                  kwargs={
                      'organisation_slug': organisation.slug,
                      'blueprint_slug': 'flashpoll'
                  })
    response = client.get(url)
    assert response.status_code == 200

    response = client.post(
        url, {
            'phases-TOTAL_FORMS':
            '2',
            'phases-INITIAL_FORMS':
            '0',
            'phases-0-id':
            '',
            'phases-0-start_date':
            '2016-10-01 16:12',
            'phases-0-end_date':
            '2016-10-01 16:13',
            'phases-0-name':
            'Name 0',
            'phases-0-description':
            'Description 0',
            'phases-0-type':
            'euth_offlinephases:000:offline',
            'phases-0-weight':
            '0',
            'phases-0-delete':
            '0',
            'phases-1-id':
            '',
            'phases-1-start_date':
            '2016-10-01 16:14',
            'phases-1-end_date':
            '2016-10-01 16:15',
            'phases-1-name':
            'Name 1',
            'phases-1-description':
            'Description 1',
            'phases-1-type':
            'euth_maps:020:collect',
            'phases-1-weight':
            '1',
            'phases-1-delete':
            '0',
            'project-description':
            'Project description',
            'project-name':
            'Project name Flashpoll',
            'project-information':
            'Project info',
            'save_draft':
            '',
            'module_settings-key':
            '32a34235ba14df2de',
            'module_settings-title':
            'title',
            'module_settings-shortDescription':
            'shortDescription',
            'module_settings-longDescription':
            'longDescription',
            'module_settings-concludeMessage':
            'concludeMessage',
            'module_settings-startTime':
            '30/01/2017 12:00',
            'module_settings-endTime':
            '01/02/2017 12:00',
            'module_settings-geofenceLocation':
            'POLYGON' + '((12.721618618816137 52.71100659513395,' +
            '12.765563931316137 52.05384170239608,' +
            '14.039977993816137 52.38699960050584' +
            ',13.073181118816137 52.707678513988185' +
            ',12.721618618816137 52.71100659513395))',
        })

    assert response.status_code == 302
    assert redirect_target(response) == 'dashboard-project-list'
    project = organisation.project_set.first()
    assert project.is_draft
    assert project.name == 'Project name Flashpoll'
    assert len(project.module_set.first().phase_set.all()) == 2
Exemplo n.º 29
0
def test_dashboard_project_users(client, project, user_factory,
                                 request_factory, invite_factory):
    url = reverse('dashboard-project-users', kwargs={
        'organisation_slug': project.organisation.slug,
        'slug': project.slug,
    })
    request0 = request_factory(project=project)
    request1 = request_factory(project=project)
    request2 = request_factory(project=project)
    invite0 = invite_factory(project=project)
    invite1 = invite_factory(project=project)
    user0 = user_factory(email='*****@*****.**')
    user1 = user_factory(email='*****@*****.**')
    project.participants.add(user0)
    project.participants.add(user1)

    response = client.get(url)
    assert redirect_target(response) == 'account_login'

    initiator = project.organisation.initiators.first()
    client.login(username=initiator.email, password='******')
    response = client.get(url)
    assert response.status_code == 200
    multiform = response.context['form']
    assert len(multiform['requests'].forms) == 3
    assert multiform['requests'].forms[0].instance == request0
    assert multiform['requests'].forms[1].instance == request1
    assert multiform['requests'].forms[2].instance == request2
    assert multiform['requests'].extra == 0
    assert len(multiform['invites'].forms) == 2
    assert multiform['invites'].forms[0].instance == invite0
    assert multiform['invites'].forms[1].instance == invite1
    assert len(multiform['users'].forms) == 2
    assert multiform['users'].forms[0].instance == user0
    assert multiform['users'].forms[1].instance == user1

    response = client.post(url, {
        'requests-0-id': request0.pk,
        'requests-0-action': 'accept',
        'requests-1-id': request1.pk,
        'requests-1-action': 'decline',
        'requests-2-id': request2.pk,
        'requests-2-action': '',
        'requests-TOTAL_FORMS': '3',
        'requests-INITIAL_FORMS': '3',
        'requests-MAX_NUM_FORMS': '',
        'invites-TOTAL_FORMS': '2',
        'invites-INITIAL_FORMS': '2',
        'invites-MAX_NUM_FORMS': '',
        'invites-0-id': invite0.pk,
        'invites-0-delete': 'on',
        'invites-1-id': invite1.pk,
        'users-TOTAL_FORMS': '2',
        'users-INITIAL_FORMS': '2',
        'users-MAX_NUM_FORMS': '',
        'users-0-id': user0.id,
        'users-0-delete': 'on',
        'users-1-id': user1.id,
        'users-1-delete': '',
    })
    assert redirect_target(response) == 'dashboard-project-users'
    assert len(project.request_set.all()) == 1
    assert project.request_set.first() == request2
    assert len(project.invite_set.all()) == 1
    assert project.invite_set.first() == invite1
    assert len(project.participants.all()) == 2
    assert not project.participants.filter(username=user0.username).exists()
    assert User.objects.filter(username=user0.username).exists()
Exemplo n.º 30
0
def test_authenticated_user_can_upload_avatar(client, user, login_url):
    url = reverse('dashboard-profile')
    client.post(login_url, {'email': user.email, 'password': '******'})
    response = client.get(url)
    assert redirect_target(response) == 'account_login'