Esempio n. 1
0
class BaseTestCollectionMembershipField(object):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()

    def get_request(self, query_string):
        request = RequestFactory().get('/', query_string)
        request.REGION = mkt.regions.WORLDWIDE
        request.API = True
        return request

    def test_to_native(self):
        request = self.get_request({})
        resource = AppSerializer(self.app)
        resource.context = {'request': request}
        self.field.context['request'] = request
        native = self.field.to_native(self.membership)
        for key, value in native.iteritems():
            if key == 'resource_uri':
                eq_(value, self.app.get_api_url(pk=self.app.pk))
            else:
                eq_(value, resource.data[key])

    def _field_to_native_profile(self, profile='0.0'):
        request = self.get_request({'pro': profile, 'dev': 'firefoxos'})
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context['request'] = request

        return self.field.field_to_native(self.collection,
                                          'collectionmembership_set')

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2, order=0)
        result = self._field_to_native_profile()
        eq_(len(result), 2)
        eq_(int(result[0]['id']), self.app2.id)
        eq_(int(result[1]['id']), self.app.id)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile('muahahah')
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)
Esempio n. 2
0
class BaseTestCollectionMembershipField(object):

    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()
        self.create_switch('buchets')

    def get_request(self, query_string):
        request = RequestFactory().get('/', query_string)
        request.REGION = mkt.regions.WORLDWIDE
        request.API = True
        return request

    def test_to_native(self):
        resource = AppResource().full_dehydrate(Bundle(obj=self.app))
        native = self.field.to_native(self.membership)
        for key, value in native.iteritems():
            if key == 'resource_uri':
                eq_(value, self.app.get_api_url(pk=self.app.pk))
            else:
                eq_(value, resource.data[key])

    def _field_to_native_profile(self, profile='0.0'):
        request = self.get_request({'pro': profile, 'dev': 'firefoxos'})
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context['request'] = request

        return self.field.field_to_native(self.collection,
                                          'collectionmembership_set')

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2, order=0)
        result = self._field_to_native_profile()
        eq_(len(result), 2)
        eq_(int(result[0]['id']), self.app2.id)
        eq_(int(result[1]['id']), self.app.id)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile('muahahah')
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)
Esempio n. 3
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.collection.add_app(self.app)
     self.field = CollectionMembershipField()
     self.membership = CollectionMembership.objects.all()[0]
     self.request = RequestFactory()
     self.profile = FeatureProfile(apps=True).to_signature()
Esempio n. 4
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.app.addondevicetype_set.get_or_create(
         device_type=amo.DEVICE_GAIA.id)
     self.collection.add_app(self.app, order=1)
     self.field = CollectionMembershipField()
     self.field.context = {}
     self.membership = CollectionMembership.objects.all()[0]
     self.profile = FeatureProfile(apps=True).to_signature()
Esempio n. 5
0
class TestCollectionMembershipField(CollectionDataMixin, amo.tests.TestCase):

    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app)
        self.field = CollectionMembershipField()
        self.membership = CollectionMembership.objects.all()[0]
        self.request = RequestFactory()
        self.profile = FeatureProfile(apps=True).to_signature()

    def test_to_native(self):
        resource = AppResource().full_dehydrate(Bundle(obj=self.app))
        native = self.field.to_native(self.membership)
        for key, value in native.iteritems():
            if key == 'resource_uri':
                eq_(value, self.app.get_api_url(pk=self.app.pk))
            else:
                eq_(value, resource.data[key])

    def test_field_to_native(self):
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context = {
            'request': self.request.get('/', {'pro': self.profile})
        }

        # Ensure that the one app is included in the default response.
        native = self.field.field_to_native(self.collection,
                                           'collectionmembership_set')
        eq_(len(native), 1)
        eq_(int(native[0]['id']), self.app.id)

        # ...but is not included when there is a feature profile mismatch.
        self.app.current_version.features.update(has_geolocation=True)
        native_without = self.field.field_to_native(self.collection,
                                                    'collectionmembership_set')
        eq_(len(native_without), 0)

    def test_field_to_native_invalid_profile(self):
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context = {
            'request': self.request.get('/', {'pro': 'muahaha'})
        }

        # Ensure that no exceptions were raised.
        native = self.field.field_to_native(self.collection,
                                            'collectionmembership_set')

        # Ensure that no filtering took place.
        eq_(len(native), 1)
        eq_(int(native[0]['id']), self.app.id)
