Esempio n. 1
0
    def test_get_avg_weight_partial_invalid_data(self):

        data = {
            'objects': [{
                "category": 'Air Conditioners',
                "size": {
                    "width": 10.0,
                    "height": 20.0
                }
            }, {
                "category": 'Air Conditioners',
                "size": {
                    "length": 43.0,
                    "width": 45.0,
                    "height": 50.2
                }
            }, {
                "category": 'Washing Machine',
                "size": {
                    "length": 43.0,
                    "width": 45.0,
                    "height": 53.6
                }
            }],
            'next':
            None
        }
        self.mock_get.return_value = MockAPIResponse(data, 200)
        obj = CalculateCategoryWeight()
        obj.category = PRODUCTS[AIR_CONDITIONERS]

        self.assertEqual(obj.get_avg_weight(), 24.28425)
Esempio n. 2
0
    def test_get_avg_weight_returns_error(self):

        self.mock_get.return_value = MockAPIResponse({}, 400)
        obj = CalculateCategoryWeight()
        obj.category = PRODUCTS[AIR_CONDITIONERS]

        self.assertRaises(CalculatorException, obj.get_avg_weight)
Esempio n. 3
0
    def test_get_avg_weight_with_empty_data(self):

        data = {'objects': [], 'next': None}
        self.mock_get.return_value = MockAPIResponse(data, 200)
        obj = CalculateCategoryWeight()
        obj.category = PRODUCTS[AIR_CONDITIONERS]

        self.assertEqual(obj.get_avg_weight(), 0)
Esempio n. 4
0
    def test_get_avg_weight_with_no_dataset(self):

        data = {
            'objects': [{
                "category": 'Washing Machine',
                "size": {
                    "length": 43.0,
                    "width": 45.0,
                    "height": 53.6
                }
            }],
            'next':
            None
        }
        self.mock_get.return_value = MockAPIResponse(data, 200)
        obj = CalculateCategoryWeight()
        obj.category = PRODUCTS[AIR_CONDITIONERS]

        self.assertEqual(obj.get_avg_weight(), 0)