Example #1
0
    def setUp(self):
        super(TableResourceTest, self).setUp()

        #Create the user
        self.username = '******'
        self.password = '******'
        self.user = User.objects.create_user(self.username, '*****@*****.**',
                                             self.password)

        #Create a model to be used for testing
        model_data = base_model.copy()
        del model_data['images']
        self.model = Model(**model_data)
        self.model.save()

        #Create configuration for testing
        self.configuration = Configuration(configuration='Coffee Table')
        self.configuration.save()

        #Strip pillows and make pillows separately
        table_data = base_product.copy()
        del table_data['corner_pillow']
        del table_data['accent_pillow']
        del table_data['back_pillow']
        del table_data['lumbar_pillow']
        self.product = Table(**table_data)
        self.product.description = 'AC-1 Coffee Table'
        self.product.type = 'table'
        self.product.model = self.model
        self.product.configuration = self.configuration
        self.product.save()
Example #2
0
 def setUp(self):
     super(TableResourceTest, self).setUp()
     
     #Create the user
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(self.username, '*****@*****.**', self.password)
     
     #Create a model to be used for testing
     model_data = base_model.copy()
     del model_data['images']
     self.model = Model(**model_data)
     self.model.save()
     
     #Create configuration for testing
     self.configuration = Configuration(configuration='Coffee Table')
     self.configuration.save()
     
     #Strip pillows and make pillows separately
     table_data = base_product.copy()
     del table_data['corner_pillow']
     del table_data['accent_pillow']
     del table_data['back_pillow']
     del table_data['lumbar_pillow']
     self.product = Table(**table_data)
     self.product.description = 'AC-1 Coffee Table'
     self.product.type = 'table'
     self.product.model = self.model
     self.product.configuration = self.configuration
     self.product.save()
Example #3
0
class TableResourceTest(APITestCase):
    def setUp(self):
        super(TableResourceTest, self).setUp()

        #Create the user
        self.username = '******'
        self.password = '******'
        self.user = User.objects.create_user(self.username, '*****@*****.**',
                                             self.password)

        #Create a model to be used for testing
        model_data = base_model.copy()
        del model_data['images']
        self.model = Model(**model_data)
        self.model.save()

        #Create configuration for testing
        self.configuration = Configuration(configuration='Coffee Table')
        self.configuration.save()

        #Strip pillows and make pillows separately
        table_data = base_product.copy()
        del table_data['corner_pillow']
        del table_data['accent_pillow']
        del table_data['back_pillow']
        del table_data['lumbar_pillow']
        self.product = Table(**table_data)
        self.product.description = 'AC-1 Coffee Table'
        self.product.type = 'table'
        self.product.model = self.model
        self.product.configuration = self.configuration
        self.product.save()

    def get_credentials(self):
        return None  #self.create_basic(username=self.username, password=self.password)

    def test_get_list(self):
        """
        Test getting a list of models via GET
        """
        resp = self.client.get('/api/v1/table/', format='json')

        #Validate resp
        self.assertEqual(resp.status_code, 200)

        #Validate data
        resp_obj = resp.data
        self.assertEqual(len(resp_obj['results']), 1)

        #Validate the first resource
        table = resp_obj['results'][0]
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')

    def test_get(self):
        """
        Test retrieving a resource via GET
        """
        resp = self.client.get('/api/v1/table/1/', format='json')

        #Validate resp
        self.assertEqual(resp.status_code, 200)

        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')

    def test_post(self):
        """
        Test creating a resource via POST
        """
        #Validate object creation
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.post('/api/v1/table/',
                                format='json',
                                data=base_table)

        self.assertEqual(Table.objects.count(), 2)
        #Validate response
        self.assertEqual(resp.status_code, 201)

        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 2)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')

    def test_put(self):
        """
        Test updating a resource via POST
        
        The first part of the test will validate that an object
        is neither created or deleted
        """
        #Update data
        updated_table = base_table.copy()
        updated_table['wholesale_price'] = 120000

        #Validate object update
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.put('/api/v1/table/1/',
                               format='json',
                               data=updated_table,
                               authorization=self.get_credentials())
        self.assertEqual(Table.objects.count(), 1)
        self.assertEqual(resp.status_code, 200)

        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')

    def test_delete(self):
        """
        Test deleting a resource via DELETE
        """
        #Validate resource deleted
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.delete('/api/v1/table/1/',
                                  format='json',
                                  authentication=self.get_credentials())
        self.assertEqual(Table.objects.count(), 0)

        #Validate the response
        self.assertEqual(resp.status_code, 204)
Example #4
0
class TableResourceTest(APITestCase):
    def setUp(self):
        super(TableResourceTest, self).setUp()
        
        #Create the user
        self.username = '******'
        self.password = '******'
        self.user = User.objects.create_user(self.username, '*****@*****.**', self.password)
        
        #Create a model to be used for testing
        model_data = base_model.copy()
        del model_data['images']
        self.model = Model(**model_data)
        self.model.save()
        
        #Create configuration for testing
        self.configuration = Configuration(configuration='Coffee Table')
        self.configuration.save()
        
        #Strip pillows and make pillows separately
        table_data = base_product.copy()
        del table_data['corner_pillow']
        del table_data['accent_pillow']
        del table_data['back_pillow']
        del table_data['lumbar_pillow']
        self.product = Table(**table_data)
        self.product.description = 'AC-1 Coffee Table'
        self.product.type = 'table'
        self.product.model = self.model
        self.product.configuration = self.configuration
        self.product.save()
                
    def get_credentials(self):
        return None#self.create_basic(username=self.username, password=self.password)
    
    def test_get_list(self):
        """
        Test getting a list of models via GET
        """
        resp = self.client.get('/api/v1/table/', format='json')
        
        #Validate resp
        self.assertEqual(resp.status_code, 200)
        
        #Validate data
        resp_obj = resp.data
        self.assertEqual(len(resp_obj['results']), 1)
        
        #Validate the first resource
        table = resp_obj['results'][0]
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')
        
        
    def test_get(self):
        """
        Test retrieving a resource via GET
        """
        resp = self.client.get('/api/v1/table/1/', format='json')
        
        #Validate resp
        self.assertEqual(resp.status_code, 200)
        
        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')
        
    def test_post(self):
        """
        Test creating a resource via POST
        """
        #Validate object creation
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.post('/api/v1/table/', 
                                    format='json',
                                    data=base_table)

        self.assertEqual(Table.objects.count(), 2)
        #Validate response
        self.assertEqual(resp.status_code, 201)
       
        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 2)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')
        
    def test_put(self):
        """
        Test updating a resource via POST
        
        The first part of the test will validate that an object
        is neither created or deleted
        """
        #Update data
        updated_table = base_table.copy()
        updated_table['wholesale_price'] = 120000
        
        #Validate object update
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.put('/api/v1/table/1/', 
                                   format='json',
                                   data=updated_table,
                                   authorization=self.get_credentials())
        self.assertEqual(Table.objects.count(), 1)
        self.assertEqual(resp.status_code, 200)
        
        #Validate the first resource
        table = resp.data
        self.assertEqual(table['id'], 1)
        self.assertEqual(table['type'], 'table')
        self.assertEqual(table['description'], 'AC-1 Coffee Table')
        self.assertEqual(table['model']['id'], 1)
        self.assertEqual(table['configuration']['id'], 1)
        self.assertEqual(table['width'], 1000)
        self.assertEqual(table['depth'], 500)
        self.assertEqual(table['height'], 400)
        self.assertEqual(table['manufacture_price'], '50000.00')
        
    def test_delete(self):
        """
        Test deleting a resource via DELETE
        """
        #Validate resource deleted
        self.assertEqual(Table.objects.count(), 1)
        resp = self.client.delete('/api/v1/table/1/', 
                                      format='json', 
                                      authentication=self.get_credentials())
        self.assertEqual(Table.objects.count(), 0)
        
        #Validate the response
        self.assertEqual(resp.status_code, 204)
Example #5
0
def addtocart(request, id=None):
    flag = 0
    form = None
    table = Table()
    z = None
    try:
        lapi = Laptop.objects.get(id=id)
        for x in myproducts.keys():
            if (x.id == lapi.id):
                flag = 1
                cnt = myproducts.get(x)
                cnt = int(cnt)
                myproducts[lapi] = cnt + 1
                table = Table.objects.create(name=request.user, pro_id=lapi.id)
                amt = amt + lapi.cost
        if flag == 0:
            myproducts[lapi] = 1

            table = Table()
            table = Table.objects.create(name=request.user, pro_id=lapi.id)
            amt = amt + lapi.cost

    except:
        try:
            wth = Watch.objects.get(id=id)
            for x in myproducts.keys():
                if (x.id == wth.id):
                    flag = 1
                    cnt = myproducts.get(x)
                    cnt = int(cnt)
                    myproducts[wth] = cnt + 1

                    table = Table.objects.create(name=request.user,
                                                 pro_id=wth.id)

                    amt = amt + wth.cost

            if flag == 0:
                myproducts[wth] = 1

                table = Table.objects.create(name=request.user, pro_id=wth.id)
                amt = amt + wth.cost

        except:
            try:

                phn = Phone.objects.get(id=id)
                for x in myproducts.keys():
                    if (x.id == phn.id):
                        flag = 1
                        cnt = myproducts.get(x)
                        cnt = int(cnt)
                        myproducts[phn] = cnt + 1

                        table = Table.objects.create(name=request.user,
                                                     pro_id=phn.id)

                        amt = amt + phn.cost

                if flag == 0:
                    myproducts[phn] = 1

                    table = Table.objects.create(name=request.user,
                                                 pro_id=phn.id)
                    amt = amt + phn.cost

                # return render(request,'forms.html',{'obj':phn,'msg':msg,'myproducts':myproducts})
            except:
                pass

    return redirect('/proview')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/added'))