Skip to content

Conversation

@yuryfirebolt
Copy link
Contributor

No description provided.

Comment on lines 125 to 138
@pytest.fixture
def mock_db_name() -> str:
return "mock_database"


@pytest.fixture
def db_description() -> str:
return "database description"


@pytest.fixture
def mock_db_description() -> str:
return "mock database description"

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between db_name, db_description and their mock counterparts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

db_name (and db_description) fixtures are used everywhere, which leads to cases, when the parameter passing is not being checked correctly. For example in tests/unit/service/test_database.py:33, previously if we would pass something different to the database = manager.databases.create(name="other_db_name"), the next check assert database.name == db_name would still work correctly, which is a wrong behaviour.
In my opinion, all listed fixtures are unnecessary, however removing them would lead to a lot of refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how changing the name in the mock fixes the issue you're outlining. In test_database.py:33 when a new name is passed to manager.databases.create nothing changes since httpx still has the databases url callback mocked to return the result with db_name, which passes the assert below. If that's modified to use mock_db_name the issue still stands e.g. manager.databases.create(name="yet_another_db_name") would pass the assert database.name == "other_db_name".
I think in order to fix this and avoid any mistakes made in testing we can check what's being sent to the mock API in the test itself. e.g. httpx_mock.get_request( <insert_expected_request_here> )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After decoupling the parameters, the test_databases_create started to fail, showing us that, there is an issue. Having just one db_name, that we use everywhere obfuscates such problems.

By splitting db_name and mock_db_name I didn't fix the issue. The issue was fixed by extending the create_databases_callback.

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like we're testing the fixture and not the sdk itself.
My suggestion would be to remove the mock_database fixture from the callback function and create another database object inside a callback with provided parameters, and then return it's dict(). This way it seems to be simpler and representative.
Depending on different database names seems too implicit and not very obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As suggested by @stepansergeevitch, I would remove both use mock_database as a function, then the mock_db_name mock_db_description would not be needed anymore, and I will remove them as well. @ptiurin are you fine with this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Contributor Author

@yuryfirebolt yuryfirebolt Jan 13, 2022

Choose a reason for hiding this comment

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

I figured, that mock_database is used much more than I thought, so this solution is also not optimal. I will try to find something more elegant

) -> Response:
database_properties = json.loads(request.read().decode("utf-8"))["database"]

mock_database.name = database_properties["name"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we can just return database_properties as json parameter in to_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.

the mock_database fixture set some additional default parameters, e.g. database_id. I would prefer to keep the responsibility for the default parameters to the mock_database function.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@yuryfirebolt yuryfirebolt requested a review from ptiurin January 14, 2022 11:04
Copy link
Contributor

@ptiurin ptiurin left a comment

Choose a reason for hiding this comment

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

lgtm

@yuryfirebolt yuryfirebolt merged commit 08743e2 into main Jan 17, 2022
@yuryfirebolt yuryfirebolt deleted the database-create-with-description branch January 17, 2022 08: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.

4 participants