Multi-platform: support multiple files per version #201
@ -683,6 +683,11 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
|
||||
def add_file(self, file: File):
|
||||
current_platforms = set([p.slug for p in self.platforms.all()])
|
||||
if not current_platforms:
|
||||
raise ValueError(
|
||||
f'add_file failed: Version pk={self.pk} is not platform-specific, '
|
||||
f'no more files allowed'
|
||||
)
|
||||
file_platforms = set(file.get_platforms() or [])
|
||||
if overlap := current_platforms & file_platforms:
|
||||
raise ValueError(
|
||||
|
@ -131,6 +131,11 @@ class VersionTest(TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
version.add_file(file)
|
||||
|
||||
all_platforms_version = create_version(metadata__platforms=[])
|
||||
file = FileFactory(metadata__platforms=['linux-x64'])
|
||||
with self.assertRaises(ValueError):
|
||||
all_platforms_version.add_file(file)
|
||||
|
||||
def test_get_file_for_platform(self):
|
||||
version = create_version(metadata__platforms=['linux-x64'])
|
||||
file = FileFactory(metadata__platforms=['windows-x64'])
|
||||
|
Loading…
Reference in New Issue
Block a user