Esempio n. 6
0
class TestCollectionMembershipField(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app)
        self.field = CollectionMembershipField()
        self.membership = CollectionMembership.objects.all()[0]
        self.request = RequestFactory()
        self.profile = FeatureProfile(apps=True).to_signature()

    def test_to_native(self):
        resource = AppResource().full_dehydrate(Bundle(obj=self.app))
        native = self.field.to_native(self.membership)
        for key, value in native.iteritems():
            if key == 'resource_uri':
                eq_(value, self.app.get_api_url(pk=self.app.pk))
            else:
                eq_(value, resource.data[key])

    def test_field_to_native(self):
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context = {
            'request': self.request.get('/', {'pro': self.profile})
        }

        # Ensure that the one app is included in the default response.
        native = self.field.field_to_native(self.collection,
                                            'collectionmembership_set')
        eq_(len(native), 1)
        eq_(int(native[0]['id']), self.app.id)

        # ...but is not included when there is a feature profile mismatch.
        self.app.current_version.features.update(has_geolocation=True)
        native_without = self.field.field_to_native(
            self.collection, 'collectionmembership_set')
        eq_(len(native_without), 0)

    def test_field_to_native_invalid_profile(self):
        self.field.parent = self.collection
        self.field.source = 'collectionmembership_set'
        self.field.context = {
            'request': self.request.get('/', {'pro': 'muahaha'})
        }

        # Ensure that no exceptions were raised.
        native = self.field.field_to_native(self.collection,
                                            'collectionmembership_set')

        # Ensure that no filtering took place.
        eq_(len(native), 1)
        eq_(int(native[0]['id']), self.app.id)
Esempio n. 7
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.collection.add_app(self.app, order=1)
     self.field = CollectionMembershipField()
     self.field.context = {}
     self.membership = CollectionMembership.objects.all()[0]
     self.profile = FeatureProfile(apps=True).to_signature()
Esempio n. 8
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.app.addondevicetype_set.get_or_create(device_type=amo.DEVICE_GAIA.id)
     self.collection.add_app(self.app, order=1)
     self.field = CollectionMembershipField()
     self.field.context = {}
     self.membership = CollectionMembership.objects.all()[0]
     self.profile = FeatureProfile(apps=True).to_signature()
Esempio n. 9
0
class TestCollectionMembershipField(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app)
        self.field = CollectionMembershipField()

    def test_to_native(self):
        membership = self.collection.collectionmembership_set.all()[0]
        native = self.field.to_native(membership)
        eq_(native, app_to_dict(self.app))
Esempio n. 10
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.app.platform_set.get_or_create(platform_id=mkt.PLATFORM_FXOS.id)
     self.app.form_factor_set.get_or_create(
         form_factor_id=mkt.FORM_MOBILE.id)
     self.collection.add_app(self.app, order=1)
     self.field = CollectionMembershipField()
     self.field.context = {}
     self.membership = CollectionMembership.objects.all()[0]
     self.profile = FeatureProfile(apps=True).to_signature()
Esempio n. 11
0
class TestCollectionMembershipField(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app)
        self.field = CollectionMembershipField()

    def test_to_native(self):
        membership = self.collection.collectionmembership_set.all()[0]
        native = self.field.to_native(membership)
        eq_(native, app_to_dict(self.app))
Esempio n. 12
0
class TestCollectionMembershipField(CollectionDataMixin, amo.tests.TestCase):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app)
        self.field = CollectionMembershipField()
        self.membership = CollectionMembership.objects.all()[0]

    def test_to_native(self):
        resource = AppResource().full_dehydrate(Bundle(obj=self.app))
        native = self.field.to_native(self.membership)
        for key, value in native.iteritems():
            if key == "resource_uri":
                eq_(value, self.app.get_api_url(pk=self.app.pk))
            else:
                eq_(value, resource.data[key])
