Beispiel #1
0
    def test_a_3_003_pc_delete(self):
        pc1 = ProductCategory.query().get(1)
        pc1.delete()
        pcs = ProductCategory.query().all()

        self.assertEqual(len(pcs), 15)
        print("Test a_3_3: pc delete")
Beispiel #2
0
    def test_a_3_002_pc_update(self):
        pc1 = ProductCategory.query().get(1)
        #pc1.name = "modified"
        pc1.update(name="modified")
        pc_1 = ProductCategory.query().get(1)

        self.assertEqual(pc_1.name, "modified")
        print("Test a_3_2: pc update")
Beispiel #3
0
    def test_a_2_010_category_delete_relationships(self):
        products_before = len(Product.query().all())
        categories_before = len(Category.query().all())
        pc_before = len(ProductCategory.query().all())

        # deleting the product
        category_to_del = Category.query().get(1)

        category_to_del.delete()
        self.assertEqual(len(Product.query().all()), products_before)
        self.assertEqual(len(Category.query().all()), categories_before - 1)
        self.assertEqual(len(ProductCategory.query().all()), pc_before - 3)

        print("Test a_2_10: category delete relationships")
Beispiel #4
0
def delete_products_categories(request, id):
    try:
        pc = ProductCategoryExists(id=id)
    except Exception as e:
        return jsoinify_error(e)
    pc = ProductCategory.query().get(pc.id).delete()
    return {"suucess": True, "result": "Product Category deleted successfully"}
Beispiel #5
0
def get_products_categories(request, id):
    try:
        pc_id = ProductCategoryExists(id=id)
    except Exception as e:
        return jsoinify_error(e)
    pc = ProductCategory.query().get(pc_id.id)
    return {"suucess": True, "product_category": pc.deep()}
Beispiel #6
0
    def test_a_3_005_pc_values(self):
        pc = ProductCategory.query().get(1)
        self.assertEqual(pc.id, 1)
        self.assertEqual(pc.product_id, 1)
        self.assertEqual(pc.category_id, 1)
        #self.assertEqual(pc.parent,None)
        #self.assertEqual(str(pc.children),
        #	'[{"id": 2, "name": "Camera", "parent_id": 1}]')
        #print(pc.product.simple())
        self.assertEqual(
            pc.product.simple(), {
                'code': 789456611,
                'id': 1,
                'name': 'Cheese',
                'price': 50.4,
                'quantity': 7.89
            })
        #print(pc.category.simple())
        self.assertEqual(pc.category.simple(), {
            'id': 1,
            'name': 'Electronics',
            'parent_id': None
        })

        print("Test a_3_5: pc values")
Beispiel #7
0
    def test_a_1_010_product_delete_relationships(self):
        #measuring lengths beofre actions
        #populate_tables()
        products_before = len(Product.query().all())
        categories_before = len(Category.query().all())
        pc_before = len(ProductCategory.query().all())

        # deleting the product
        prod_to_del = Product.query().get(1)

        prod_to_del.delete()
        self.assertEqual(len(Product.query().all()), products_before - 1)
        self.assertEqual(len(Category.query().all()), categories_before)
        self.assertEqual(len(ProductCategory.query().all()), pc_before - 5)

        print("Test a_1_10: product delete relationships")
Beispiel #8
0
    def test_a_3_006_pc_insert_wrong(self):
        pcs = ProductCategory.query().all()
        old_records_number = len(pcs)
        try:
            #This code will not be executed
            #There are missing required parameters
            pc = ProductCategory()
            pc.insert()
            self.assertEqual(True, False)
        except Exception as e:
            self.assertEqual(str(e), "True != False")

        pcs = ProductCategory.query().all()
        new_records_number = len(pcs)

        self.assertEqual(old_records_number, new_records_number)
        print("Test a_3_6: pc insert with missing" + "required parameters")
Beispiel #9
0
    def test_a_3_001_pc_insert(self):
        db_drop_and_create_all()
        populate_tables()
        pc1 = ProductCategory(product_id=3, category_id=7)
        pc1.insert()
        pcs = ProductCategory.query().all()

        self.assertEqual(len(pcs), 16)
        print("Test a_3_1: pc insert")
Beispiel #10
0
    def test_a_3_007_pc_delete_wrong(self):
        pcs = ProductCategory.query().all()
        old_records_number = len(pcs)
        try:
            #This code will not be executed
            #There is no pc with the number 0
            pc1 = ProductCategory.query().get(0)
            pc1.delete()
            self.assertEqual(True, False)

        except Exception as e:
            self.assertEqual(
                str(e), "'NoneType' " + "object has no attribute 'delete'")
            #print(str(e))

        pcs = ProductCategory.query().all()
        new_records_number = len(pcs)

        self.assertEqual(old_records_number, new_records_number)
        print("Test a_3_7: pc delete mistake, non-existent" + "pc id")
Beispiel #11
0
    def category_id_validation(cls, value, values):
        validate_model_id_pydantic(Category, value)

        # Make sure that these values do not already exist
        if "product_id" in values:
            result = ProductCategory.query().filter(
                ProductCategory.category_id == value,
                ProductCategory.product_id == values["product_id"]).all()
            if len(result) != 0:
                raise ValueError("this product and this" +
                                 " category are already linked")
        return value
Beispiel #12
0
    def get_list(self, request):
        '''
        Returns a list of all the product categories supported by aWare
        '''
        categories = ProductCategory.query().fetch()

        collection = []
        for category in categories:
            msg = CategoryMessage()
            msg.key = category.key.urlsafe()
            msg.name = category.name
            collection.append(msg)

        return CategoriesCollection(items=collection)
Beispiel #13
0
    def test_a_3_011_pc_deep(self):
        #measuring lengths beofre actions
        pc = ProductCategory.query().get(5)
        #print(pc.deep())
        self.assertEqual(
            pc.deep(), {
                'category': {
                    'id': 5,
                    'name': 'Cars',
                    'parent_id': None
                },
                'category_id': 5,
                'id': 5,
                'product': {
                    'code': 789456611,
                    'id': 1,
                    'name': 'Cheese',
                    'price': 50.4,
                    'quantity': 7.89
                },
                'product_id': 1
            })

        print("Test a_3_11: pc deep")
Beispiel #14
0
def get_products_categories(request):
    all_pcs = ProductCategory.query().order_by("id").all()
    all_pcs = [category.simple() for category in all_pcs]
    return {"suucess": True, "categories": all_pcs}
Beispiel #15
0
 def test_a_3_009_pc_relationship_order(self):
     pc = ProductCategory.query().get(1)
     #pc.parent=None
     #pc = ProductCategory.query().get(4)
     print("Test a_3_9:pc relationship")
Beispiel #16
0
    def test_a_3_004_populate(self):
        populate_tables()
        pcs = ProductCategory.query().all()

        self.assertEqual(len(pcs), 15)
        print("Test a_3_4: Populate Tables")
Beispiel #17
0
    def test_a_3_008_pc_simple(self):
        pc = ProductCategory.query().get(1).simple()
        #print(pc)
        self.assertEqual(pc, {'category_id': 1, 'id': 1, 'product_id': 1})

        print("Test a_3_8: pc simple")