コード例 #1
0
    def test_db_data(self, setup_db):
        params = {"name": "UPADTE_NAME"}
        client.put(f"/projects/{1}", json=params)

        project = setup_db.query(Project).filter(Project.id == 1).first()

        assert project.name == "UPADTE_NAME"
コード例 #2
0
 def test_invitations_reject_valid(self, client):
     token = create_token1()
     res = client.put('/api/invitations/reject/3',
                     headers={'Authorization':'Bearer ' + token},
                     content_type='application/json')
     res_json = json.loads(res.data)
     if res.status_code != 200:
         raise ValueError('The res.status_code must be 200, please check your code')
コード例 #3
0
 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
コード例 #4
0
    def test_response(self, setup_db):
        params = {"name": "UPADTE_NAME"}
        response = client.put(f"/projects/{1}", json=params)

        assert response.status_code == 200
        assert response.json() == {
            "id": 1,
            "name": "UPADTE_NAME",
        }
コード例 #5
0
 def test_invitations_accept_invalid_no_token(self, client):
     """
     test invalid accept without token
     """
     
     res = client.put('/api/invitations/accept/1',
                     content_type='application/json')
     res_json = json.loads(res.data)
     if res.status_code != 401:
         raise ValueError('The res.status_code must be 401, please check your code')
コード例 #6
0
 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
コード例 #7
0
 def testPutConfirmedByUser(self, client):
     """Test put an order record using user's token and status='confirmed'
     User is not permitted to change status to confirmed, hence will raise 403(forbidden) error"""
     token = createTokenUser()
     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 == 403
コード例 #8
0
 def testUserPutMobileNumberAlreadyListed(self, client):
     """put user data to table with mobile number that is already in the table, hence will get 400 error code"""
     token = createTokenUser()
     data = {"mobile_number": "0811221122112"}
     res = client.put('/v1/users',
                      data=json.dumps(data),
                      headers={'Authorization': 'Bearer ' + token},
                      content_type='application/json')
     res_json = json.loads(res.data)
     assert res.status_code == 400
コード例 #9
0
 def testUserPutMobileNumberOwner(self, client):
     """put user data to table with mobile number that is as same as old number"""
     token = createTokenUser()
     data = {"mobile_number": "08812121212"}
     res = client.put('/v1/users',
                      data=json.dumps(data),
                      headers={'Authorization': 'Bearer ' + token},
                      content_type='application/json')
     res_json = json.loads(res.data)
     assert res.status_code == 200
コード例 #10
0
def test_if_store_edit_returns_406_if_the_paylod_is_not_json():
    response = client.put(url_for('store_bp.store_edit'), data="teste")

    expected_return = {
        "status": "Error",
        "status_code": 406,
        "message": "Payload is not a JSON"
    }

    assert response.status_code == 406
    assert json.loads(response.data) == expected_return
コード例 #11
0
    def testOrderPutCancelled(self, client):
        """Test put order record with status 'cancelled' using valid token."""
        token = createTokenUser()
        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 == 200
コード例 #12
0
def test_if_store_edit_returns_400_if_the_json_is_invalid(create_store):
    response = client.put(url_for('store_bp.store_edit'),
                          json={"name": "Fake store edited"})

    expected_return = {
        "status": "Error",
        "status_code": 400,
        "message": "Fields missing in JSON",
    }

    assert response.status_code == 400
    assert json.loads(response.data) == expected_return
コード例 #13
0
    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
コード例 #14
0
    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
コード例 #15
0
    def testOrderPutInvalidStatus(self, client):
        """test put an order record using status 'cancelledmaybe' which is not a valid options for status"""

        token = createTokenUser()
        order_status = {
            "status": "cancelledmaybe"
        }

        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 == 400
コード例 #16
0
    def testUserPutInvalidMobileNumber(self, client):
        """test put user data to table with invalid mobile number format,
        hence will raise 400(bad request) error"""

        token = createTokenUser()
        data = {"mobile_number": "812121212"}
        res = client.put('/v1/users',
                         data=json.dumps(data),
                         headers={'Authorization': 'Bearer ' + token},
                         content_type='application/json')
        res_json = json.loads(res.data)
        assert res.status_code == 400