Commit 0b624086 authored by Harrison Wright's avatar Harrison Wright Committed by Philipp Schmitt
Browse files

Fix datetime comparison when there is no tzinfo and autotype sequence none check (#116)

* Fix datetime comparison when there is no tzinfo

 Along for the ride is a fix for when autotype sequence is None

* Bump version

* Revert "Bump version"

This reverts commit b5f317113d39b89ae3143694cad041b4d0c2e21f.

* Add test for utc offset

* Add test for missing autotype sequence

* Fix typo
parent b0c4978c
......@@ -78,7 +78,7 @@ class BaseElement(object):
def _datetime_to_utc(self, dt):
"""Convert naive datetimes to UTC"""
if not dt.tzinfo:
dt = dt.replace(tzinfo=tz.gettz())
return dt.astimezone(tz.gettz('UTC'))
......@@ -150,7 +150,9 @@ class BaseElement(object):
def expired(self):
return self.expires and (datetime.utcnow() > self.expiry_time)
if self.expires:
return self._datetime_to_utc(datetime.utcnow()) > self._datetime_to_utc(self.expiry_time)
return False
......@@ -177,7 +177,8 @@ class Entry(BaseElement):
def autotype_sequence(self):
return self._element.find('AutoType/DefaultSequence').text
sequence = self._element.find('AutoType/DefaultSequence')
return sequence.text if sequence else None
def autotype_sequence(self, value):
......@@ -4,6 +4,7 @@ from pykeepass import icons, PyKeePass
from pykeepass.entry import Entry
from import Group
from pykeepass.kdbx_parsing import KDBX
from lxml.etree import Element
import os
import shutil
import unittest
......@@ -346,6 +347,35 @@ class EntryTests(unittest.TestCase):
entry.tags = ['changed', 'again', 'tags']
self.assertEqual(entry.tags, ['changed', 'again', 'tags'])
def test_expired_datetime_offset(self):
"""Test for"""
future_time = + timedelta(days=1)
past_time = - timedelta(days=1)
entry = Entry(
entry.expiry_time = past_time
def test_autotype_no_default_sequence(self):
entry = Entry(
# create an element, but one without AutoType
class GroupTests(unittest.TestCase):
# get some things ready before testing
def setUp(self):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment