Projet

Général

Profil

0001-toulouse-smart-use-post-transition-time-to-resolve-r.patch

Nicolas Roche, 17 octobre 2022 15:48

Télécharger (2,79 ko)

Voir les différences:

Subject: [PATCH] toulouse-smart: use post-transition time to resolve reverting
 from DST (#70309)

 passerelle/contrib/toulouse_smart/utils.py | 2 +-
 tests/test_toulouse_smart.py               | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
passerelle/contrib/toulouse_smart/utils.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.utils.dateparse import parse_datetime
18 18
from django.utils.timezone import localtime, make_aware, make_naive, utc
19 19

  
20 20

  
21 21
def localtz_to_utc(date_time_string):
22
    aware_dt_in_utc = make_aware(parse_datetime(date_time_string)).astimezone(utc)
22
    aware_dt_in_utc = make_aware(parse_datetime(date_time_string), is_dst=False).astimezone(utc)
23 23
    return aware_dt_in_utc.isoformat()
24 24

  
25 25

  
26 26
def utc_to_localtz(date_time_string):
27 27
    aware_dt_in_local_tz = localtime(parse_datetime(date_time_string))
28 28
    return make_naive(aware_dt_in_local_tz).isoformat()
tests/test_toulouse_smart.py
36 36
import tests.utils
37 37
from passerelle.base.models import Job
38 38
from passerelle.contrib.toulouse_smart.models import (
39 39
    SmartRequest,
40 40
    ToulouseSmartResource,
41 41
    WcsRequest,
42 42
    WcsRequestFile,
43 43
)
44
from passerelle.contrib.toulouse_smart.utils import localtz_to_utc, utc_to_localtz
44 45
from tests.test_manager import login
45 46

  
46 47
TEST_BASE_DIR = os.path.join(os.path.dirname(__file__), 'data', 'toulouse_smart')
47 48

  
48 49

  
49 50
@pytest.fixture
50 51
def smart(db, settings):
51 52
    settings.TIME_ZONE = 'Europe/Paris'
......
125 126
        return desc.read()
126 127

  
127 128

  
128 129
def get_media_file(filename):
129 130
    with open(os.path.join(TEST_BASE_DIR, "%s" % filename), 'rb') as desc:
130 131
        return desc.read()
131 132

  
132 133

  
134
def test_save_daylight_time_change(settings):
135
    settings.TIME_ZONE = 'Europe/Paris'
136
    settings.USE_TZ = True
137
    assert localtz_to_utc('2022-10-30T02:19:48') == '2022-10-30T01:19:48+00:00'
138
    assert utc_to_localtz('2022-10-30T01:19:48+00:00') == '2022-10-30T02:19:48'
139

  
140

  
133 141
@mock_response(['/v1/type-intervention', None, b'<List></List>'])
134 142
def test_empty_intervention_types(smart):
135 143
    assert smart.get_intervention_types() == []
136 144

  
137 145

  
138 146
INTERVENTION_TYPES = '''<List>
139 147
   <item>
140 148
       <id>1234</id>
141
-