Exemple #1
0
    def test_polymorphism(self):
        """Test polymorphism of products """
        ##Creates categories
        cat1 = cmod.Category()
        cat1.code = 'brass'
        cat1.name = 'Brass Instruments'
        cat1.save()

        cat2 = cmod.Category()
        cat2.code = 'woodwind'
        cat2.name = 'Woodwind Instruments'
        cat2.save()

        cat3 = cmod.Category()
        cat3.code = 'string'
        cat3.name = 'String Instruments'
        cat3.save()

        #Creates conditions
        con1 = cmod.Condition()
        con1.name = 'Poor'
        con1.save()

        con2 = cmod.Condition()
        con2.name = 'Good'
        con2.save()

        con3 = cmod.Condition()
        con3.name = 'Excellent'
        con3.save()

        ##Creates a unique product
        up1 = cmod.UniqueProduct()
        up1.category = cat1
        up1.name = 'Trumpet'
        up1.brand = 'Yamaha'
        up1.price = Decimal('899.99')
        up1.serial_number = '747amfhuefhi'
        up1.save()

        ##Creates a rental product
        rp1 = cmod.RentalProduct()
        rp1.category = cat3
        rp1.name = 'Trombone'
        rp1.brand = 'Yamaha'
        rp1.price = Decimal('1029.99')
        rp1.serial_number = '0348dsaiopjd'
        rp1.condition = con2
        rp1.save()

        #pull back off of the database
        brand1 = up1.brand
        brand2 = rp1.brand
        self.assertEqual(brand1, brand2)
Exemple #2
0
def seeded_session(database):
    from catalog.database import Session
    try:
        session = Session()
        session.add(models.User(username='******', email='*****@*****.**'))
        session.add(
            models.User(username='******', email='*****@*****.**'))

        session.add(
            models.Category(name='Football',
                            description='The real one from Europe.',
                            owner_id=2))

        session.add(
            models.Item(name='Football ball',
                        description='Rather hard to play without one init?',
                        category_id=1))
        session.add(
            models.Item(name='Arsenal Jersey',
                        description='You still there Arsene?',
                        category_id=1))
        session.add(
            models.Item(name='Drama Classes',
                        description=
                        'Falling on the grass is an art. It takes practice to '
                        'master it.',
                        category_id=1))

        session.add(
            models.Category(name='Boxing',
                            description='If you'
                            're up for a good fight.',
                            owner_id=2))

        session.add(
            models.Item(name='Gloves',
                        description='We'
                        're fighters here, not brute.',
                        category_id=2))
        session.add(
            models.Item(name='Jumping Rope',
                        description='Just like Rocky.',
                        category_id=2))
        session.commit()
        yield session

    except:
        session.rollback()
        raise
    finally:
        session.close()
Exemple #3
0
    def test_product_picture(self):
        """Test the foreign key picture to products"""
        #creates a category
        cat3 = cmod.Category()
        cat3.code = 'string'
        cat3.name = 'String Instruments'
        cat3.save()

        # Creates a bulk product
        bp1 = cmod.BulkProduct()
        bp1.category = cat3
        bp1.name = 'Guitar Strings'
        bp1.brand = 'Gibson'
        bp1.price = Decimal('9.99')
        bp1.quantity = 40
        bp1.reorder_trigger = 10
        bp1.reorder_quantity = 35
        bp1.save()

        #Creates a picture and is a foreign key to the bulk product
        pic1 = cmod.ProductPicture()
        pic1.product = bp1
        pic1.path = 'catalog/media/product_images/gibsonStrings.jpg'
        pic1.altText = 'Guitar Strings1'
        pic1.imageType = 'jpg'
        pic1.save()

        #pull back off of the database
        product1 = cmod.Product.objects.get(id=1)
        picture1path = product1.pictures.all()[0].path
        picture2path = bp1.pictures.all()[0].path
        self.assertEqual(picture1path, picture2path)
Exemple #4
0
    def test_create_a_unique_product(self):
        ## Will create a category and a unique product, then make sure the values saved and that we have access to those values
        ## Assumptions
        # User would be logged in
        # User would have the permissions to create a product

        # Create a category
        cat5 = cmod.Category()
        cat5.codename = 'st'
        cat5.name = 'Strings'
        cat5.save()

        # Create a Unique Product
        p1 = cmod.UniqueProduct()
        p1.product = p1
        p1.serial_number = '1234asdf'
        p1.name = 'Violin'
        p1.category = cat5
        p1.price = Decimal('250.99')
        dList = [
            'Violin hand made in 1456', 'Played be Bach and Beethoved',
            'Korys favorite instrument'
        ]
        p1.descriptionList = json.dumps(dList)
        iList = [
            '/static/homepage/media/img/violin.jpg',
            '/static/homepage/media/img/violin2.png',
            '/static/homepage/media/img/violin3.jpg',
            '/static/homepage/media/img/thumbnail_violin.jpg'
        ]
        p1.imgList = json.dumps(iList)
        p1.save()

        p2 = cmod.Product.objects.get(id=p1.id)
        self.assertEquals(p2.serial_number, '1234asdf')
        self.assertEquals(p2.name, 'Violin')
        self.assertEquals(p2.category, cat5)
        self.assertEquals(p2.price, Decimal('250.99'))
        self.assertEquals(p2.descriptionList, json.dumps(dList))
        self.assertEquals(p2.imgList, json.dumps(iList))
