Update extension fields from manifest metadata #111 #121
@ -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')))
|
||||
)
|
||||
|
@ -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:
|
||||
|
@ -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/')
|
||||
|
Loading…
Reference in New Issue
Block a user