def test_returns_video_unavailable_if_channel_has_been_terminated( self, client, video_with_transcodes_factory, channel_factory, user, video_factory, ): channel = channel_factory( name='My Channel', user=user, description='My Channel Desc', ) video_data = video_with_transcodes_factory(channel=channel) video_factory(channel=channel) video = video_data['video'] moderation_services.terminate_channel( channel_id=channel.id, reason='reason', ) response = client.get(f'/v/{video.id}/') assert response.status_code == OK assert response.context['error_unavailable'] == { 'title': 'Video Unavailable', 'description': ('The channel associated with this video has been terminated.'), }
def test_is_terminated_returns_true_if_was_terminated( self, channel_factory, user ): channel = channel_factory(user=user) moderation_services.terminate_channel( channel_id=channel.id, reason='reason', ) channel.refresh_from_db() assert channel.is_terminated is True
def test_get_returns_204_if_channel_is_terminated(self, api_client_no_auth, video_with_renditions): video = video_with_renditions moderation_services.terminate_channel(channel_id=video.channel.id, reason='reason') response = api_client_no_auth.get( f'/api/v1/video/{video.id}/playlist.m3u8') assert response.status_code == NO_CONTENT assert response.content.decode() == ''
def test_terminated_on_is_set_if_was_terminated( self, channel_factory, user ): channel = channel_factory(user=user) moderation_services.terminate_channel( channel_id=channel.id, reason='reason', ) channel.refresh_from_db() assert isinstance(channel.terminated_on, datetime)
def test_delete_when_channel_is_terminated_returns_403( self, video_with_transcodes): api_client = video_with_transcodes['api_client'] video = video_with_transcodes['video'] moderation_services.terminate_channel(channel_id=video.channel.id, reason='reason') response = api_client.delete(f'/api/v1/video/{video.id}/') assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ERRORS['cant_modify_video_channel_terminated'] }
def test_skips_syncing_if_channel_is_terminated(self, channel_sync): moderation_services.terminate_channel( channel_id=channel_sync.destination_channel.id, reason='x', ) ( synced_external_source_video_ids, new_video_records_ids, ) = services.sync(channel_sync_id=channel_sync.id) assert synced_external_source_video_ids == () assert new_video_records_ids == () channel_sync.refresh_from_db() assert channel_sync.is_syncing is False
def test_raises_if_destination_channel_is_terminated(self, channel): moderation_services.terminate_channel(channel_id=channel.id, reason='x', notify=False) with pytest.raises(PermissionDenied): services.create_channel_sync( external_source='youtube', external_source_channel_url=( f'https://youtube.com/channel/{EXTERNAL_SOURCE_CHANNEL_ID}' ), destination_channel_id=channel.id, user_id=channel.user_id, )
def test_when_channel_is_terminated_returns_403(self, api_client, channel_factory, settings): settings.CELERY_TASK_ALWAYS_EAGER = True api_client, user = api_client channel = channel_factory(user=user) moderation_services.terminate_channel(channel_id=channel.id, reason='reason') response = api_client.delete(f'/api/v1/channel/{channel.id}/') assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ERRORS['cant_modify_channel_channel_terminated'] }
def test_get_when_channel_is_terminated( self, api_client_no_auth, video_with_transcodes, expected_video_resp_json, ): video = video_with_transcodes['video'] moderation_services.terminate_channel(channel_id=video.channel.id, reason='reason') response = api_client_no_auth.get(f'/api/v1/video/{video.id}/') assert response.status_code == OK assert response.json() == expected_video_resp_json.extend( {'channel_is_terminated': True})
def test(self, channel, mocker, settings): mock_send_mail = mocker.patch(f'{MODULE}.send_mail') channel_termination = services.terminate_channel( channel_id=channel.id, reason='broke rule X, many times', notify=False, ) tasks.task_notify_channel_owner_channel_is_termination( channel_termination_id=channel_termination.id) assert mock_send_mail.called exp_subject = 'Your Veems channel has been terminated' exp_message = ( f'Your channel "{channel.name}" ' 'has been terminated permanently.\n\n' 'You will not be able to upload new videos.\n' 'Users will not be able to view your videos.\n' 'Your channel content will be deleted in 30 days.\n\n' f'Channel link: http://localhost:8000/c/{channel.id}/\n' f'Reason: {channel_termination.reason}' f'\n\nIf you think this decision has been made in error, ' 'please reply to this email.' '\nIf you would like you export your subscribers, ' 'please reply to this email.' '\n\n- Veems Support Team\n') mock_send_mail.assert_called_once_with( subject=exp_subject, message=exp_message, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=[channel.user.email], fail_silently=False, )
def test_when_channel_is_terminated_returns_403(self, api_client, channel_factory): api_client, user = api_client channel_factory(user=user, is_selected=True) channel = channel_factory(user=user, is_selected=False) body = { 'is_selected': True, } moderation_services.terminate_channel(channel_id=channel.id, reason='reason') response = api_client.put(f'/api/v1/channel/{channel.id}/', body, format='json') assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ERRORS['cant_modify_channel_channel_terminated'] }
def test_terminated_on_is_null_if_termination_record_deleted( self, channel_factory, user ): channel = channel_factory(user=user) channel_termination = moderation_services.terminate_channel( channel_id=channel.id, reason='reason', ) channel_termination.delete() channel.refresh_from_db() assert channel.terminated_on is None
def test_returns_403_when_channel_is_terminated(self, api_client, channel_factory): api_client, user = api_client channel = channel_factory(user=user) moderation_services.terminate_channel(channel_id=channel.id, reason='reason') body = json.dumps({ 'filename': 'MyFile.mp4', 'channel_id': channel.id, 'num_parts': 3, }) response = api_client.put(self.URL, body, content_type='application/json') assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ERRORS['cant_upload_channel_terminated'] } assert models.Upload.objects.count() == 0 assert models.Video.objects.count() == 0
def test_put_when_channel_is_terminated_returns_403( self, video_with_transcodes): video = video_with_transcodes['video'] api_client = video_with_transcodes['api_client'] moderation_services.terminate_channel(channel_id=video.channel.id, reason='reason') payload = { 'title': 'new title', 'visibility': 'public', 'description': 'new description', 'tags': ['new', 'tags'], } response = api_client.put( f'/api/v1/video/{video.id}/', payload, format='json', ) assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ERRORS['cant_modify_video_channel_terminated'] }
def test_returns_403_if_destination_channel_is_terminated( self, api_client, channel_factory): api_client, user = api_client channel = channel_factory(user=user) moderation_services.terminate_channel(channel_id=channel.id, reason='x') body = { 'destination_channel_id': channel.id, 'external_source': 'youtube', 'external_source_channel_url': (f'https://youtube.com/channel/{EXTERNAL_SOURCE_CHANNEL_ID}'), } response = api_client.post('/api/v1/channel/sync/', body, format='json') assert response.status_code == FORBIDDEN assert response.json() == { 'detail': ('Cannot create a sync for a Channel which is terminated') }
def test(self, channel, mocker): mock_task_notify_channel_owner_channel_is_terminated = mocker.patch( f'{MODULE}.tasks.task_notify_channel_owner_channel_is_termination') assert services.terminate_channel( channel_id=channel.id, reason='broke rule X, many times', ) terminations = channel.terminations.all() assert len(terminations) == 1 termination = terminations[0] assert termination.channel == channel assert termination.reason == 'broke rule X, many times' assert ( mock_task_notify_channel_owner_channel_is_terminated.delay.called)
def make(channel=None): channel = channel or request.getfixturevalue('channel') return moderation_services.terminate_channel(channel_id=channel.id, reason='broke rule X')
def terminated_channel(channel_factory, user): record = channel_factory(name='Terminated', user=user) moderation_services.terminate_channel( channel_id=record.id, reason='reason' ) return record