Exemplo n.º 1
0
    def to_native(self, obj):
        native = super(VersionSerializer, self).to_native(obj)

        # Add non-field data to the response.
        native.update({
            'features': AppFeaturesSerializer().to_native(obj.features),
            'is_current_version': obj.addon.current_version == obj,
            'releasenotes': (unicode(obj.releasenotes) if obj.releasenotes else
                             None),
        })

        # Remap fields to friendlier, more backwards-compatible names.
        for old, new in self.Meta.field_rename.items():
            native[new] = native[old]
            del native[old]

        return native
Exemplo n.º 2
0
class TestAppFeaturesSerializer(amo.tests.TestCase):
    def setUp(self):
        self.app = amo.tests.app_factory()
        self.serializer = AppFeaturesSerializer()

    def _test_features(self, true_features):
        features = self.app.current_version.features
        data = self.serializer.to_native(features)
        self.assertSetEqual(['has_' + i for i in data], true_features)

    def test_all_false(self):
        self._test_features([])

    def test_one_true(self):
        features = {'has_apps': True}
        self.app.current_version.features.update(**features)
        self._test_features(features.keys())

    def test_several_true(self):
        features = {'has_apps': True, 'has_video_webm': True}
        self.app.current_version.features.update(**features)
        self._test_features(features.keys())
Exemplo n.º 3
0
class TestAppFeaturesSerializer(amo.tests.TestCase):

    def setUp(self):
        self.app = amo.tests.app_factory()
        self.serializer = AppFeaturesSerializer()

    def _test_features(self, true_features):
        features = self.app.current_version.features
        data = self.serializer.to_native(features)
        self.assertSetEqual(['has_' + i for i in data], true_features)

    def test_all_false(self):
        self._test_features([])

    def test_one_true(self):
        features = {'has_apps': True}
        self.app.current_version.features.update(**features)
        self._test_features(features.keys())

    def test_several_true(self):
        features = {'has_apps': True, 'has_video_webm': True}
        self.app.current_version.features.update(**features)
        self._test_features(features.keys())
Exemplo n.º 4
0
 def setUp(self):
     self.app = amo.tests.app_factory()
     self.serializer = AppFeaturesSerializer()
Exemplo n.º 5
0
 def setUp(self):
     self.app = amo.tests.app_factory()
     self.serializer = AppFeaturesSerializer()