Merge lp:~michael.nelson/ubuntu-webcatalog/1180770-handle-incorrect-desktop-files into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Merged
Approved by: Martin Albisetti
Approved revision: 185
Merged at revision: 184
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/1180770-handle-incorrect-desktop-files
Merge into: lp:ubuntu-webcatalog
Diff against target: 83 lines (+41/-2)
3 files modified
src/webcatalog/forms.py (+9/-2)
src/webcatalog/tests/test_data/workrave:workrave.desktop (+16/-0)
src/webcatalog/tests/test_forms.py (+16/-0)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/1180770-handle-incorrect-desktop-files
Reviewer Review Type Date Requested Status
Martin Albisetti (community) Approve
Review via email: mp+164881@code.launchpad.net

Commit message

Invalid desktop files are handled (skipped) rather than erroring.

Description of the change

Invalid desktop files are handled (skipped) rather than erroring.

See the linked bug for a description of the problem.

`fab test`

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/forms.py'
2--- src/webcatalog/forms.py 2012-07-02 21:25:30 +0000
3+++ src/webcatalog/forms.py 2013-05-21 12:28:08 +0000
4@@ -21,7 +21,10 @@
5
6 import apt
7 import json
8-from ConfigParser import ConfigParser
9+from ConfigParser import (
10+ ConfigParser,
11+ ParsingError,
12+)
13 from StringIO import StringIO
14
15 from django import forms
16@@ -64,7 +67,11 @@
17 @classmethod
18 def get_form_from_desktop_data(cls, str_data, distroseries):
19 parser = ConfigParser()
20- parser.readfp(StringIO(str_data))
21+ try:
22+ parser.readfp(StringIO(str_data))
23+ except ParsingError:
24+ return cls(data={}, instance=None)
25+
26 data = dict(parser.items('Desktop Entry'))
27 for desktop_key, app_key in desktop_field_mappings.items():
28 if desktop_key in data:
29
30=== added file 'src/webcatalog/tests/test_data/workrave:workrave.desktop'
31--- src/webcatalog/tests/test_data/workrave:workrave.desktop 1970-01-01 00:00:00 +0000
32+++ src/webcatalog/tests/test_data/workrave:workrave.desktop 2013-05-21 12:28:08 +0000
33@@ -0,0 +1,16 @@
34+[Desktop Entry]
35+Categories=Application;Other
36+X-AppInstall-Package=workrave
37+X-AppInstall-Popcon=500
38+X-AppInstall-Section=universe
39+
40+Type=Application
41+Categories=Utility;GTK;Accessibility
42+Exec=workrave
43+Icon=workrave
44+Comment=Assists in the prevention and recovery of Repetitive Strain Injury (RSI)
45+- RSI (Repetitive Strain Injury) oraz wspomaga rekonwalescencję
46+ запястья и снятии общего мышечного напряжения.
47+Name=Workrave
48+
49+X-Ubuntu-Gettext-Domain=app-install-data
50
51=== modified file 'src/webcatalog/tests/test_forms.py'
52--- src/webcatalog/tests/test_forms.py 2012-07-02 21:25:30 +0000
53+++ src/webcatalog/tests/test_forms.py 2013-05-21 12:28:08 +0000
54@@ -19,6 +19,8 @@
55
56 from __future__ import absolute_import
57
58+import os
59+
60 from django.forms import ValidationError
61 from django.test import TestCase
62
63@@ -108,6 +110,20 @@
64 self.assertTrue(form.is_valid())
65 self.assertEqual('MyPkg description', form.cleaned_data['description'])
66
67+ def test_get_form_from_desktop_data_bad_data(self):
68+ """Don't panic if we can't parse the desktop file."""
69+ app = self.factory.make_application(package_name='workrave')
70+ curdir = os.path.dirname(__file__)
71+ desktop_file_path = os.path.join(curdir, 'test_data',
72+ 'workrave:workrave.desktop')
73+ with open(desktop_file_path, 'r') as desktop_file:
74+ data = desktop_file.read()
75+
76+ form = ArchiveApplicationForm.get_form_from_desktop_data(
77+ data, distroseries=app.distroseries)
78+
79+ self.assertFalse(form.is_valid())
80+
81 def test_extra_fields(self):
82 # There are a bunch of extra fields which are also supported by
83 # the model form.

Subscribers

People subscribed via source and target branches