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

Tests api processor routers #105

Merged
merged 5 commits into from
Jan 25, 2021

Conversation

JFer11
Copy link
Contributor

@JFer11 JFer11 commented Dec 21, 2020

In this branch, first endpoints tests were added.
All "app" and "config" router endpoints were tested with pytest.

api/tests/app/test_app.py Outdated Show resolved Hide resolved
expected_response = get_app_from_ini_config_file_json(config_sample_path)
expected_response["dashboardurl"] = expected_response["dashboard_url"]
del expected_response["dashboard_url"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required?

I tested the endpoint /app and it returns the key "dashboard_url"

Copy link
Contributor Author

@JFer11 JFer11 Dec 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about that, in my case, when i debug, the endpoint returns the key "dashboardurl". However, my function get_app_from_ini_config_file_json, returns all the keys fine, less "dashboard_url", so we have to change it manually.

assert response.status_code == 200
expected_response = expected_response_function(config_sample_path)
assert response.json() == expected_response
elif correct_type == "integer":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is missing the correct_type == "integer" case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant the "bool" case, I made it explicit now.

response = client.put('/app', json=body)

expected_response = expected_response_function(config_sample_path)
expected_response_2 = expected_response_default()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can rename the variable as default_response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@JFer11 JFer11 force-pushed the tests_api_processor_routers branch from 8aa8e0f to dd4155a Compare January 14, 2021 19:37
@pgrill pgrill requested a review from renzodgc January 15, 2021 20:48
@@ -0,0 +1,10 @@
###How tests were built

To further improve the tests, I made this file to easily understand how they worked.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To further improve the tests, I made this file to easily understand how they worked.
This file aims to clarify how the unitary test work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!


To further improve the tests, I made this file to easily understand how they worked.

The main thing to know is to understand what role fixtures play, especially Config_rollback.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The main thing to know is to understand what role fixtures play, especially Config_rollback.
The main thing to know is to understand what role fixtures play, especially `Config_rollback`.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another thing to clarify or just Config_rollback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just Config_rollback


The main thing to know is to understand what role fixtures play, especially Config_rollback.

Config_rollback fixture does the following:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Config_rollback fixture does the following:
The `Config_rollback` fixture does the following:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

The main thing to know is to understand what role fixtures play, especially Config_rollback.

Config_rollback fixture does the following:
1. setUp: Initialize the app with a different config file (the one with template in the name).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. setUp: Initialize the app with a different config file (the one with template in the name).
1. `setUp`: Initializes the app with a different config file (given from the name of an actual config file).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!


Config_rollback fixture does the following:
1. setUp: Initialize the app with a different config file (the one with template in the name).
2. Returns the client to make the request and also returns the root of the config file. That root is also returned in order to go directly to that file and check if the changes made from our endpoints were valid.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does root mean path? or its content? I presume is the path

Suggested change
2. Returns the client to make the request and also returns the root of the config file. That root is also returned in order to go directly to that file and check if the changes made from our endpoints were valid.
2. Returns the client to make the request and also the root of the config file. The latter is returned in order to check directly if the endpoints managed to change the said file with the intended updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed!

Comment on lines 4 to 5
# The line below is absolutely necessary. Fixtures are passed as arguments to test functions. That is why IDE could
# not recognized them.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# The line below is absolutely necessary. Fixtures are passed as arguments to test functions. That is why IDE could
# not recognized them.
# The line below is absolutely necessary. Fixtures are passed as arguments to test functions.
# This is why the IDE can't recognize them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

Comment on lines 13 to 14
# It is weird that this change does not appear in response.json()
# Because if request was successfully, the PUT request will change the flag "has_been_configured"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a FIXME: comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was reported and Pablo has already fixed it. :) The comment will be deleted.

api/tests/app/test_config.py Show resolved Hide resolved

from fastapi.testclient import TestClient

# from api.tests.utils.common_variables import default
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, deleted!

Comment on lines 22 to 23
# Here, to import ProcessorAPI successfully, "Settings" must be previously initialized with a config, that is why
# import order matters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Here, to import ProcessorAPI successfully, "Settings" must be previously initialized with a config, that is why
# import order matters
# Import ProcessorAPI after Settings has been initialized with a config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@renzodgc renzodgc merged commit 8a94648 into galliot-us:master Jan 25, 2021
@renzodgc renzodgc deleted the tests_api_processor_routers branch January 25, 2021 16:41
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

Successfully merging this pull request may close these issues.

3 participants