Update extension fields from manifest metadata #111 #121

Merged
Oleg-Komarov merged 4 commits from update-metadata-from-manifest into main 2024-05-10 15:13:33 +02:00
3 changed files with 74 additions and 2 deletions
Showing only changes of commit ea6e5ed978 - Show all commits

View File

@ -19,6 +19,7 @@ class ExtensionFactory(DjangoModelFactory):
name = factory.Faker('catch_phrase')
extension_id = factory.Faker('slug')
slug = factory.Faker('slug')
description = factory.LazyAttribute(
lambda _: fake_markdown.post(size=random.choice(('medium', 'large')))
)

View File

@ -185,8 +185,6 @@ class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Mod
return utils.slugify(EXTENSION_STATUS_CHOICES[self.status - 1][1])
def clean(self) -> None:
if not self.slug:
self.slug = utils.slugify(self.name)
# Require at least one approved version with a file for approved extensions
if self.status == self.STATUSES.APPROVED:
if not self.latest_version:

View File

@ -132,3 +132,76 @@ class VersionTest(TestCase):
response = self.client.get(path)
self.assertEqual(response.status_code, 200, path)
class UpdateMetadataTest(TestCase):
fixtures = ['dev', 'licenses']
def setUp(self):
super().setUp()
self.first_version = create_version(
extension__description='Extension description',
extension__name='name',
extension__status=Extension.STATUSES.INCOMPLETE,
extension__support='https://example.com/',
extension__website='https://example.com/',
file__metadata={
'name': 'name',
'support': 'https://example.com/',
'website': 'https://example.com/',
},
)
self.extension = self.first_version.extension
def test_version_create_and_delete(self):
second_version = create_version(
extension=self.extension,
file__metadata={
'name': 'new name',
'support': 'https://example.com/new',
'website': 'https://example.com/new',
},
)
self.extension.refresh_from_db()
self.assertEqual(self.extension.name, 'new name')
self.assertEqual(self.extension.support, 'https://example.com/new')
self.assertEqual(self.extension.website, 'https://example.com/new')
second_version.delete()
self.extension.refresh_from_db()
self.assertEqual(self.extension.name, 'name')
self.assertEqual(self.extension.support, 'https://example.com/')
self.assertEqual(self.extension.website, 'https://example.com/')
def test_old_name_taken(self):
second_version = create_version(
extension=self.extension,
file__metadata={
'name': 'new name',
'support': 'https://example.com/new',
'website': 'https://example.com/new',
},
)
# another extension uses old name
create_version(
extension__description='Extension description',
extension__extension_id='lalalala',
extension__name='name',
extension__status=Extension.STATUSES.INCOMPLETE,
extension__support='https://example.com/',
extension__website='https://example.com/',
file__metadata={
'name': 'name',
'support': 'https://example.com/',
'website': 'https://example.com/',
},
)
second_version.delete()
self.extension.refresh_from_db()
# couldn't revert the name because it has been taken
self.assertEqual(self.extension.name, 'new name')
# reverted other fields
self.assertEqual(self.extension.support, 'https://example.com/')
self.assertEqual(self.extension.website, 'https://example.com/')