Exemplo n.º 1
0
    def test_execute_http_request_post_with_auth_token(self):
        http_url = 'http://localhost:8080/mock'
        auth_token = "bearer jkhfhkujsfsfslfhjsfhkjsfhskhfksj"
        resp_msg = "Data added successfully"
        request_params = {
            'data': 'test_data',
            'test_class': [{
                'key': 'value'
            }, {
                'key2': 'value2'
            }]
        }

        responses.add(method=responses.POST,
                      url=http_url,
                      body=resp_msg,
                      status=200,
                      match=[responses.json_params_matcher(request_params)])

        response = ActionUtility.execute_http_request(
            auth_token=auth_token,
            http_url=http_url,
            request_method=responses.POST,
            request_body=request_params)
        assert response
        assert response == resp_msg
        assert responses.calls[0].request.headers[
            'Authorization'] == auth_token
Exemplo n.º 2
0
    def test_execute_http_request_getWith_auth_token(self):
        http_url = 'http://localhost:8080/mock'
        # file deepcode ignore HardcodedNonCryptoSecret: Random string for testing
        auth_token = "bearer jkhfhkujsfsfslfhjsfhkjsfhskhfksj"

        responses.add(method=responses.GET,
                      url=http_url,
                      json={
                          'data': 'test_data',
                          'test_class': [{
                              'key': 'value'
                          }, {
                              'key2': 'value2'
                          }]
                      },
                      status=200)

        response = ActionUtility.execute_http_request(
            auth_token=auth_token,
            http_url=http_url,
            request_method=responses.GET)
        assert response
        assert response['data'] == 'test_data'
        assert len(response['test_class']) == 2
        assert response['test_class'][1]['key2'] == 'value2'
        assert responses.calls[0].request.headers[
            'Authorization'] == auth_token
Exemplo n.º 3
0
    def test_execute_http_request_delete_no_auth_token(self):
        http_url = 'http://localhost:8080/mock'
        resp_msg = "Data updated successfully"
        request_params = {
            'data': 'test_data',
            'test_class': [{
                'key': 'value'
            }, {
                'key2': 'value2'
            }]
        }

        responses.add(method=responses.DELETE,
                      url=http_url,
                      body=resp_msg,
                      status=200,
                      match=[responses.json_params_matcher(request_params)])

        response = ActionUtility.execute_http_request(
            auth_token=None,
            http_url=http_url,
            request_method=responses.DELETE,
            request_body=request_params)
        assert response
        assert response == resp_msg
        assert 'Authorization' not in responses.calls[0].request.headers
Exemplo n.º 4
0
    def test_execute_http_request_get_no_auth_token(self):
        http_url = 'http://localhost:8080/mock'
        responses.add(
            method=responses.GET,
            url=http_url,
            json={'data': 'test_data', 'test_class': [{'key': 'value'}, {'key2': 'value2'}]},
            status=200
        )

        response = ActionUtility.execute_http_request(auth_token=None, http_url=http_url,
                                                      request_method=responses.GET)
        assert response
        assert response['data'] == 'test_data'
        assert len(response['test_class']) == 2
        assert response['test_class'][1]['key2'] == 'value2'
        assert 'Authorization' not in responses.calls[0].request.headers
Exemplo n.º 5
0
    def test_execute_http_request_delete_with_auth_token_no_request_body(self):
        http_url = 'http://localhost:8080/mock'
        auth_token = "bearer jkhfhkujsfsfslfhjsfhkjsfhskhfksj"
        resp_msg = "Data deleted successfully"

        responses.add(
            method=responses.DELETE,
            url=http_url,
            body=resp_msg,
            status=200,
        )

        response = ActionUtility.execute_http_request(auth_token=auth_token, http_url=http_url,
                                                      request_method=responses.DELETE, request_body=None)
        assert response
        assert response == resp_msg
        assert responses.calls[0].request.headers['Authorization'] == auth_token