Ejemplo n.º 1
0
    def test_post_bad_product_name(self):
        products = Products(config=self.config)

        ok_(not products.post(
            product='Spaces not allowed',
            version='',
        ))
Ejemplo n.º 2
0
    def test_get_default_version(self):
        products = Products(config=self.config)

        # Test 1: default versions for all existing products
        res = products.get_default_version()
        res_expected = {
            "hits": {
                "Firefox": "8.0",
                "Thunderbird": "10.0.2b",
                "Fennec": "12.0b1",
            }
        }

        eq_(res, res_expected)

        # Test 2: default version for one product
        params = {"products": "Firefox"}
        res = products.get_default_version(**params)
        res_expected = {"hits": {"Firefox": "8.0"}}

        eq_(res, res_expected)

        # Test 3: default version for two products
        params = {"products": ["Firefox", "Thunderbird"]}
        res = products.get_default_version(**params)
        res_expected = {"hits": {"Firefox": "8.0", "Thunderbird": "10.0.2b"}}

        eq_(res, res_expected)
Ejemplo n.º 3
0
    def test_post_bad_product_name(self):
        products = Products(config=self.config)

        ok_(not products.post(
            product='Spaces not allowed',
            version='',
        ))
Ejemplo n.º 4
0
    def test_post_bad_product_name(self):
        products = Products(config=self.config)

        build_id = self.now.strftime('%Y%m%d%H%M')
        ok_(not products.post(
            product='Spaces not allowed',
            version='',
        ))
Ejemplo n.º 5
0
    def test_post_bad_product_name(self):
        products = Products(config=self.config)

        build_id = self.now.strftime('%Y%m%d%H%M')
        ok_(not products.post(
            product='Spaces not allowed',
            version='',
        ))
Ejemplo n.º 6
0
    def test_post(self):
        products = Products(config=self.config)

        ok_(products.post(product="KillerApp", version="1.0"))

        # let's check certain things got written to certain tables
        cursor = self.connection.cursor()
        try:
            # expect there to be a new product
            cursor.execute("select product_name from products " "where product_name=%s", ("KillerApp",))
            product_name, = cursor.fetchone()
            eq_(product_name, "KillerApp")
        finally:
            self.connection.rollback()
Ejemplo n.º 7
0
    def test_get_webapp_products(self):
        api = Products(config=self.config)

        res = api.get(type='webapp')
        res_expected = {
            'products': ['ClockOClock', 'EmailApp'],
            'hits': {
                'EmailApp': [
                    {
                        "product": "EmailApp",
                        "version": "0.2",
                        "start_date": None,
                        "end_date": None,
                        "throttle": 1.0,
                        "featured": False,
                        "release": "Beta",
                        "has_builds": False
                    },
                    {
                        "product": "EmailApp",
                        "version": "0.1",
                        "start_date": None,
                        "end_date": None,
                        "throttle": 1.0,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False
                    }
                ],
                'ClockOClock': [
                    {
                        "product": "ClockOClock",
                        "version": "1.0.18",
                        "start_date": None,
                        "end_date": None,
                        "throttle": 1.0,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False
                    }
                ]
            },
            'total': 3
        }
        self.assertEqual(res, res_expected)
Ejemplo n.º 8
0
    def test_post(self):
        products = Products(config=self.config)

        ok_(products.post(
            product='KillerApp',
            version='1.0',
        ))

        # let's check certain things got written to certain tables
        cursor = self.connection.cursor()
        try:
            # expect there to be a new product
            cursor.execute(
                'select product_name from products '
                "where product_name=%s", ('KillerApp', ))
            product_name, = cursor.fetchone()
            eq_(product_name, 'KillerApp')
        finally:
            self.connection.rollback()
Ejemplo n.º 9
0
    def test_post(self):
        products = Products(config=self.config)

        build_id = self.now.strftime('%Y%m%d%H%M')
        ok_(products.post(
            product='KillerApp',
            version='1.0',
        ))

        # let's check certain things got written to certain tables
        cursor = self.connection.cursor()
        try:
            # expect there to be a new product
            cursor.execute(
                'select product_name from products '
                "where product_name=%s",
                ('KillerApp',)
            )
            product_name, = cursor.fetchone()
            eq_(product_name, 'KillerApp')
        finally:
            self.connection.rollback()
