Defect #31388
ApiTest fails if config.time_zone is set
Status: | Closed | Start date: | ||
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | % Done: | 0% | ||
Category: | Code cleanup/refactoring | |||
Target version: | 4.1.0 | |||
Resolution: | Fixed | Affected version: |
Description
ApiTest fails if config.time_zone is set. The tests suppose that time in API response is always in UTC, but it varies depending on the value of config.time_zone is set.
Set config.time_zone
in config/additional_environment.rb
.
config.time_zone = 'Tokyo'
Run test/integration/api_test/api_test.rb
. It fails. In the following example, the test expected that created_on in the response was "2006-07-19T17:12:21Z", but actually it was "2006-07-20T02:12:21+09:00".
$ bin/rails test test/integration/api_test/api_test.rb Run options: --seed 57420 # Running: .F Failure: Redmine::ApiTest::ApiTest#test_json_datetime_format [/Users/maeda/redmines/redmine-trunk/test/integration/api_test/api_test.rb:43]: ""created_on":"2006-07-19T17:12:21Z"" not found in "{"user":{"id":1,"login":"admin","admin":true,"firstname":"Redmine","lastname":"Admin","mail":"admin@somenet.foo","created_on":"2006-07-20T02:12:21+09:00","last_login_on":"2019-05-18T08:30:27+09:00","api_key":"9b0dd9bb5f4dcb890696137385999b2569f24631","status":1,"custom_fields":[{"id":4,"name":"Phone number","value":null},{"id":5,"name":"Money","value":null}]}}" bin/rails test test/integration/api_test/api_test.rb:41 .F Failure: Redmine::ApiTest::ApiTest#test_xml_datetime_format [/Users/maeda/redmines/redmine-trunk/test/integration/api_test/api_test.rb:48]: "<created_on>2006-07-19T17:12:21Z</created_on>" not found in "<?xml version="1.0" encoding="UTF-8"?><user><id>1</id><login>admin</login><admin>true</admin><firstname>Redmine</firstname><lastname>Admin</lastname><mail>admin@somenet.foo</mail><created_on>2006-07-20T02:12:21+09:00</created_on><last_login_on>2019-05-18T08:30:27+09:00</last_login_on><api_key>4bfca692e987af9ce73c77b1f31f79a11bbd3e4c</api_key><status>1</status><custom_fields type="array"><custom_field id="4" name="Phone number"><value/></custom_field><custom_field id="5" name="Money"><value/></custom_field></custom_fields></user>" bin/rails test test/integration/api_test/api_test.rb:46 Finished in 1.001562s, 3.9938 runs/s, 5.9906 assertions/s. 4 runs, 6 assertions, 2 failures, 0 errors, 0 skips
Associated revisions
ApiTest fails if config.time_zone is set (#31388).
Patch by Yuichi HARADA.
History
#3
Updated by Go MAEDA 7 months ago
- Category changed from REST API to Code cleanup/refactoring
Go MAEDA wrote:
Should we update the test code or always fix the time zone for API responses to UTC?
I think we should fix the test, not API. Looking at the API documents, the time zone in the response is not supposed to be fixed to UTC.
#4
Updated by Yuichi HARADA 6 months ago
- File 31388_apitest_failed.patch
added
I have fixed the API tests. It does not depend on UTC time zone.