Пример #1
0
def translate_products(data):
    products = []
    for item in data:
        product = Product()
        product.created = convert_to_datetime(item["created"])
        product.updated = convert_to_datetime(item["updated"])
        product.product_id = item["id"]
        product.name = item["name"]
        for attribute in item["attributes"]:
            # Expecting values for "type", "arch", "name"
            product.attrs[attribute["name"]] = attribute["value"]
        eng_prods = []
        eng_ids = []
        for prod_cnt in item["productContent"]:
            ep = dict()
            ep["id"] = prod_cnt["content"]["id"]
            ep["label"] = prod_cnt["content"]["label"]
            ep["name"] = prod_cnt["content"]["name"]
            ep["vendor"] = prod_cnt["content"]["vendor"]
            eng_prods.append(ep)
            eng_ids.append(ep["id"])
        product.eng_prods = eng_prods
        product.engineering_ids = eng_ids
        product.dependent_product_ids = item["dependentProductIds"]
        products.append(product)
    return products
Пример #2
0
    def test_date_as_string_is_converted_on_save(self):
        found = Product.objects()
        self.assertEquals(len(found), 0)

        p = Product()
        p.product_id = "pid"
        p.name = "pname"
        p.engineering_ids = ["3", "5"]
        p.created = "2012-12-06T11:13:06.432367+00:00"
        p.updated = "2012-12-06T11:13:06.432367+00:00"
        p.eng_prods = []
        p.attrs = {}
        p.dependent_product_ids = []
        p.save()

        found = Product.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].product_id, p.product_id)
        self.assertEquals(found[0].name, p.name)
        self.assertEquals(found[0].engineering_ids, p.engineering_ids)
        self.assertEquals(found[0].eng_prods, p.eng_prods)
        self.assertEquals(found[0].attrs, p.attrs)
        self.assertEquals(found[0].dependent_product_ids, p.dependent_product_ids)
        self.assertIsNotNone(found[0].created)
        self.assertEquals(type(found[0].created), datetime.datetime)
        self.assertIsNotNone(found[0].updated)
        self.assertEquals(type(found[0].updated), datetime.datetime)
        self.assertEquals(str(found[0].created), "2012-12-06 11:13:06.432000+00:00")
        self.assertEquals(str(found[0].updated), "2012-12-06 11:13:06.432000+00:00")
Пример #3
0
    def test_uploading_duplicate(self):
        found = Product.objects()
        self.assertEquals(len(found), 0)

        p = Product()
        p.product_id = "a"
        p.name = "a_name"
        p.engineering_ids = ["1"]
        p.eng_prods = []
        p.attrs = {}
        p.created = "2012-12-07T15:35:54.448000"
        p.updated = "2012-12-07T15:35:54.448000"
        p.save()  # <- This is the big difference from test_uploading_single_product

        example = {"objects":[p]}
        post_data = utils.obj_to_json(example)
        LOG.info("Calling api for product import with post data: '%s'" % (post_data))
        resp = self.raw_api_client.post('/api/v1/product/', format='json', data=post_data,
                                        SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        LOG.info("Status Code: %s, Response: %s" % (resp.status_code, resp))
        self.assertEquals(resp.status_code, 204)
        # Now check that the server api saved the object as expected
        found = Product.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].product_id, p.product_id)
Пример #4
0
    def test_upload_newer_product(self):
        found = Product.objects()
        self.assertEquals(len(found), 0)
        # Create 'older' which is one month older than newer
        older = Product()
        older.product_id = "a"
        older.name = "old name"
        older.engineering_ids = ["old1"]
        older.eng_prods = [{"more old info": 1}]
        older.attrs = {"old": "info"}
        older.created = "2012-10-01T01:01:01.111111"
        older.updated = "2012-10-01T01:01:01.111111"
        older.save()
        found = Product.objects()
        self.assertEquals(len(found), 1)

        newer = Product()
        newer.product_id = "a"
        newer.name = "a_name"
        newer.engineering_ids = ["1"]
        newer.eng_prods = [{"new_info": 5}]
        newer.attrs = {}
        newer.created = "2012-12-07T15:35:54.448000"
        newer.updated = "2012-12-07T15:35:54.448000"

        example = {"objects":[newer]}
        post_data = utils.obj_to_json(example)
        LOG.info("Calling api for product import with post data: '%s'" % (post_data))
        resp = self.raw_api_client.post('/api/v1/product/', format='json', data=post_data,
                                        SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        LOG.info("Status Code: %s, Response: %s" % (resp.status_code, resp))
        self.assertEquals(resp.status_code, 204)
        # Now check that the server api saved the object as expected
        found = Product.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].product_id, newer.product_id)
        self.assertEquals(found[0].name, newer.name)
        self.assertEquals(found[0].engineering_ids, newer.engineering_ids)
        self.assertEquals(found[0].eng_prods, newer.eng_prods)
        self.assertIsNotNone(found[0].created)
        self.assertEquals(str(found[0].created), '2012-12-07 15:35:54.448000+00:00')
        self.assertIsNotNone(found[0].updated)
        self.assertEquals(str(found[0].updated), '2012-12-07 15:35:54.448000+00:00')