def test_populate_channel_fields_batch(mocker): """ populate_channel_fields should set fields from reddit """ channels = ChannelFactory.create_batch(2) mock_api = mocker.patch("channels.api.Api", autospec=True) mock_subreddit = mock_api.return_value.get_subreddit.return_value mock_subreddit.submission_type = LINK_TYPE_ANY mock_subreddit.title = "A channel title" mock_subreddit.subreddit_type = CHANNEL_TYPE_PUBLIC updated_channel = channels[0] updated_channel.allowed_post_types = 0 updated_channel.title = None updated_channel.channel_type = None updated_channel.save() tasks.populate_channel_fields_batch.delay( [channel.id for channel in channels]) updated_channel.refresh_from_db() mock_api.return_value.get_subreddit.assert_called_once_with( updated_channel.name) assert int(updated_channel.allowed_post_types) == int( Channel.allowed_post_types.self | Channel.allowed_post_types.link) assert updated_channel.channel_type == CHANNEL_TYPE_PUBLIC assert updated_channel.title == "A channel title"
def test_get_channels(user): """ Test that get_channels returns the correct list of channel names for a user """ channels = ChannelFactory.create_batch(4) sync_channel_subscription_model(channels[0], user) add_user_role(channels[1], ROLE_CONTRIBUTORS, user) add_user_role(channels[2], ROLE_MODERATORS, user) assert get_channels(user) == {channel.name for channel in channels[:3]}
def test_get_channel_join_dates(user): """ Test out the get_channel_join_dates function """ channels = ChannelFactory.create_batch(4) sync_channel_subscription_model(channels[0], user) sync_channel_subscription_model(channels[1], user) add_user_role(channels[2], "moderators", user) add_user_role(channels[3], "contributors", user) assert sorted(get_channel_join_dates(user)) == sorted( [ (obj.channel.name, obj.created_on) for obj in list(user.channelsubscription_set.all()) + list(ChannelGroupRole.objects.filter(group__in=user.groups.all())) ] )