Exemple #1
0
 def testHistoryGetByAdmin(self, client):
     """test get all data from reward history by admin"""
     token = createTokenAdmin()
     res = client.get('/v1/reward_history',
                      headers={'Authorization': "Bearer " + token},
                      content_type='application/json')
     assert res.status_code == 200
    def testGetAll(self, client):
        """get all users data from users table"""

        token = createTokenAdmin()
        res = client.get('/v1/users/all',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 200
    def testGetOneByAdmin(self, client):
        """test get a specific user data using admin token"""

        token = createTokenAdmin()
        res = client.get('/v1/users/admin/2',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 200
 def testTrashCategoriesDeleteInvalidId(self, client):
     """Test soft delete a record in trash categories table
     trash with id 123 is not in the table, hence will get a 404(Not Found) error"""
     token = createTokenAdmin()
     res = client.delete('/v1/trash_category/123',
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
     assert res.status_code == 404
    def testGetOneByAdminNotFound(self, client):
        """test get a specific user data which is not exist in the table using admin token,
        will raise a 404(Not Found) error"""

        token = createTokenAdmin()
        res = client.get('/v1/users/admin/100',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 404
    def testTrashGet(self, client):
        """Test getting all data from trashes table using valid token"""

        token = createTokenAdmin()
        res = client.get('/v1/trash',
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
    def testOrderGet(self, client):
        """test get all order data from orders table"""

        token = createTokenAdmin()

        res = client.get(
            '/v1/orders', headers={'Authorization': "Bearer " + token}, content_type='application/json')
        assert res.status_code == 200
Exemple #8
0
    def testGetAllRewards(self, client):
        """test get all rewards data from rewards table using valid token"""
        token = createTokenAdmin()
        res = client.get('/v1/rewards',
                         headers={'Authorization': 'Bearer ' + token})

        res_json = json.loads(res.data)
        assert res.status_code == 200
    def testTrashCategoriesGetByAdmin(self, client):
        """Test getting all data from trash category table using token from an admin account"""

        token = createTokenAdmin()
        res = client.get('/v1/trash_category',
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
    def testTrashCategoriesDelete(self, client):
        """Test soft delete a record in trash category table with valid token and id"""

        token = createTokenAdmin()
        res = client.delete('/v1/trash_category/{}'.format(
            TestTrashManagement.temp_category_id),
                            headers={'Authorization': "Bearer " + token},
                            content_type='application/json')
        assert res.status_code == 200
    def testUserOrderGetInvalidToken(self, client):
        """Test get a specific user's order data using admin token,
        hence will raise 403(forbidden) error"""

        token = createTokenAdmin()
        res = client.get(
            'v1/orders/user', headers={'Authorization': "Bearer " + token}, content_type='application/json')

        assert res.status_code == 403
 def testPutConfirmed(self, client):
     """Test put an order record using admin's token and status='confirmed'"""
     token = createTokenAdmin()
     order_status = {
         "status": "confirmed"
     }
     res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps(
         order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json')
     assert res.status_code == 200
 def testTrashCategoriesPutInvalidId(self, client):
     """test put a record in trash category table with invalid id.
     'none' is an invalid id, hence will raise a 404(Not Found) error"""
     token = createTokenAdmin()
     new_name = {"category_name": "dummyname"}
     res = client.put('/v1/trash_category/none',
                      data=json.dumps(new_name),
                      headers={'Authorization': "Bearer " + token},
                      content_type='application/json')
     assert res.status_code == 404
    def testTrashCategoriesPut(self, client):
        """test put a record in tras category table with valid token and data"""

        token = createTokenAdmin()
        new_name = {"category_name": "newdummy", "status": False}

        res = client.put('/v1/trash_category/{}'.format(
            TestTrashManagement.temp_category_id),
                         data=json.dumps(new_name),
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
    def testOrderPutCancelledByAdmin(self, client):
        """Test put an order record using admin's token and status='cancelled'
        Admin permitted to reject, but not permitted to cancel
        hence will raise 403(forbidden) error"""

        token = createTokenAdmin()
        order_status = {
            "status": "cancelled"
        }
        res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps(
            order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json')
        assert res.status_code == 403
    def testTrashCategoriesPost(self, client):
        """test posting a new trash category to table with valid data an header"""

        token = createTokenAdmin()
        category = {"category_name": "dummy_name"}
        res = client.post('/v1/trash_category',
                          data=json.dumps(category),
                          headers={'Authorization': "Bearer " + token},
                          content_type='application/json')

        res_json = json.loads(res.data)
        TestTrashManagement.temp_category_id = res_json['id']
        assert res.status_code == 200
    def testOrderPostInvalidUser(self, client):
        """Test posting a new order using admin token. 
        Admin is not permitted to post a new order,hence request will get 403 response
        """

        token = createTokenAdmin()
        order = {
            "adress": "args",
            "time": "2018-03-29T13:34:00.000",
            "photo": "args"
        }
        res = client.post('/v1/orders', data=json.dumps(order), headers={
                          'Authorization': "Bearer " + token}, content_type='application/json')

        res_json = json.loads(res.data)
        assert res.status_code == 403
    def testTrashPutInvalidId(self, client):
        """test put a record in trashes table with invalid id.
        'none' is an invalid id, hence will raise a 404(Not Found) error"""

        token = createTokenAdmin()
        new_details = {
            "trash_name": "test",
            "photo": "test",
            "price": 100,
            "point": 1
        }
        res = client.put('/v1/trash/none',
                         data=json.dumps(new_details),
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 404
Exemple #19
0
    def testEditReward(self, client):
        """test put a record in rewards table using admin token"""
        token = createTokenAdmin()
        data = {
            "name": "tes2",
            "point_to_claim": 1,
            "photo": "tes",
            "stock": 1,
            "status": False
        }
        res = client.put('/v1/rewards/3',
                         data=json.dumps(data),
                         headers={'Authorization': 'Bearer ' + token},
                         content_type='application/json')

        res_json = json.loads(res.data)

        assert res.status_code == 200
    def testTrashPut(self, client):
        """test put a record in tras tableh with valid token and data"""
        token = createTokenAdmin()
        new_details = {
            "trash_category_id": 1,
            "trash_name": "test",
            "photo": "test",
            "price": 100,
            "point": 1,
            "status": False
        }

        res = client.put('/v1/trash/{}'.format(
            TestTrashManagement.temp_trash_id),
                         data=json.dumps(new_details),
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
Exemple #21
0
    def testEditRewardInvalidId(self, client):
        """test put a reward record which id is not in the table,
        hence will raise 404(Not Found) error"""
        token = createTokenAdmin()
        data = {
            "name": "tes2",
            "point_to_claim": 1,
            "photo": "tes",
            "stock": 1,
            "status": False
        }
        res = client.put('/v1/rewards/23',
                         data=json.dumps(data),
                         headers={'Authorization': 'Bearer ' + token},
                         content_type='application/json')

        res_json = json.loads(res.data)

        assert res.status_code == 404
    def testOrderPutDone(self, client):
        """Test put an order record using admin's token and status='done'"""
        token = createTokenAdmin()
        order_status = {
            "status": "done",
            "details": [
                {"trash_id": 1,
                 "qty": 2.9
                 },
                {"trash_id": 2,
                    "qty": 1.2
                 }
            ]
        }

        res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps(
            order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json')

        assert res.status_code == 200
    def testTrashPost(self, client):
        """test posting a new trash to table with valid data and authorization header"""

        token = createTokenAdmin()
        trash = {
            "trash_category_id": TestTrashManagement.temp_category_id,
            "trash_name": "test",
            "photo": "test",
            "price": 100,
            "point": 1
        }
        res = client.post('/v1/trash',
                          data=json.dumps(trash),
                          headers={'Authorization': "Bearer " + token},
                          content_type='application/json')

        res_json = json.loads(res.data)
        TestTrashManagement.temp_trash_id = res_json['id']
        assert res.status_code == 200