Ejemplo n.º 10
0
    def test_get_default_version(self):
        products = Products(config=self.config)

        # Test 1: default versions for all existing products
        res = products.get_default_version()
        res_expected = {"hits": {"Firefox": "8.0", "Thunderbird": "10.0.2b", "Fennec": "12.0b1"}}

        eq_(res, res_expected)

        # Test 2: default version for one product
        params = {"products": "Firefox"}
        res = products.get_default_version(**params)
        res_expected = {"hits": {"Firefox": "8.0"}}

        eq_(res, res_expected)

        # Test 3: default version for two products
        params = {"products": ["Firefox", "Thunderbird"]}
        res = products.get_default_version(**params)
        res_expected = {"hits": {"Firefox": "8.0", "Thunderbird": "10.0.2b"}}

        eq_(res, res_expected)
Ejemplo n.º 11
0
    def update_featured(self, **kwargs):
        """Update lists of featured versions. """
        products_list = Products(config=self.context).get()['products']
        releases = {}

        for p in kwargs:
            if p in products_list:
                if isinstance(kwargs[p], basestring):
                    # Assuming `,` for now, see
                    # https://bugzilla.mozilla.org/show_bug.cgi?id=787233
                    releases[p] = kwargs[p].split(',')
                else:
                    releases[p] = kwargs[p]

        if len(releases) == 0:
            return False

        sql = """/* socorro.external.postgresql.releases.update_featured */
            SELECT edit_featured_versions(%%s, %s)
        """
        error_message = "Failed updating featured versions in PostgreSQL"

        with self.get_connection() as connection:
            try:
                cursor = connection.cursor()

                for p in releases:
                    query = sql % ", ".join(
                        "%s" for i in xrange(len(releases[p]))
                    )
                    sql_params = [p] + releases[p]
                    # logger.debug(cursor.mogrify(query, sql_params))
                    cursor.execute(query, sql_params)

                connection.commit()
            except psycopg2.Error:
                connection.rollback()
                logger.error(error_message)
                raise DatabaseError(error_message)

        return True
Ejemplo n.º 12
0
    def update_featured(self, **kwargs):
        """Update lists of featured versions. """
        products_dict = Products(config=self.context).get()
        products_list = [i["product_name"] for i in products_dict["hits"]]
        logger.debug(products_list)
        releases = {}

        for p in kwargs:
            if p in products_list:
                releases[p] = kwargs[p]

        if len(releases) == 0:
            return False

        sql = """/* socorro.external.postgresql.releases.update_featured */
            SELECT edit_featured_versions(%%s, %s)
        """

        try:
            connection = self.database.connection()
            cur = connection.cursor()

            for p in releases:
                query = sql % ", ".join("%s" for i in xrange(len(releases[p])))
                sql_params = [p] + releases[p]
                logger.debug(cur.mogrify(query, sql_params))
                cur.execute(query, sql_params)

            connection.commit()
        except psycopg2.Error:
            connection.rollback()
            logger.error("Failed updating featured versions in PostgreSQL")
            raise
        finally:
            connection.close()

        return True
