Esempio n. 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()
Esempio n. 2
0
    def setUp(self):
        super(ModelResourceTest, 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()
Esempio n. 3
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()
Esempio n. 4
0
 def setUp(self):
     super(ModelResourceTest, 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()
Esempio n. 5
0
class ModelResourceTest(APITestCase):
    def setUp(self):
        super(ModelResourceTest, 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()

    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/model/', 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
        model = resp_obj['results'][0]
        self.assertEqual(model['id'], 1)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')

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

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

        #Validate the resource
        model = resp.data
        self.assertEqual(model['id'], 1)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')

    def test_post(self):
        """
        Test creating a resource via POST
        """
        #Validate object creation
        self.assertEqual(Model.objects.count(), 1)
        resp = self.client.post('/api/v1/model/',
                                format='json',
                                data=base_model,
                                authorization=self.get_credentials())
        self.assertEqual(Model.objects.count(), 2)

        #Validate response
        self.assertEqual(resp.status_code, 201)

        #Validate the resource
        model = resp.data
        self.assertEqual(model['id'], 2)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')

    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_model = base_model.copy()
        updated_model['name'] = 'Patsy'

        #Validate object update
        self.assertEqual(Model.objects.count(), 1)
        resp = self.client.put('/api/v1/model/1/',
                               format='json',
                               data=updated_model,
                               authorization=self.get_credentials())
        self.assertEqual(Model.objects.count(), 1)

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

        #Validate resource
        model = resp.data
        self.assertEqual(model['name'], 'Patsy')

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

        #Validate the response
        self.assertEqual(resp.status_code, 204)
Esempio n. 6
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)
Esempio n. 7
0
class ModelResourceTest(APITestCase):
    def setUp(self):
        super(ModelResourceTest, 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()
                
    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/model/', 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
        model = resp_obj['results'][0]
        self.assertEqual(model['id'], 1)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')
        
    def test_get(self):
        """
        Test retrieving a resource via GET
        """
        resp = self.client.get('/api/v1/model/1/', format='json')
        
        #Validate resp
        self.assertEqual(resp.status_code, 200)
        
        #Validate the resource
        model = resp.data
        self.assertEqual(model['id'], 1)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')
        
    def test_post(self):
        """
        Test creating a resource via POST
        """
        #Validate object creation
        self.assertEqual(Model.objects.count(), 1)
        resp = self.client.post('/api/v1/model/', 
                                    format='json',
                                    data=base_model,
                                    authorization=self.get_credentials())
        self.assertEqual(Model.objects.count(), 2)
        
        #Validate response
        self.assertEqual(resp.status_code, 201)
       
        #Validate the resource
        model = resp.data
        self.assertEqual(model['id'], 2)
        self.assertEqual(model['model'], 'AC-1')
        self.assertEqual(model['name'], 'Susie')
        self.assertEqual(model['collection'], 'Dellarobbia Thailand')
        
    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_model = base_model.copy()
        updated_model['name'] = 'Patsy'
        
        #Validate object update
        self.assertEqual(Model.objects.count(), 1)
        resp = self.client.put('/api/v1/model/1/', 
                                   format='json',
                                   data=updated_model,
                                   authorization=self.get_credentials())
        self.assertEqual(Model.objects.count(), 1)
        
        #Validate resp
        self.assertEqual(resp.status_code, 200)
        
        #Validate resource
        model = resp.data
        self.assertEqual(model['name'], 'Patsy')

        
    def test_delete(self):
        """
        Test deleting a resource via DELETE
        """
        #Validate resource deleted
        self.assertEqual(Model.objects.count(), 1)
        resp = self.client.delete('/api/v1/model/1/', 
                                      format='json', 
                                      authentication=self.get_credentials())
        self.assertEqual(Model.objects.count(), 0)
        
        #Validate the response
        self.assertEqual(resp.status_code, 204)
Esempio n. 8
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)