def test_404_get_product_by_category(self):
        c = Category(id=1, name='Electronics')
        c.insert()
        res = self.client().get('/categories/1/products')
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 404)
        self.assertEqual(data['success'], False)
        self.assertEqual(data['message'], 'resource not found')
    def test_get_product_by_id(self):
        c = Category(id=1, name='Electronics')
        c.insert()
        p = Product(id=1, category=c)
        p.insert()
        res = self.client().get('/products/1')
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 200)
        self.assertEqual(data['success'], True)
        self.assertTrue(data['product'])
    def test_admin_post_new_product(self):
        c = Category(id=1, name='Electronics')
        c.insert()
        res = self.client().post('/products',
                                 data=json.dumps(self.new_product),
                                 headers=self.admin_header)
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 200)
        self.assertEqual(data['success'], True)
        self.assertTrue(data['created'])
        self.assertTrue(data['total_products'])