|
1 | 1 | """ |
2 | 2 | Tests for asset-related API endpoints. |
3 | 3 | """ |
| 4 | +import mock |
4 | 5 | from django.test import TestCase |
5 | 6 | from django.urls import reverse |
6 | 7 | from rest_framework import status |
@@ -79,6 +80,48 @@ def test_create_asset_should_return_201(self, version): |
79 | 80 | self.assertEqual(response.data['play_order'], 0) |
80 | 81 | self.assertEqual(response.data['skip_asset_check'], 0) |
81 | 82 |
|
| 83 | + @mock.patch('api.serializers.mixins.rename') |
| 84 | + @mock.patch('api.serializers.mixins.validate_uri') |
| 85 | + def test_create_video_asset_v2_with_non_zero_duration_should_fail( |
| 86 | + self, |
| 87 | + mock_validate_uri, |
| 88 | + mock_rename |
| 89 | + ): |
| 90 | + """Test that v2 rejects video assets with non-zero duration.""" |
| 91 | + mock_validate_uri.return_value = True |
| 92 | + asset_list_url = reverse('api:asset_list_v2') |
| 93 | + |
| 94 | + test_data = { |
| 95 | + 'name': 'Test Video', |
| 96 | + 'uri': '/data/screenly_assets/video.mp4', |
| 97 | + 'start_date': '2019-08-24T14:15:22Z', |
| 98 | + 'end_date': '2029-08-24T14:15:22Z', |
| 99 | + 'duration': 30, |
| 100 | + 'mimetype': 'video', |
| 101 | + 'is_enabled': True, |
| 102 | + 'nocache': False, |
| 103 | + 'play_order': 0, |
| 104 | + 'skip_asset_check': False |
| 105 | + } |
| 106 | + |
| 107 | + response = self.client.post( |
| 108 | + asset_list_url, |
| 109 | + data=test_data, |
| 110 | + format='json' |
| 111 | + ) |
| 112 | + |
| 113 | + self.assertEqual( |
| 114 | + response.status_code, |
| 115 | + status.HTTP_500_INTERNAL_SERVER_ERROR |
| 116 | + ) |
| 117 | + self.assertIn( |
| 118 | + 'Duration must be zero for video assets', |
| 119 | + str(response.data) |
| 120 | + ) |
| 121 | + |
| 122 | + self.assertEqual(mock_rename.call_count, 1) |
| 123 | + self.assertEqual(mock_validate_uri.call_count, 1) |
| 124 | + |
82 | 125 | @parametrize_version |
83 | 126 | def test_get_assets_after_create_should_return_1_asset(self, version): |
84 | 127 | self.create_asset(ASSET_CREATION_DATA, version) |
|
0 commit comments