[extensions-web] Fix ExtensionVersions's source max_length field.
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Fix ExtensionVersions's source max_length field.
- Date: Fri, 23 Sep 2011 23:09:51 +0000 (UTC)
commit b026582e181f81bb872bde8e9972ff2c0ae98a4f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Sep 23 17:36:17 2011 -0400
Fix ExtensionVersions's source max_length field.
...ersion_source__chg_field_extensionversion_ve.py | 96 ++++++++++++++++++++
sweettooth/extensions/models.py | 9 ++-
.../extensions/testdata/LargeUUID/LargeUUID.zip | Bin 0 -> 296 bytes
.../extensions/testdata/LargeUUID/metadata.json | 6 ++
sweettooth/extensions/tests.py | 64 ++++++++++---
5 files changed, 157 insertions(+), 18 deletions(-)
---
diff --git a/sweettooth/extensions/migrations/0007_auto__chg_field_extensionversion_source__chg_field_extensionversion_ve.py b/sweettooth/extensions/migrations/0007_auto__chg_field_extensionversion_source__chg_field_extensionversion_ve.py
new file mode 100644
index 0000000..9333238
--- /dev/null
+++ b/sweettooth/extensions/migrations/0007_auto__chg_field_extensionversion_source__chg_field_extensionversion_ve.py
@@ -0,0 +1,96 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'ExtensionVersion.source'
+ db.alter_column('extensions_extensionversion', 'source', self.gf('django.db.models.fields.files.FileField')(max_length=223))
+
+ # Changing field 'ExtensionVersion.version'
+ db.alter_column('extensions_extensionversion', 'version', self.gf('django.db.models.fields.IntegerField')())
+
+
+ def backwards(self, orm):
+
+ # Changing field 'ExtensionVersion.source'
+ db.alter_column('extensions_extensionversion', 'source', self.gf('django.db.models.fields.files.FileField')(max_length=100))
+
+ # Changing field 'ExtensionVersion.version'
+ db.alter_column('extensions_extensionversion', 'version', self.gf('django.db.models.fields.IntegerField')(max_length=223))
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'extensions.extension': {
+ 'Meta': {'object_name': 'Extension'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ 'icon': ('django.db.models.fields.files.ImageField', [], {'default': "''", 'max_length': '100', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'screenshot': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100', 'blank': 'True'}),
+ 'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'None', 'db_index': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200', 'db_index': 'True'})
+ },
+ 'extensions.extensionversion': {
+ 'Meta': {'unique_together': "(('extension', 'version'),)", 'object_name': 'ExtensionVersion'},
+ 'extension': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'versions'", 'to': "orm['extensions.Extension']"}),
+ 'extra_json_fields': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'shell_versions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['extensions.ShellVersion']", 'symmetrical': 'False'}),
+ 'source': ('django.db.models.fields.files.FileField', [], {'max_length': '223'}),
+ 'status': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'version': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'extensions.shellversion': {
+ 'Meta': {'object_name': 'ShellVersion'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'major': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'minor': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'point': ('django.db.models.fields.IntegerField', [], {})
+ }
+ }
+
+ complete_apps = ['extensions']
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index c96ba86..c7f210d 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -149,10 +149,12 @@ def parse_zipfile_metadata(uploaded_file):
zipfile.close()
return metadata
+# uuid max length + suffix max length
+filename_max_length = Extension._meta.get_field('uuid').max_length + len(".v000.shell-version.zip")
+
class ExtensionVersion(models.Model):
extension = models.ForeignKey(Extension, related_name="versions")
- version = models.IntegerField(default=0,
- max_length=Extension._meta.get_field('uuid').max_length + len(".v000.shell-version.zip"))
+ version = models.IntegerField(default=0)
extra_json_fields = models.TextField()
status = models.PositiveIntegerField(choices=STATUSES.items())
shell_versions = models.ManyToManyField(ShellVersion)
@@ -166,7 +168,8 @@ class ExtensionVersion(models.Model):
def make_filename(self, filename):
return "%s.v%d.shell-extension.zip" % (self.extension.uuid, self.version)
- source = models.FileField(upload_to=make_filename)
+ source = models.FileField(upload_to=make_filename,
+ max_length=filename_max_length)
@property
def shell_versions_json(self):
diff --git a/sweettooth/extensions/testdata/LargeUUID/LargeUUID.zip b/sweettooth/extensions/testdata/LargeUUID/LargeUUID.zip
new file mode 100644
index 0000000..b040e8a
Binary files /dev/null and b/sweettooth/extensions/testdata/LargeUUID/LargeUUID.zip differ
diff --git a/sweettooth/extensions/testdata/LargeUUID/metadata.json b/sweettooth/extensions/testdata/LargeUUID/metadata.json
new file mode 100644
index 0000000..f3a5c9f
--- /dev/null
+++ b/sweettooth/extensions/testdata/LargeUUID/metadata.json
@@ -0,0 +1,6 @@
+{
+ "uuid": "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 gnome org",
+ "name": "Large UUID test",
+ "description": "Simple test metadata",
+ "url": "http://test-metadata.gnome.org"
+}
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 8d0d0bc..0fbb218 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -15,7 +15,10 @@ def get_test_zipfile(testname):
class UploadTest(TestCase):
def setUp(self):
- self.user = User.objects.create_user('testing', 'a a aa', 'jjj')
+ self.username = 'TestUser1'
+ self.email = 'non-existant non-existant tld'
+ self.password = 'a random password'
+ self.user = User.objects.create_user(self.username, self.email, self.password)
def test_simple_metadata(self):
metadata = {"name": "Test Metadata",
@@ -45,9 +48,31 @@ class UploadTest(TestCase):
self.assertEquals(extension.description, "Simple test metadata")
self.assertEquals(extension.url, "http://test-metadata.gnome.org")
+ def test_extra_metadata(self):
+ extension = models.Extension(creator=self.user)
+ version = models.ExtensionVersion()
+ version.extension = extension
+
+ with get_test_zipfile('ExtraMetadata') as f:
+ metadata = models.parse_zipfile_metadata(f)
+ version.parse_metadata_json(metadata)
+
+ extra = json.loads(version.extra_json_fields)
+ self.assertEquals(extension.uuid, "test-extension-2 gnome org")
+ self.assertEquals(extra["extra"], "This is some good data")
+ self.assertTrue("description" not in extra)
+ self.assertTrue("url" not in extra)
+
+class UploadTest(TestCase):
+ def setUp(self):
+ self.username = 'TestUser1'
+ self.email = 'non-existant non-existant tld'
+ self.password = 'a random password'
+ self.user = User.objects.create_user(self.username, self.email, self.password)
+
def test_upload_parsing(self):
client = Client()
- client.login(username='testing', password='jjj')
+ client.login(username=self.username, password=self.password)
with get_test_zipfile('SimpleExtension') as f:
response = client.post(reverse('extensions-upload-file'),
@@ -80,24 +105,33 @@ class UploadTest(TestCase):
self.assertEquals(version2.status, models.STATUS_NEW)
self.assertEquals(version2.version, version1.version+1)
- def test_extra_metadata(self):
- extension = models.Extension(creator=self.user)
- version = models.ExtensionVersion()
- version.extension = extension
- with get_test_zipfile('ExtraMetadata') as f:
- metadata = models.parse_zipfile_metadata(f)
- version.parse_metadata_json(metadata)
- extra = json.loads(version.extra_json_fields)
- self.assertEquals(extension.uuid, "test-extension-2 gnome org")
- self.assertEquals(extra["extra"], "This is some good data")
- self.assertTrue("description" not in extra)
- self.assertTrue("url" not in extra)
+ def test_upload_large_uuid(self):
+ client = Client()
+ client.login(username=self.username, password=self.password)
+
+ with get_test_zipfile('LargeUUID') as f:
+ response = client.post(reverse('extensions-upload-file'),
+ dict(source=f), follow=True)
+
+ large_uuid = '1234567890'*9 + '@gnome.org'
+ extension = models.Extension.objects.get(uuid=large_uuid)
+ version1 = extension.versions.order_by("-version")[0]
+
+ self.assertEquals(version1.status, models.STATUS_NEW)
+ self.assertEquals(extension.creator, self.user)
+ self.assertEquals(extension.name, "Large UUID test")
+ self.assertEquals(extension.description, "Simple test metadata")
+ self.assertEquals(extension.url, "http://test-metadata.gnome.org")
+
class ExtensionVersionTest(TestCase):
def setUp(self):
- self.user = User.objects.create_user('testing', 'a a aa', 'jjj')
+ self.username = 'TestUser1'
+ self.email = 'non-existant non-existant tld'
+ self.password = 'a random password'
+ self.user = User.objects.create_user(self.username, self.email, self.password)
def test_single_version(self):
metadata = {"name": "Test Metadata",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]