Multi-platform: support multiple files per version #201

Merged
Oleg-Komarov merged 43 commits from multi-os into main 2024-07-09 16:27:46 +02:00
2 changed files with 10 additions and 0 deletions
Showing only changes of commit 49e0cb0fe5 - Show all commits

View File

@ -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(

View File

@ -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'])