Esempio n. 13
0
class BaseTestCollectionMembershipField(object):

    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.app.platform_set.get_or_create(platform_id=mkt.PLATFORM_FXOS.id)
        self.app.form_factor_set.get_or_create(
            form_factor_id=mkt.FORM_MOBILE.id)
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()

    def get_request(self, data=None):
        if data is None:
            data = {}
        request = RequestFactory().get('/', data)
        request.REGION = mkt.regions.RESTOFWORLD
        request.API = True
        return request

    def test_to_native(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2)
        apps = [self.app, self.app2]
        request = self.get_request({})
        resource = SimpleAppSerializer(apps)
        resource.context = {'request': request}
        self.field.context['request'] = request
        data = self.field.to_native(self.collection.apps())
        eq_(len(data), 2)
        eq_(data[0]['id'], int(self.app.pk))
        eq_(data[0]['resource_uri'], self.app.get_api_url(pk=self.app.pk))
        eq_(data[1]['id'], int(self.app2.id))
        eq_(data[1]['resource_uri'], self.app2.get_api_url(pk=self.app2.pk))

    def _field_to_native_profile(self, **kwargs):
        query = {'pro': '0.0', 'dev': 'firefoxos'}
        query.update(kwargs)
        request = self.get_request(query)
        self.field.parent = self.collection
        self.field.source = 'apps'
        self.field.context['request'] = request

        return self.field.field_to_native(self.collection, 'apps')

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.app2.platform_set.get_or_create(platform_id=mkt.PLATFORM_FXOS.id)
        self.app2.form_factor_set.get_or_create(
            form_factor_id=mkt.FORM_MOBILE.id)
        self.collection.add_app(self.app2, order=0)
        self.app3 = amo.tests.app_factory()
        self.app3.platform_set.get_or_create(platform_id=mkt.PLATFORM_FXOS.id)
        self.app3.form_factor_set.get_or_create(
            form_factor_id=mkt.FORM_MOBILE.id)
        self.collection.add_app(self.app3)
        result = self._field_to_native_profile()
        eq_(len(result), 3)
        eq_(int(result[0]['id']), self.app2.id)
        eq_(int(result[1]['id']), self.app.id)
        eq_(int(result[2]['id']), self.app3.id)

    def test_app_delete(self):
        self.app.delete()
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_disable(self):
        self.app.update(disabled_by_user=True)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_pending(self):
        self.app.update(status=amo.STATUS_PENDING)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile(pro='muahahah')
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_device_filter(self):
        result = self._field_to_native_profile(dev='android', device='mobile')
        eq_(len(result), 0)

    def test_field_to_native_platform_form_factor_filter(self):
        result = self._field_to_native_profile(platform='android',
                                               form_factor='tablet', dev=None)
        eq_(len(result), 0)
Esempio n. 14
0
class BaseTestCollectionMembershipField(object):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.app.addondevicetype_set.get_or_create(device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()

    def get_request(self, data=None):
        if data is None:
            data = {}
        request = RequestFactory().get("/", data)
        request.REGION = mkt.regions.RESTOFWORLD
        request.API = True
        return request

    def test_to_native(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2)
        apps = [self.app, self.app2]
        request = self.get_request({})
        resource = SimpleAppSerializer(apps)
        resource.context = {"request": request}
        self.field.context["request"] = request
        data = self.field.to_native(self.collection.apps())
        eq_(len(data), 2)
        eq_(data[0]["id"], int(self.app.pk))
        eq_(data[0]["resource_uri"], self.app.get_api_url(pk=self.app.pk))
        eq_(data[1]["id"], int(self.app2.id))
        eq_(data[1]["resource_uri"], self.app2.get_api_url(pk=self.app2.pk))

    def _field_to_native_profile(self, **kwargs):
        query = {"pro": "0.0", "dev": "firefoxos"}
        query.update(kwargs)
        request = self.get_request(query)
        self.field.parent = self.collection
        self.field.source = "apps"
        self.field.context["request"] = request

        return self.field.field_to_native(self.collection, "apps")

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.app2.addondevicetype_set.get_or_create(device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app2, order=0)
        self.app3 = amo.tests.app_factory()
        self.app3.addondevicetype_set.get_or_create(device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app3)
        result = self._field_to_native_profile()
        eq_(len(result), 3)
        eq_(int(result[0]["id"]), self.app2.id)
        eq_(int(result[1]["id"]), self.app.id)
        eq_(int(result[2]["id"]), self.app3.id)

    def test_app_delete(self):
        self.app.delete()
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_disable(self):
        self.app.update(disabled_by_user=True)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_pending(self):
        self.app.update(status=amo.STATUS_PENDING)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]["id"]), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile(pro="muahahah")
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]["id"]), self.app.id)

    def test_field_to_native_device_filter(self):
        result = self._field_to_native_profile(pro="muahahah", dev="android", device="mobile")
        eq_(len(result), 0)
