Ejemplo n.º 1
0
def test_create_inits_form_with_schema(GroupSchema, Form):
    schema = mock.Mock()
    GroupSchema.return_value = mock.Mock(bind=mock.Mock(return_value=schema))

    views.create(request=_mock_request())

    Form.assert_called_once_with(schema)
Ejemplo n.º 2
0
def test_create_inits_form_with_schema(GroupSchema, Form):
    schema = mock.Mock()
    GroupSchema.return_value = mock.Mock(bind=mock.Mock(return_value=schema))

    views.create(request=_mock_request())

    assert Form.call_args[0][0] == schema
Ejemplo n.º 3
0
def test_create_inits_form_with_schema(GroupSchema, Form):
    schema = mock.Mock()
    GroupSchema.return_value = mock.Mock(bind=mock.Mock(return_value=schema))

    views.create(request=_mock_request())

    Form.assert_called_once_with(schema)
Ejemplo n.º 4
0
def test_create_validates_form(Form):
    Form.return_value = form = mock.Mock()
    form.validate.return_value = {"name": "new group"}
    request = _mock_request()

    views.create(request)

    form.validate.assert_called_once_with(request.params.items())
Ejemplo n.º 5
0
def test_create_uses_name_from_validated_data(Form, User, Group):
    """It uses the "name" from the validated data to create a new group."""
    Form.return_value = mock.Mock(validate=lambda data: {"name": "test-group"})
    User.get_by_userid.return_value = user = mock.Mock()

    views.create(_mock_request())

    Group.assert_called_once_with(name="test-group", creator=user)
Ejemplo n.º 6
0
def test_create_uses_name_from_validated_data(Form, User, Group):
    """It uses the "name" from the validated data to create a new group."""
    Form.return_value = mock.Mock(validate=lambda data: {"name": "test-group"})
    User.get_by_userid.return_value = user = mock.Mock()

    views.create(_mock_request())

    Group.assert_called_once_with(name="test-group", creator=user)
Ejemplo n.º 7
0
def test_create_gets_user_with_authenticated_id(Form):
    """It uses the "name" from the validated data to create a new group."""
    Form.return_value = mock.Mock(validate=lambda data: {"name": "test-group"})
    request = _mock_request()
    type(request).authenticated_user = user_property = mock.PropertyMock()

    views.create(request)

    user_property.assert_called_once_with()
Ejemplo n.º 8
0
def test_create_gets_user_with_authenticated_id(Form, User):
    """It uses the "name" from the validated data to create a new group."""
    Form.return_value = mock.Mock(validate=lambda data: {"name": "test-group"})
    request = _mock_request()

    views.create(request)

    User.get_by_userid.assert_called_once_with(
        request.domain, request.authenticated_userid)
Ejemplo n.º 9
0
def test_create_adds_group_to_db(Group):
    """It should add the new group to the database session."""
    group = mock.Mock(id=6)
    Group.return_value = group
    request = _mock_request()

    views.create(request)

    request.db.add.assert_called_once_with(group)
Ejemplo n.º 10
0
def test_create_gets_user_with_authenticated_id(Form, User):
    """It uses the "name" from the validated data to create a new group."""
    Form.return_value = mock.Mock(validate=lambda data: {"name": "test-group"})
    request = _mock_request()

    views.create(request)

    User.get_by_userid.assert_called_once_with(
        request.domain, request.authenticated_userid)
Ejemplo n.º 11
0
def test_create_publishes_join_event(Group, session_model):
    group = mock.Mock(pubid=mock.sentinel.pubid)
    Group.return_value = group
    request = _mock_request()

    views.create(request)

    request.get_queue_writer().publish.assert_called_once_with('user', {
        'type': 'group-join',
        'userid': request.authenticated_userid,
        'group': group.pubid,
        'session_model': session_model(),
    })
Ejemplo n.º 12
0
def test_create_rerenders_form_on_validation_failure(Form):
    Form.return_value = form = mock.Mock()
    form.validate.side_effect = deform.ValidationFailure(None, None, None)

    result = views.create(_mock_request())

    assert result['form'] == form.render.return_value
Ejemplo n.º 13
0
def test_create_publishes_join_event(Group, session_model):
    group = mock.Mock(pubid=mock.sentinel.pubid)
    Group.return_value = group
    request = _mock_request()

    views.create(request)

    request.get_queue_writer().publish.assert_called_once_with(
        "user",
        {
            "type": "group-join",
            "userid": request.authenticated_userid,
            "group": group.pubid,
            "session_model": session_model(),
        },
    )
Ejemplo n.º 14
0
def test_create_rerenders_form_on_validation_failure(Form):
    Form.return_value = form = mock.Mock()
    form.validate.side_effect = deform.ValidationFailure(None, None, None)
    params = {"foo": "bar"}

    template_data = views.create(_mock_request())

    assert template_data['form'] == form
    assert template_data['data'] == params
Ejemplo n.º 15
0
def test_create_redirects_to_group_read_page(Group):
    """After successfully creating a new group it should redirect."""
    group = mock.Mock(id='test-id', slug='test-slug')
    Group.return_value = group
    request = _mock_request()

    result = views.create(request)

    assert isinstance(result, httpexceptions.HTTPRedirection)
Ejemplo n.º 16
0
def test_create_rerenders_form_on_validation_failure(Form):
    Form.return_value = form = mock.Mock()
    form.validate.side_effect = deform.ValidationFailure(None, None, None)
    params = {"foo": "bar"}

    template_data = views.create(_mock_request())

    assert template_data['form'] == form
    assert template_data['data'] == params
Ejemplo n.º 17
0
def test_create_redirects_to_group_read_page(Group, logic):
    """After successfully creating a new group it should redirect."""
    group = mock.Mock(id='test-id', slug='test-slug')
    Group.return_value = group
    request = _mock_request()
    logic.url_for_group.return_value = "test-read-url"

    redirect = views.create(request)

    logic.url_for_group.assert_called_once_with(request, group)
    assert redirect.status_int == 303
    assert redirect.location == "test-read-url"
Ejemplo n.º 18
0
def test_create_redirects_to_group_read_page(Group, hashids):
    """After successfully creating a new group it should redirect."""
    group = mock.Mock(id='test-id', slug='test-slug')
    Group.return_value = group
    request = _mock_request()
    hashids.encode.return_value = "testhashid"

    redirect = views.create(request)

    request.route_url.assert_called_once_with(
        "group_read", hashid="testhashid", slug="test-slug")
    assert redirect.status_int == 303
    assert redirect.location == "test-read-url"
Ejemplo n.º 19
0
def test_create_404s_if_groups_feature_is_off():
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.create(_mock_request(feature=lambda feature: False))
Ejemplo n.º 20
0
def test_create_with_non_ascii_name():
    views.create(_mock_request(params={"name": u"☆ ßüper Gröup ☆"}))
Ejemplo n.º 21
0
def test_create_404s_if_groups_feature_is_off():
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.create(_mock_request(feature=lambda feature: False))