Skip to content

Conversation

@EliuX
Copy link
Contributor

@EliuX EliuX commented Mar 24, 2020

This PR:

  • Fixes the issue related to the random lose of data
  • Test persistence of the API namespace for projects

This will set the foundation for future tests of the persistence of API namespaces, covering 100% of it.

api.init_app(app)

if app.config.get('DEBUG'):
app.logger.setLevel(logging.INFO)
Copy link
Contributor

Choose a reason for hiding this comment

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

should not be app.logger.setLevel(logging.DEBUG)?

Copy link
Contributor Author

@EliuX EliuX Mar 24, 2020

Choose a reason for hiding this comment

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

IMHO logging.INFO is detailed enough.

SECRET_KEY = generate_dev_secret_key()
DATABASE_URI = os.environ.get('DATABASE_URI')
PROPAGATE_EXCEPTIONS = True
RESTPLUS_VALIDATE = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Good.



def test_list_all_projects(client: FlaskClient, mocker: MockFixture):
from time_tracker_api.projects.projects_namespace import project_dao
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice, you are calling from time_tracker_api.projects.projects_namespace import project_dao in all the tests.

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, if I do it before the project_dao would be broken because it has to be constructed after the app instance is ready. This is a necessary evil.

repository_create_mock.assert_called_once_with(valid_project_data)


def test_create_project_should_reject_bad_request(client: FlaskClient, mocker: MockFixture):
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 we can use the name test_create_project_should_fail_with_invalid_request for consistency with the previous request.

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 would rather to leave bad request because that is the verbose name of the HTTP status code 400.

repository_create_mock.assert_not_called()


def test_list_all_projects(client: FlaskClient, mocker: MockFixture):
Copy link
Contributor

Choose a reason for hiding this comment

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

What about test_get_all_projects or test_get_projects?

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 description in the comments says list. As long as it makes sense and it is not ambiguous we are Ok.

repository_find_mock.assert_called_once_with(str(invalid_id))


def update_project_should_succeed_with_valid_data(client: FlaskClient, mocker: MockFixture):
Copy link
Contributor

Choose a reason for hiding this comment

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

You are missing the test_ prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch

repository_update_mock.assert_called_once_with(valid_id, valid_project_data)


def test_update_project_should_reject_bad_request(client: FlaskClient, mocker: MockFixture):
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 we can use the name test_update_project_should_fail_with_invalid_request as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bad request is better

@EliuX EliuX force-pushed the feature/Persist-projects-ns-#38 branch from e7ee5f6 to e8e225a Compare March 24, 2020 18:48
@EliuX EliuX force-pushed the feature/Persist-projects-ns-#38 branch from e8e225a to 4ce4612 Compare March 24, 2020 18:49
@EliuX EliuX merged commit 777f677 into master Mar 24, 2020
@EliuX EliuX deleted the feature/Persist-projects-ns-#38 branch March 24, 2020 18:57
@EliuX EliuX self-assigned this Apr 17, 2020
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.

5 participants