Example #1
0
def test_join_gets_user_with_authenticated_userid(User):
    request = _mock_request(matchdict=_matchdict())

    views.join(request)

    User.get_by_userid.assert_called_once_with(
        request.domain, request.authenticated_userid)
Example #2
0
def test_join_adds_user_to_group_members(Group, User):
    Group.get_by_hashid.return_value = group = mock.Mock()
    User.get_by_userid.return_value = mock.sentinel.user

    views.join(_mock_request(matchdict=_matchdict()))

    group.members.append.assert_called_once_with(mock.sentinel.user)
Example #3
0
def test_join_gets_user():
    request = _mock_request(matchdict=_matchdict())
    type(request).authenticated_user = user_property = mock.PropertyMock()

    views.join(request)

    user_property.assert_called_once_with()
Example #4
0
def test_join_adds_user_to_group_members(Group, User):
    Group.get_by_id.return_value = group = mock.Mock()
    User.get_by_userid.return_value = mock.sentinel.user

    views.join(_mock_request(matchdict=_matchdict()))

    group.members.append.assert_called_once_with(mock.sentinel.user)
Example #5
0
def test_join_gets_user_with_authenticated_userid(User):
    request = _mock_request(matchdict=_matchdict())

    views.join(request)

    User.get_by_userid.assert_called_once_with(
        request.domain, request.authenticated_userid)
Example #6
0
def test_join_adds_user_to_group_members(Group):
    Group.get_by_pubid.return_value = group = mock.Mock()
    request = _mock_request(matchdict=_matchdict(), authenticated_user=mock.sentinel.user)

    views.join(request)

    group.members.append.assert_called_once_with(mock.sentinel.user)
Example #7
0
def test_join_adds_user_to_group_members(Group):
    Group.get_by_pubid.return_value = group = mock.Mock()
    request = _mock_request(
        matchdict=_matchdict(), authenticated_user=mock.sentinel.user)

    views.join(request)

    group.members.append.assert_called_once_with(mock.sentinel.user)
Example #8
0
def test_join_uses_hashid_from_matchdict_to_get_groupid(hashids):
    matchdict = _matchdict()
    request = _mock_request(matchdict=matchdict)

    views.join(request)

    hashids.decode.assert_called_once_with(
        request, "h.groups", matchdict["hashid"])
Example #9
0
    def test_joins_group(self,
                         groups_service,
                         pyramid_config,
                         pyramid_request):
        group = FakeGroup('abc123', 'some-slug')
        pyramid_config.testing_securitypolicy('gentiana')

        views.join(group, pyramid_request)

        assert (group, 'gentiana') in groups_service.joined
Example #10
0
    def test_joins_group(self,
                         groups_service,
                         pyramid_config,
                         pyramid_request):
        group = FakeGroup('abc123', 'some-slug')
        pyramid_config.testing_securitypolicy('gentiana')

        views.join(group, pyramid_request)

        assert (group, 'gentiana') in groups_service.joined
Example #11
0
def test_join_publishes_join_event(Group, session_model):
    group = mock.Mock(pubid = mock.sentinel.pubid)
    Group.get_by_pubid.return_value = group
    request = _mock_request(matchdict=_matchdict())

    views.join(request)

    request.get_queue_writer().publish.assert_called_once_with('user', {
        'type': 'group-join',
        'userid': request.authenticated_userid,
        'group': mock.sentinel.pubid,
        'session_model': session_model(),
    })
Example #12
0
    def test_redirects_to_group_page(self, pyramid_request):
        group = FakeGroup('abc123', 'some-slug')

        result = views.join(group, pyramid_request)

        assert isinstance(result, HTTPSeeOther)
        assert result.location == '/g/abc123/some-slug'
Example #13
0
    def test_redirects_to_group_page(self, pyramid_request):
        group = FakeGroup('abc123', 'some-slug')

        result = views.join(group, pyramid_request)

        assert isinstance(result, HTTPSeeOther)
        assert result.location == '/g/abc123/some-slug'
Example #14
0
def test_join_publishes_join_event(Group, session_model):
    group = mock.Mock(pubid=mock.sentinel.pubid)
    Group.get_by_pubid.return_value = group
    request = _mock_request(matchdict=_matchdict())

    views.join(request)

    request.get_queue_writer().publish.assert_called_once_with(
        "user",
        {
            "type": "group-join",
            "userid": request.authenticated_userid,
            "group": mock.sentinel.pubid,
            "session_model": session_model(),
        },
    )
Example #15
0
def test_join_redirects_to_group_page(Group):
    slug = "test-slug"
    group = Group.get_by_pubid.return_value = mock.Mock(slug=slug)
    request = _mock_request(matchdict=_matchdict())

    result = views.join(request)

    assert isinstance(result, httpexceptions.HTTPRedirection)
Example #16
0
def test_join_redirects_to_group_page(Group, logic):
    slug = "test-slug"
    group = Group.get_by_id.return_value = mock.Mock(slug=slug)
    request = _mock_request(matchdict=_matchdict())
    logic.url_for_group.return_value = mock.sentinel.group_url

    redirect = views.join(request)

    logic.url_for_group.assert_called_once_with(request, group)
    assert redirect.status_int == 303
    assert redirect.location == mock.sentinel.group_url
Example #17
0
def test_join_404s_if_groups_feature_is_off():
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.join(_mock_request(feature=lambda feature: False))
Example #18
0
def test_join_gets_group_by_id(hashids, Group):
    hashids.decode.return_value = "test-group-id"

    views.join(_mock_request(matchdict=_matchdict()))

    Group.get_by_id.assert_called_once_with("test-group-id")
Example #19
0
def test_join_404s_if_group_not_found(Group):
    Group.get_by_pubid.return_value = None

    with pytest.raises(httpexceptions.HTTPNotFound):
        views.join(_mock_request(matchdict=_matchdict()))
Example #20
0
def test_join_gets_group_by_pubid(Group):
    views.join(_mock_request(matchdict={'pubid': 'twibble', 'slug': 'snail'}))

    Group.get_by_pubid.assert_called_once_with("twibble")
Example #21
0
def test_join_404s_if_groups_feature_is_off():
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.join(_mock_request(feature=lambda feature: False))
Example #22
0
def test_join_gets_group_by_pubid(Group):
    views.join(_mock_request(matchdict={"pubid": "twibble", "slug": "snail"}))

    Group.get_by_pubid.assert_called_once_with("twibble")