Ejemplo n.º 13
0
    def test_get(self):
        products = Products(config=self.config)
        now = datetimeutil.utc_now().date()
        lastweek = now - datetime.timedelta(days=7)
        now_str = datetimeutil.date_to_string(now)
        lastweek_str = datetimeutil.date_to_string(lastweek)

        #......................................................................
        # Test 1: find one exact match for one product and one version
        params = {"versions": "Firefox:8.0"}
        res = products.get(**params)
        res_expected = {
            "hits": [{
                "product": "Firefox",
                "version": "8.0",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }],
            "total":
            1
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 2: Find two different products with their correct verions
        params = {"versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]}
        res = products.get(**params)
        res_expected = {
            "hits": [{
                "product": "Firefox",
                "version": "8.0",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }, {
                "product": "Thunderbird",
                "version": "10.0.2b",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }],
            "total":
            2
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 3: empty result, no products:version found
        params = {"versions": "Firefox:14.0"}
        res = products.get(**params)
        res_expected = {"hits": [], "total": 0}

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 4: Test products list is returned with no parameters
        # Note that the expired version is not returned
        params = {}
        res = products.get(**params)
        res_expected = {
            "products": ["Firefox", "Thunderbird", "Fennec"],
            "hits": {
                "Firefox": [{
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False
                }],
                "Thunderbird": [{
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False,
                }],
                "Fennec": [{
                    "product": "Fennec",
                    "version": "11.0.1",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False
                }]
            },
            "total": 3
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 5: An unvalid versions list is passed, all versions are returned
        params = {'versions': [1]}
        res = products.get(**params)
        res_expected = {
            "hits": [{
                "product": "Fennec",
                "version": "11.0.1",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }, {
                "product": "Firefox",
                "version": "8.0",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }, {
                "product": "Thunderbird",
                "version": "10.0.2b",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }],
            "total":
            3
        }

        self.assertEqual(res, res_expected)
Ejemplo n.º 14
0
    def test_get(self):
        products = Products(config=self.config)
        now = datetimeutil.utc_now().date()
        lastweek = now - datetime.timedelta(days=7)
        now_str = datetimeutil.date_to_string(now)
        lastweek_str = datetimeutil.date_to_string(lastweek)

        #......................................................................
        # Test 1: find one exact match for one product and one version
        params = {
            "versions": "Firefox:8.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                 }
            ],
            "total": 1
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 2: Find two different products with their correct verions
        params = {
            "versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                 },
                 {
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                 }
            ],
            "total": 2
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 3: empty result, no products:version found
        params = {
            "versions": "Firefox:14.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [],
            "total": 0
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 4: Test products list is returned with no parameters
        # Note that the expired version is not returned
        params = {}
        res = products.get(**params)
        res_expected = {
                "products": ["Firefox", "Thunderbird", "Fennec"],
                "hits": {
                    "Firefox": [
                        {
                            "product": "Firefox",
                            "version": "8.0",
                            "start_date": now_str,
                            "end_date": now_str,
                            "throttle": 10.00,
                            "featured": False,
                            "release": "Release",
                            "has_builds": False
                        }
                    ],
                    "Thunderbird": [
                        {
                            "product": "Thunderbird",
                            "version": "10.0.2b",
                            "start_date": now_str,
                            "end_date": now_str,
                            "throttle": 10.00,
                            "featured": False,
                            "release": "Release",
                            "has_builds": False,
                        }
                    ],
                    "Fennec": [
                        {
                            "product": "Fennec",
                            "version": "11.0.1",
                            "start_date": now_str,
                            "end_date": now_str,
                            "throttle": 10.00,
                            "featured": False,
                            "release": "Release",
                            "has_builds": False
                        }
                    ]
                },
                "total": 3
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 5: An unvalid versions list is passed, all versions are returned
        params = {
            'versions': [1]
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Fennec",
                    "version": "11.0.1",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                },
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                 },
                 {
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                 }
            ],
            "total": 3
        }

        self.assertEqual(res, res_expected)
Ejemplo n.º 15
0
    def test_get(self):
        products = Products(config=self.config)
        now = datetimeutil.utc_now()
        now = datetime.datetime(now.year, now.month, now.day)
        now_str = datetimeutil.date_to_string(now)

        #......................................................................
        # Test 1: find one exact match for one product and one version
        params = {
            "versions": "Firefox:8.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0
                 }
            ],
            "total": 1
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 2: Find two different products with their correct verions
        params = {
            "versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0
                 },
                 {
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0
                 }
            ],
            "total": 2
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 3: empty result, no products:version found
        params = {
            "versions": "Firefox:14.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [],
            "total": 0
        }

        self.assertEqual(res, res_expected)

        #......................................................................
        # Test 4: Test products list is returned with no parameters
        params = {}
        res = products.get(**params)
        res_expected = {
                "hits": [
                    {
                        "product_name": "Firefox",
                        "release_name": "firefox",
                        "sort": 1,
                        "rapid_release_version": "8.0"
                     },
                    {
                        "product_name": "Fennec",
                        "release_name": "mobile",
                        "sort": 3,
                        "rapid_release_version": "11.0"
                     },
                    {
                        "product_name": "Thunderbird",
                        "release_name": "thunderbird",
                        "sort": 2,
                        "rapid_release_version": "10.0"
                     }
                ],
                "total": 3
        }
        
        self.assertEqual(res, res_expected)
Ejemplo n.º 16
0
    def test_get(self):
        products = Products(config=self.config)
        now = self.now.date()
        now_str = datetimeutil.date_to_string(now)

        # ......................................................................
        # Test 1: find one exact match for one product and one version
        params = {"versions": "Firefox:8.0"}
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "is_featured": False,
                    "version": "8.0",
                    "throttle": 10.0,
                    "start_date": now_str,
                    "end_date": now_str,
                    "has_builds": False,
                    "product": "Firefox",
                    "build_type": "Release",
                }
            ],
            "total": 1,
        }

        eq_(sorted(res["hits"][0]), sorted(res_expected["hits"][0]))

        # ......................................................................
        # Test 2: Find two different products with their correct verions
        params = {"versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]}
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False,
                },
                {
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False,
                },
            ],
            "total": 2,
        }

        eq_(sorted(res["hits"][0]), sorted(res_expected["hits"][0]))

        # ......................................................................
        # Test 3: empty result, no products:version found
        params = {"versions": "Firefox:14.0"}
        res = products.get(**params)
        res_expected = {"hits": [], "total": 0}

        eq_(res, res_expected)

        # ......................................................................
        # Test 4: Test products list is returned with no parameters
        # Note that the expired version is not returned
        params = {}
        res = products.get(**params)
        res_expected = {
            "products": ["Firefox", "Thunderbird", "Fennec"],
            "hits": {
                "Firefox": [
                    {
                        "product": "Firefox",
                        "version": "8.0",
                        "start_date": now_str,
                        "end_date": now_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False,
                    }
                ],
                "Thunderbird": [
                    {
                        "product": "Thunderbird",
                        "version": "10.0.2b",
                        "start_date": now_str,
                        "end_date": now_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False,
                    }
                ],
                "Fennec": [
                    {
                        "product": "Fennec",
                        "version": "12.0b1",
                        "start_date": now_str,
                        "end_date": now_str,
                        "throttle": 100.00,
                        "featured": False,
                        "release": "Beta",
                        "has_builds": False,
                    },
                    {
                        "product": "Fennec",
                        "version": "11.0.1",
                        "start_date": now_str,
                        "end_date": now_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False,
                    },
                ],
            },
            "total": 4,
        }

        eq_(res["total"], res_expected["total"])
        eq_(sorted(res["products"]), sorted(res_expected["products"]))
        eq_(sorted(res["hits"]), sorted(res_expected["hits"]))
        for product in sorted(res["hits"].keys()):
            eq_(sorted(res["hits"][product][0]), sorted(res_expected["hits"][product][0]))

        # test returned order of versions
        assert len(res["hits"]["Fennec"]) == 2
        eq_(res["hits"]["Fennec"][0]["version"], "12.0b1")
        eq_(res["hits"]["Fennec"][1]["version"], "11.0.1")

        # ......................................................................
        # Test 5: An invalid versions list is passed, all versions are returned
        params = {"versions": [1]}
        res = products.get(**params)
        eq_(res["total"], 4)