Esempio n. 15
0
class BaseTestCollectionMembershipField(object):
    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.app.addondevicetype_set.get_or_create(
            device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()

    def get_request(self, data=None):
        if data is None:
            data = {}
        request = RequestFactory().get('/', data)
        request.REGION = mkt.regions.RESTOFWORLD
        request.API = True
        return request

    def test_to_native(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2)
        apps = [self.app, self.app2]
        request = self.get_request({})
        resource = SimpleAppSerializer(apps)
        resource.context = {'request': request}
        self.field.context['request'] = request
        data = self.field.to_native(self.collection.apps())
        eq_(len(data), 2)
        eq_(data[0]['id'], int(self.app.pk))
        eq_(data[0]['resource_uri'], self.app.get_api_url(pk=self.app.pk))
        eq_(data[1]['id'], int(self.app2.id))
        eq_(data[1]['resource_uri'], self.app2.get_api_url(pk=self.app2.pk))

    def _field_to_native_profile(self, **kwargs):
        query = {'pro': '0.0', 'dev': 'firefoxos'}
        query.update(kwargs)
        request = self.get_request(query)
        self.field.parent = self.collection
        self.field.source = 'apps'
        self.field.context['request'] = request

        return self.field.field_to_native(self.collection, 'apps')

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.app2.addondevicetype_set.get_or_create(
            device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app2, order=0)
        self.app3 = amo.tests.app_factory()
        self.app3.addondevicetype_set.get_or_create(
            device_type=amo.DEVICE_GAIA.id)
        self.collection.add_app(self.app3)
        result = self._field_to_native_profile()
        eq_(len(result), 3)
        eq_(int(result[0]['id']), self.app2.id)
        eq_(int(result[1]['id']), self.app.id)
        eq_(int(result[2]['id']), self.app3.id)

    def test_app_delete(self):
        self.app.delete()
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_disable(self):
        self.app.update(disabled_by_user=True)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_pending(self):
        self.app.update(status=amo.STATUS_PENDING)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(pro=self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile(pro='muahahah')
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_device_filter(self):
        result = self._field_to_native_profile(pro='muahahah',
                                               dev='android',
                                               device='mobile')
        eq_(len(result), 0)
Esempio n. 16
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.collection.add_app(self.app)
     self.field = CollectionMembershipField()
Esempio n. 17
0
class BaseTestCollectionMembershipField(object):

    def setUp(self):
        self.collection = Collection.objects.create(**self.collection_data)
        self.app = amo.tests.app_factory()
        self.collection.add_app(self.app, order=1)
        self.field = CollectionMembershipField()
        self.field.context = {}
        self.membership = CollectionMembership.objects.all()[0]
        self.profile = FeatureProfile(apps=True).to_signature()

    def get_request(self, query_string):
        request = RequestFactory().get('/', query_string)
        request.REGION = mkt.regions.WORLDWIDE
        request.API = True
        return request

    def test_to_native(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2)
        apps = [self.app, self.app2]
        request = self.get_request({})
        resource = SimpleAppSerializer(apps)
        resource.context = {'request': request}
        self.field.context['request'] = request
        data = self.field.to_native(self.collection.apps())
        eq_(len(data), 2)
        eq_(data[0]['id'], int(self.app.pk))
        eq_(data[0]['resource_uri'], self.app.get_api_url(pk=self.app.pk))
        eq_(data[1]['id'], int(self.app2.id))
        eq_(data[1]['resource_uri'], self.app2.get_api_url(pk=self.app2.pk))

    def _field_to_native_profile(self, profile='0.0'):
        request = self.get_request({'pro': profile, 'dev': 'firefoxos'})
        self.field.parent = self.collection
        self.field.source = 'apps'
        self.field.context['request'] = request

        return self.field.field_to_native(self.collection, 'apps')

    def test_ordering(self):
        self.app2 = amo.tests.app_factory()
        self.collection.add_app(self.app2, order=0)
        self.app3 = amo.tests.app_factory()
        self.collection.add_app(self.app3)
        result = self._field_to_native_profile()
        eq_(len(result), 3)
        eq_(int(result[0]['id']), self.app2.id)
        eq_(int(result[1]['id']), self.app.id)
        eq_(int(result[2]['id']), self.app3.id)

    def test_app_delete(self):
        self.app.delete()
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_disable(self):
        self.app.update(disabled_by_user=True)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_app_pending(self):
        self.app.update(status=amo.STATUS_PENDING)
        result = self._field_to_native_profile()
        eq_(len(result), 0)

    def test_field_to_native_profile(self):
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)

    def test_field_to_native_profile_mismatch(self):
        self.app.current_version.features.update(has_geolocation=True)
        result = self._field_to_native_profile(self.profile)
        eq_(len(result), 0)

    def test_field_to_native_invalid_profile(self):
        result = self._field_to_native_profile('muahahah')
        # Ensure that no filtering took place.
        eq_(len(result), 1)
        eq_(int(result[0]['id']), self.app.id)
Esempio n. 18
0
 def setUp(self):
     self.collection = Collection.objects.create(**self.collection_data)
     self.app = amo.tests.app_factory()
     self.collection.add_app(self.app)
     self.field = CollectionMembershipField()