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

Add timezone and use_utc parameters into RegisterTortoise class. #1649

Merged
merged 8 commits into from
Jun 18, 2024

Conversation

Abeautifulsnow
Copy link
Contributor

@Abeautifulsnow Abeautifulsnow commented Jun 13, 2024

Description

A detailed description can be found here: #1632

Motivation and Context

There are no timezone and utc configurations which can be applied to RegisterTortoise class when using db_url to initialize a sql connection. I've made them available in RegisterTortoise, allowing users to conveniently specify these settings.

How Has This Been Tested?

There are no side effects on other areas of the code. It just introduces two parameters within the RegisterTortoise. I have tested it within my project, and it works with these settings specified. #1632

And can also be tested with:

cd examples/fastapi && PYTHONPATH=. pytest _tests.py

I have also added test cases for the modified parts and passed the self-test.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@abondar
Copy link
Member

abondar commented Jun 16, 2024

@Abeautifulsnow seems like tests are failing

@Abeautifulsnow
Copy link
Contributor Author

@Abeautifulsnow seems like tests are failing

Ummm... It seems I know where the problem lies. My two test assertions timezones are both based on Asia/Shanghai. Then where is the timezone of the CI test environment? Or maybe I should add more code to adjust the timezone to ensure the test passes?

@abondar
Copy link
Member

abondar commented Jun 17, 2024

Yeah, you would need to somehow modify it, so it doesn't rely on what environment it is, as github action do not give any guarantees regarding their timezones

@Abeautifulsnow
Copy link
Contributor Author

The changes has been Done! @abondar

@Abeautifulsnow
Copy link
Contributor Author

Abeautifulsnow commented Jun 18, 2024

_____________ TestModelMethods.test_update_or_create_with_defaults _____________
[gw3] linux -- Python 3.8.18 /opt/hostedtoolcache/Python/3.8.18/x64/bin/python3.8
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
    yield
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 676, in run
    self._callTestMethod(testMethod)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/async_case.py", line 65, in _callTestMethod
    self._callMaybeAsync(method)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/async_case.py", line 88, in _callMaybeAsync
    return self._asyncioTestLoop.run_until_complete(fut)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/async_case.py", line 102, in _asyncioLoopRunner
    ret = await awaitable
  File "/home/runner/work/tortoise-orm/tortoise-orm/tests/test_model_methods.py", line 186, in test_update_or_create_with_defaults
    await self.cls.update_or_create(id=mdl.id, defaults=mdl_dict)
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 227, in __exit__
    self._raiseFailure("{} not raised".format(exc_name))
  File "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/unittest/case.py", line 164, in _raiseFailure
    raise self.test_case.failureException(msg)
AssertionError: ParamsError not raised

=========================== short test summary info ============================
FAILED tests/test_model_methods.py::TestModelMethods::test_update_or_create_with_defaults - AssertionError: ParamsError not raised
1 failed, 1102 passed, 80 skipped, 3 xfailed, 50 warnings in 58.54s
make: *** [Makefile:53: test_postgres_psycopg] Error 1
Error: Process completed with exit code 2.

It seems the issue is due to other test files, not my own. Could you please check it out? Thank you.

@coveralls
Copy link

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9559957832

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.006%) to 89.055%

Files with Coverage Reduction New Missed Lines %
tortoise/contrib/fastapi/init.py 2 63.44%
Totals Coverage Status
Change from base Build 9543663341: 0.006%
Covered Lines: 5870
Relevant Lines: 6494

💛 - Coveralls

@abondar abondar merged commit bc18384 into tortoise:develop Jun 18, 2024
7 checks passed
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.

None yet

3 participants