Ejemplo n.º 17
0
    def test_get(self):
        products = Products(config=self.config)
        now = self.now.date()
        lastweek = now - datetime.timedelta(days=7)
        nextweek = now + datetime.timedelta(days=7)
        now_str = datetimeutil.date_to_string(now)
        lastweek_str = datetimeutil.date_to_string(lastweek)
        nextweek_str = datetimeutil.date_to_string(nextweek)

        #......................................................................
        # Test 1: find one exact match for one product and one version
        params = {
            "versions": "Firefox:8.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "is_featured": False,
                    "version": "8.0",
                    "throttle": 10.0,
                    "start_date": now_str,
                    "end_date": now_str,
                    "has_builds": False,
                    "product": "Firefox",
                    "build_type": "Release"
                }
            ],
            "total": 1
        }
        # make sure the 'throttle' is a floating point number
        ok_(isinstance(res['hits'][0]['throttle'], float))
        eq_(
            sorted(res['hits'][0]),
            sorted(res_expected['hits'][0])
        )

        #......................................................................
        # Test 2: Find two different products with their correct verions
        params = {
            "versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]
        }
        res = products.get(**params)
        res_expected = {
            "hits": [
                {
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": True
                },
                {
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "is_featured": False,
                    "build_type": "Release",
                    "throttle": 10.0,
                    "has_builds": False
                }
            ],
            "total": 2
        }

        eq_(
            sorted(res['hits'][0]),
            sorted(res_expected['hits'][0])
        )

        #......................................................................
        # Test 3: empty result, no products:version found
        params = {
            "versions": "Firefox:14.0"
        }
        res = products.get(**params)
        res_expected = {
            "hits": [],
            "total": 0
        }

        eq_(res, res_expected)

        #......................................................................
        # Test 4: Test products list is returned with no parameters
        params = {}
        res = products.get(**params)
        res_expected = {
            "products": ["Firefox", "Thunderbird", "Fennec"],
            "hits": {
                "Firefox": [
                    {
                        "product": "Firefox",
                        "version": "9.0",
                        "start_date": now_str,
                        "end_date": nextweek_str,
                        "throttle": 100.00,
                        "featured": True,
                        "release": "Nightly",
                        "has_builds": True
                    },
                    {
                        "product": "Firefox",
                        "version": "8.0",
                        "start_date": lastweek_str,
                        "end_date": lastweek_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False
                    }
                ],
                "Thunderbird": [
                    {
                        "product": "Thunderbird",
                        "version": "10.0.2b",
                        "start_date": now_str,
                        "end_date": nextweek_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False,
                    }
                ],
                "Fennec": [
                    {
                        "product": "Fennec",
                        "version": "12.0b1",
                        "start_date": now_str,
                        "end_date": nextweek_str,
                        "throttle": 100.00,
                        "featured": False,
                        "release": "Beta",
                        "has_builds": True
                    },
                    {
                        "product": "Fennec",
                        "version": "11.0.1",
                        "start_date": now_str,
                        "end_date": now_str,
                        "throttle": 10.00,
                        "featured": False,
                        "release": "Release",
                        "has_builds": False
                    }
                ]
            },
            "total": 5
        }

        eq_(res['total'], res_expected['total'])
        eq_(
            sorted(res['products']),
            sorted(res_expected['products'])
        )
        eq_(sorted(res['hits']), sorted(res_expected['hits']))
        for product in sorted(res['hits'].keys()):
            eq_(
                sorted(res['hits'][product][0]),
                sorted(res_expected['hits'][product][0])
            )
            eq_(res['hits'][product], res_expected['hits'][product])

        # test returned order of versions
        assert len(res['hits']['Fennec']) == 2
        eq_(res['hits']['Fennec'][0]['version'], '12.0b1')
        eq_(res['hits']['Fennec'][1]['version'], '11.0.1')

        #......................................................................
        # Test 5: An invalid versions list is passed, all versions are returned
        params = {
            'versions': [1]
        }
        res = products.get(**params)
        eq_(res['total'], 5)