Exemple #5
0
    def test_create_a_Bulk_Product(self):
        ## Will create a category and a Bulk product, then make sure the values saved and that we have access to those values
        ## Assumptions
        # User would be logged in
        # User would have the permissions to create a product

        # Create a category
        cat4 = cmod.Category()
        cat4.codename = 'ac'
        cat4.name = 'Accessories'
        cat4.save()

        # Create a Bulk Product
        p3 = cmod.BulkProduct()
        p3.name = 'Sheet Music 1'
        p3.category = cat4
        p3.price = Decimal('9.50')
        p3.quantity = 20
        p3.reorder_trigger = 5
        p3.reorder_quantity = 30
        dList = ['Holy sheet music', 'From Beethoven to T-swizzle']
        p3.descriptionList = json.dumps(dList)
        iList = [
            '/static/homepage/media/img/sh1.jpg',
            '/static/homepage/media/img/sh2.jpg',
            '/static/homepage/media/img/sh3.png'
        ]
        p3.imgList = json.dumps(iList)
        p3.save()

        p4 = cmod.Product.objects.get(id=p3.id)
        self.assertEquals(p4.name, 'Sheet Music 1')
        self.assertEquals(p4.category, cat4)
        self.assertEquals(p4.price, Decimal('9.50'))
        self.assertEquals(p4.descriptionList, json.dumps(dList))
        self.assertEquals(p4.imgList, json.dumps(iList))
        self.assertEquals(p4.quantity, 20)
        self.assertEquals(p4.reorder_quantity, 30)
        self.assertEquals(p4.reorder_trigger, 5)
Exemple #6
0
def process_request(request):
    try:
        product = cmod.Product.objects.get(id=request.urlparams[0])
        new = False
    except:
        product = cmod.BulkProduct(name='',
                                   status='A',
                                   description='',
                                   category=cmod.Category(name='Brass'),
                                   price=0)
        product.TITLE = 'Bulk'
        new = True

    if request.urlparams[0] == 'submit':
        new = False

    # process the form
    form = EditForm(request, product, new)
    if form.is_valid():
        form.commit(product)
        return HttpResponseRedirect('/manager/products')

    # render the template
    return request.dmp_render('edit.html', {'form': form})
Exemple #7
0
##################################
###   Products

cmod.ProductImage.objects.all().delete()
cmod.IndividualProduct.objects.all().delete()
cmod.RentalProduct.objects.all().delete()
cmod.BulkProduct.objects.all().delete()
cmod.Category.objects.all().delete()

# categories
print('Creating categories...')

categories = []
for catname in ('Instruments', 'Sheet Music', 'Electronics', 'Software',
                'Lesson Books'):
    c = cmod.Category()
    c.name = catname
    c.description = 'This is a category named {}'.format(catname)
    c.save()
    categories.append(c)

# products
print('Creating products...')
for i in range(1, 25):
    p = cmod.BulkProduct()
    p.name = 'unset'  # see image adding below
    p.description = 'unset'
    p.category = random.choice(categories)
    p.status = 'A'
    p.price = random.uniform(1, 1000)
    p.reorder_trigger = random.randint(5, 15)
Exemple #8
0
u3.zip = '84604'
u3.date_joined = datetime.now()
u3.last_login = datetime.now()
u3.email = "*****@*****.**"
u3.phone_number = "8013863392"
u3.city = "Orem"
u3.state = "UT"
u3.is_staff = True
u3.is_active = True
u3.save()

u1 = FomoUser.objects.get(id=2)
print(u1.username)

#categories
cat1 = cmod.Category()
cat1.code = 'brass'
cat1.name = 'Brass Instruments'
cat1.save()

cat2 = cmod.Category()
cat2.code = 'woodwind'
cat2.name = 'Woodwind Instruments'
cat2.save()

cat3 = cmod.Category()
cat3.code = 'string'
cat3.name = 'String Instruments'
cat3.save()
#end of category creation
Exemple #9
0
    for group_name in data[12]:
        group = Group.objects.get(name__exact=group_name)
        user.groups.add(group)
    # create initial shopping cart for user
    cart = cmod.ShoppingCart()
    cart.user = user
    cart.save()

# add categories
for data in (
    ('Brass Instruments', 'brass'),
    ('String Instruments', 'string'),
    ('Wind Instruments', 'wind'),
    ('Percussion Instruments', 'percussion'),
):
    cat = cmod.Category()
    cat.name = data[0]
    cat.codename = data[1]
    cat.save()

# product picture base uri
dir = 'catalog/media/product_images/'

## add products
# add bulk products
for data in (
    ('Trumpet Mouthpiece', 'brass', 'Galaxy', Decimal('49.99'), 20, 5, 10, [
        [dir + 'trumpet_mouthpiece.jpg', 'jpg', True],
        [dir + 'trumpet_mouthpiece_1.jpg', 'jpg', False],
        [dir + 'trumpet_mouthpiece_2.jpg', 'jpg', False],
        [dir + 'trumpet_mouthpiece_3.jpg', 'jpg', False],