Exemplo n.º 1
0
def sync_products():
    cfg = config.get_candlepin_config_info()
    products = candlepin_client.get_products(
        host=cfg["host"],
        port=cfg["port"],
        username=cfg["username"],
        password=cfg["password"],
        https=cfg["https"],
        baseurl=cfg["url"],
    )
    for p in products:
        found = Product.objects(product_id=p.product_id).first()
        if found:
            if found.updated < p.updated:
                found.update_to(p)
                found.update()
        else:
            p.save()

    objs = Product.objects().only("product_id").all()
    db_product_ids = set([x.product_id for x in objs])
    source_product_ids = set([x.product_id for x in products])
    to_delete_ids = db_product_ids - source_product_ids
    for p_id in to_delete_ids:
        p = Pool.objects(product_id=p_id).first()
        p.delete()
Exemplo n.º 2
0
    def test_uploading_single_product(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"

        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)
        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.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')
Exemplo n.º 3
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
Exemplo n.º 4
0
    def test_example_with_raw_string_data(self):
        example = {"objects": [
            {
                "product_id": "a",
                "name": "prod_name_a",
                "engineering_ids": ["1"],
                "eng_prods": [],
                "attrs": {},
                "created": "2012-12-07T15:35:54.448000",
                "updated": "2012-12-07T15:35:54.448000",
            },
            {
                "product_id": "b",
                "name": "prod_name_b",
                "engineering_ids": ["3"],
                "eng_prods": [],
                "attrs": {},
                "created": "2012-12-07T15:35:54.448000",
                "updated": "2012-12-07T15:35:54.448000",
            },

        ]}
        post_data = json.dumps(example)
        resp = self.raw_api_client.post('/api/v1/product/', format='json', data=post_data,
            SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        self.assertEquals(resp.status_code, 204)
        found = Product.objects()
        self.assertEquals(len(found), 2)
        self.assertIn(found[0].product_id, ("a", "b"))
Exemplo n.º 5
0
 def test_get_product_collection(self):
     a = Product(product_id="a", name="namea", engineering_ids=["1"], eng_prods=[],
                 attrs={}, dependent_product_ids=[],
                 created="2012-12-06T11:13:06.432367+00:00",
                 updated="2012-12-06T11:13:06.432367+00:00")
     a.save()
     b = Product(product_id="b", name="nameb", engineering_ids=["1"], eng_prods=[],
                 attrs={}, dependent_product_ids=[],
                 created="2012-12-06T11:13:06.432367+00:00",
                 updated="2012-12-06T11:13:06.432367+00:00")
     b.save()
     resp = self.api_client.get('/api/v1/product/', format='json',
         SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
     self.assertEquals(resp.status_code, 200)
     LOG.info("Status Code: %s, Response: %s" % (resp.status_code, resp))
     found = Product.objects()
     self.assertEquals(len(found), 2)
Exemplo n.º 6
0
 def get_existing(self, obj):
     return Product.objects(product_id=obj.product_id).first()
Exemplo n.º 7
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")
Exemplo n.º 8
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')