Ejemplo n.º 18
0
    def test_get(self):
        products = Products(config=self.config)
        now = self.now.date()
        now_str = datetimeutil.date_to_string(now)

        #......................................................................
        # Test 1: find one exact match for one product and one version
        params = {"versions": "Firefox:8.0"}
        res = products.get(**params)
        res_expected = {
            "hits": [{
                "is_featured": False,
                "version": "8.0",
                "throttle": 10.0,
                "start_date": now_str,
                "end_date": now_str,
                "has_builds": False,
                "product": "Firefox",
                "build_type": "Release"
            }],
            "total":
            1
        }

        eq_(sorted(res['hits'][0]), sorted(res_expected['hits'][0]))

        #......................................................................
        # Test 2: Find two different products with their correct verions
        params = {"versions": ["Firefox:8.0", "Thunderbird:10.0.2b"]}
        res = products.get(**params)
        res_expected = {
            "hits": [{
                "product": "Firefox",
                "version": "8.0",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }, {
                "product": "Thunderbird",
                "version": "10.0.2b",
                "start_date": now_str,
                "end_date": now_str,
                "is_featured": False,
                "build_type": "Release",
                "throttle": 10.0,
                "has_builds": False
            }],
            "total":
            2
        }

        eq_(sorted(res['hits'][0]), sorted(res_expected['hits'][0]))

        #......................................................................
        # Test 3: empty result, no products:version found
        params = {"versions": "Firefox:14.0"}
        res = products.get(**params)
        res_expected = {"hits": [], "total": 0}

        eq_(res, res_expected)

        #......................................................................
        # Test 4: Test products list is returned with no parameters
        # Note that the expired version is not returned
        params = {}
        res = products.get(**params)
        res_expected = {
            "products": ["Firefox", "Thunderbird", "Fennec"],
            "hits": {
                "Firefox": [{
                    "product": "Firefox",
                    "version": "8.0",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False
                }],
                "Thunderbird": [{
                    "product": "Thunderbird",
                    "version": "10.0.2b",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False,
                }],
                "Fennec": [{
                    "product": "Fennec",
                    "version": "12.0b1",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 100.00,
                    "featured": False,
                    "release": "Beta",
                    "has_builds": False
                }, {
                    "product": "Fennec",
                    "version": "11.0.1",
                    "start_date": now_str,
                    "end_date": now_str,
                    "throttle": 10.00,
                    "featured": False,
                    "release": "Release",
                    "has_builds": False
                }]
            },
            "total": 4
        }

        eq_(res['total'], res_expected['total'])
        eq_(sorted(res['products']), sorted(res_expected['products']))
        eq_(sorted(res['hits']), sorted(res_expected['hits']))
        for product in sorted(res['hits'].keys()):
            eq_(sorted(res['hits'][product][0]),
                sorted(res_expected['hits'][product][0]))

        # test returned order of versions
        assert len(res['hits']['Fennec']) == 2
        eq_(res['hits']['Fennec'][0]['version'], '12.0b1')
        eq_(res['hits']['Fennec'][1]['version'], '11.0.1')

        #......................................................................
        # Test 5: An invalid versions list is passed, all versions are returned
        params = {'versions': [1]}
        res = products.get(**params)
        eq_(res['total'], 4)