Exemple #1
0
def test_create_channel_no_descriptions(index_user, staff_client, staff_user,
                                        reddit_factories, settings):
    """
    Create a channel and assert the response for no descriptions
    """
    settings.INDEXING_API_USERNAME = index_user.username
    url = reverse("channel-list")
    channel = reddit_factories.channel("private",
                                       user=staff_user,
                                       strategy=STRATEGY_BUILD)
    payload = {
        "channel_type": channel.channel_type,
        "link_type": "any",
        "name": channel.name,
        "title": channel.title,
    }
    resp = staff_client.post(url, data=payload)
    expected = {
        **default_channel_response_data(channel),
        **payload,
        "description": "",
        "public_description": "",
        "user_is_moderator": True,
        "membership_is_managed": True,
    }
    assert resp.status_code == status.HTTP_201_CREATED
    assert resp.json() == expected
Exemple #2
0
def test_list_channels(user_client, private_channel_and_contributor, request):
    """
    List channels the user is subscribed to
    """
    channel, _ = private_channel_and_contributor
    url = reverse("channel-list")
    resp = user_client.get(url)
    assert resp.status_code == status.HTTP_200_OK
    assert resp.json() == [default_channel_response_data(channel)]
Exemple #3
0
def test_get_channel(user_client, private_channel_and_contributor):
    """
    Get a channel
    """
    channel, _ = private_channel_and_contributor
    url = reverse("channel-detail", kwargs={"channel_name": channel.name})
    resp = user_client.get(url)
    assert resp.status_code == status.HTTP_200_OK
    assert resp.json() == default_channel_response_data(channel)
Exemple #4
0
def test_get_channel_anonymous(client, public_channel):
    """
    An anonymous user should be able to see a public channel
    """
    url = reverse("channel-detail",
                  kwargs={"channel_name": public_channel.name})
    resp = client.get(url)
    assert resp.status_code == status.HTTP_200_OK
    assert resp.json() == {
        **default_channel_response_data(public_channel),
        "user_is_contributor": False,
        "user_is_subscriber": False,
    }
Exemple #5
0
def test_patch_channel_moderator(user_client, staff_api,
                                 private_channel_and_contributor):
    """
    Update a channel's settings with a moderator user
    """
    private_channel, user = private_channel_and_contributor
    url = reverse("channel-detail",
                  kwargs={"channel_name": private_channel.name})
    staff_api.add_moderator(user.username, private_channel.name)
    resp = user_client.patch(url, {"channel_type": "public"}, format="json")
    assert resp.status_code == status.HTTP_200_OK
    assert resp.json() == {
        **default_channel_response_data(private_channel),
        "user_is_moderator": True,
        "channel_type": "public",
    }
Exemple #6
0
def test_patch_channel(staff_client, private_channel):
    """
    Update a channel's settings
    """
    url = reverse("channel-detail",
                  kwargs={"channel_name": private_channel.name})
    resp = staff_client.patch(url, {"channel_type": "public"}, format="json")
    assert resp.status_code == status.HTTP_200_OK
    assert resp.json() == {
        **default_channel_response_data(private_channel),
        "user_is_moderator": True,
        "channel_type": "public",
    }
    assert Channel.objects.count() == 1
    channel_obj = Channel.objects.first()
    assert channel_obj.name == private_channel.name
    assert channel_obj.membership_is_managed is False