Example #1
0
    def test_deserialize_limit(self):
        apps = [amo.tests.app_factory(), amo.tests.app_factory()]
        app_map = dict((app.id, app.get_indexer().extract_document(app.id)) for app in apps)
        field = AppESField(many=True, limit=1)
        field.context = {"app_map": app_map, "request": amo.tests.req_factory_factory("")}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 1)
        eq_(data[0]["id"], apps[0].id)

        field.limit = 0
        data = field.to_native([app.id for app in apps])
        eq_(len(data), 0)
Example #2
0
    def test_deserialize_limit(self):
        apps = [mkt.site.tests.app_factory(), mkt.site.tests.app_factory()]
        app_map = dict((app.id, app.get_indexer().extract_document(app.id))
                       for app in apps)
        field = AppESField(many=True, limit=1)
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 1)
        eq_(data[0]['id'], apps[0].id)

        field.limit = 0
        data = field.to_native([app.id for app in apps])
        eq_(len(data), 0)
Example #3
0
    def test_deserialize_limit(self):
        apps = [mkt.site.tests.app_factory(), mkt.site.tests.app_factory()]
        app_map = dict((app.id, app.get_indexer().extract_document(app.id))
                       for app in apps)
        field = AppESField(many=True, limit=1)
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 1)
        eq_(data[0]['id'], apps[0].id)

        field.limit = 0
        data = field.to_native([app.id for app in apps])
        eq_(len(data), 0)
Example #4
0
    def test_deserialize_single(self):
        app = amo.tests.app_factory(description={"en-US": "lol"})
        app_map = {app.id: app.get_indexer().extract_document(app.id)}
        field = AppESField(source="app")
        field.context = {"app_map": app_map, "request": amo.tests.req_factory_factory("")}
        data = field.to_native(app.id)

        eq_(data["id"], app.id)
        eq_(data["slug"], app.app_slug)
        eq_(data["description"], {"en-US": "lol"})
Example #5
0
    def test_no_exist(self):
        """
        Handle when the app is not in the app map (as result of filtering).
        """
        app = mkt.site.tests.app_factory()

        field = AppESField()
        field.context = {'app_map': {},
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native(app.id)
        ok_(not data)
Example #6
0
    def test_deserialize_single(self):
        app = mkt.site.tests.app_factory(description={'en-US': 'lol'})
        app_map = {app.id: app.get_indexer().extract_document(app.id)}
        field = AppESField(source='app')
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native(app.id)

        eq_(data['id'], app.id)
        eq_(data['slug'], app.app_slug)
        eq_(data['description'], {'en-US': 'lol'})
Example #7
0
    def test_no_exist(self):
        """
        Handle when the app is not in the app map (as result of filtering).
        """
        app = mkt.site.tests.app_factory()

        field = AppESField()
        field.context = {'app_map': {},
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native(app.id)
        ok_(not data)
Example #8
0
    def test_deserialize_single(self):
        app = mkt.site.tests.app_factory(description={'en-US': 'lol'})
        app_map = {app.id: app.get_indexer().extract_document(app.id)}
        field = AppESField(source='app')
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native(app.id)

        eq_(data['id'], app.id)
        eq_(data['slug'], app.app_slug)
        eq_(data['description'], {'en-US': 'lol'})
    def test_deserialize_multi(self):
        apps = [amo.tests.app_factory(), amo.tests.app_factory()]
        app_map = dict((app.id, app.get_indexer().extract_document(app.id))
                       for app in apps)
        field = AppESField(many=True)
        field.context = {'app_map': app_map,
                         'request': amo.tests.req_factory_factory('')}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 2)
        eq_(data[0]['id'], apps[0].id)
        eq_(data[1]['id'], apps[1].id)
Example #10
0
    def test_deserialize_multi(self):
        apps = [amo.tests.app_factory(), amo.tests.app_factory()]
        app_map = dict((app.id, app.get_indexer().extract_document(app.id))
                       for app in apps)
        field = AppESField(many=True)
        field.context = {
            'app_map': app_map,
            'request': amo.tests.req_factory_factory('')
        }
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 2)
        eq_(data[0]['id'], apps[0].id)
        eq_(data[1]['id'], apps[1].id)
Example #11
0
    def test_multi_no_exist(self):
        """
        Handle when the app is not in the app map (as result of filtering).
        """
        apps = [mkt.site.tests.app_factory(), mkt.site.tests.app_factory()]
        app_map = {
            apps[0].id: apps[0].get_indexer().extract_document(apps[0].id)
        }

        field = AppESField(many=True)
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 1)
        eq_(data[0]['id'], apps[0].id)
Example #12
0
    def test_multi_no_exist(self):
        """
        Handle when the app is not in the app map (as result of filtering).
        """
        apps = [mkt.site.tests.app_factory(), mkt.site.tests.app_factory()]
        app_map = {
            apps[0].id: apps[0].get_indexer().extract_document(apps[0].id)
        }

        field = AppESField(many=True)
        field.context = {'app_map': app_map,
                         'request': mkt.site.tests.req_factory_factory('')}
        data = field.to_native([app.id for app in apps])

        eq_(len(data), 1)
        eq_(data[0]['id'], apps[0].id)