Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload with non serializable JSON data #138

Open
ArturoQuintana opened this issue May 27, 2021 · 5 comments
Open

Payload with non serializable JSON data #138

ArturoQuintana opened this issue May 27, 2021 · 5 comments

Comments

@ArturoQuintana
Copy link

ArturoQuintana commented May 27, 2021

Hi, @cmagnobarbosa.
Issue 132 seems to be closed by PR 137, and in there, we referenced problems with some payloads.
The application continues failing in the case in which a payload specifies non-serializable JSON data.

some tests:

def test_030_install_flow_should_fail(self):
        """Test if the flow installation process specifying a
        wrong datatype payload behaves as expected (400 Error)."""

        payload = {
            "flows": [
                {
                    "priority"
                }
            ]
        }

        api_url = KYTOS_API + '/flow_manager/v2/flows/00:00:00:00:00:00:00:01'
        response = requests.post(api_url, data=json.dumps(payload),
                                 headers={'Content-type': 'application/json'})
        assert response.status_code == 400
def test_055_install_flows_should_fail(self):
        """Test if the flow installation process specifying a
        wrong datatype payload behaves as expected (400 Error)."""

        payload = {
            "flows": [
                {
                    "priority"
                }
            ]
        }

        api_url = KYTOS_API + '/flow_manager/v2/flows'
        response = requests.post(api_url, data=json.dumps(payload),
                                 headers={'Content-type': 'application/json'})
        assert response.status_code == 400
 def test_080_delete_flow_should_fail(self):
        """Test if the flow deletion process specifying a
        wrong datatype payload behaves as expected (400 Error)."""

        payload = {
            "flows": [
                {
                    "priority"
                }
            ]
        }

        # delete the flow
        api_url = KYTOS_API + '/flow_manager/v2/flows/00:00:00:00:00:00:00:01'
        response = requests.delete(api_url, data=json.dumps(payload),
                                   headers={'Content-type': 'application/json'})
        assert response.status_code == 400
def test_100_delete_flows_should_fail(self):
        """Test if the flow deletion process specifying a
        wrong datatype payload behaves as expected (400 Error)."""

        payload = {
            "flows": [
                {
                    "priority"
                }
            ]
        }

        # delete the flow
        api_url = KYTOS_API + '/flow_manager/v2/flows'
        response = requests.delete(api_url, data=json.dumps(payload),
                                   headers={'Content-type': 'application/json'})
        assert response.status_code == 400
@josemauro
Copy link
Member

josemauro commented May 27, 2021

Hello @ArturoQuintana, I was discussing with @cmagnobarbosa and we would like to get more information about failed test, like the output showing the error/exception. Can you share the output with us? We have some guess about why the test is failing and the output would help us understand better. Thank you.

@ArturoQuintana
Copy link
Author

Hi @josemauro and @cmagnobarbosa, thanks for getting back to us about this issue.
This is the output we are receiving for each one of the tests.
Screen Shot 2021-05-28 at 2 58 10 PM

@josemauro
Copy link
Member

Thank you @ArturoQuintana. The error shown in the output is a TypeError raised because you are using an invalid dictionary that can not be serializable to JSON by 'json.dumps'. The method 'dumps' will only return you a string, so instead using 'dumps' in this case you can assemble your own string with the invalid JSON replacing data=json.dumps(payload) by 'data={"flows": [{"priority"}]}' , the last one represents the string that you want use in the request. Just let us know if you have any other problem.

@ArturoQuintana
Copy link
Author

Thanks @josemauro
The idea to provide an invalid JSON is on purpose. This is an API call, and the reliability of the application lies in the fact that the application will run regardless of the input provided.

@josemauro
Copy link
Member

Sure, but this error is not related to the API call, actually you are not even making the call because a primary error is occurring preventing the call to be done. As I mentioned before, the error is caused by 'json.dumps'. I've tested the API call using the string that I recommended and I got the code 400.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants