Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jardin/query_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def add_to_where_values(self, key, value):
self.where_values[key] = v
keys += [':' + key]
return '(' + ', '.join(keys) + ')'

key = self.where_key(key)
self.where_values[key] = value

Expand Down Expand Up @@ -246,7 +246,7 @@ def write_values(self):
kw_values = kw_values.attributes
if isinstance(kw_values, dict):
kw_values = [kw_values]

kw_values = pd.DataFrame(kw_values).copy()
kw_values.reset_index(drop=True, inplace=True)

Expand Down Expand Up @@ -281,7 +281,7 @@ def values_list(self):
if isinstance(v, pd.Timestamp) and ((self.scheme == 'mysql' \
and sys.version_info[0] == 3) or self.scheme == 'sqlite'):
v = v.strftime('%Y-%m-%d %H:%M:%S')
if isinstance(v, pd._libs.tslib.NaTType):
if isinstance(v, type(pd.NaT)):
v = None
if isinstance(v, float) and np.isnan(v):
v = None
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ future==0.16.0
freezegun==0.3.10
PyMySQL==0.8.0
mysqlclient==1.3.12
snowflake-connector-python==1.5.6
snowflake-connector-python==1.5.6
mock==2.0.0
6 changes: 6 additions & 0 deletions tests/support/mydatetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import datetime

class _mydatetime(datetime.datetime):
@property
def nanosecond(self):
return 0
6 changes: 4 additions & 2 deletions tests/test_jardin.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import unittest
from mock import patch
from time import sleep
from freezegun import freeze_time
from datetime import datetime, timedelta
import pandas as pd

from tests import transaction
from tests.models import JardinTestModel

from support.mydatetime import _mydatetime

class User(JardinTestModel): pass


class TestModel(unittest.TestCase):

@patch('pandas.datetime', _mydatetime) #hack to fix https://github.com/spulec/freezegun/issues/242
@transaction(model=User)
def test_created_at_updated_at(self):
user = User.insert(values={'name': 'Jardinier'})
Expand All @@ -35,7 +37,7 @@ def test_no_created_at_updated_at(self):
if User.db().db_config.scheme == 'sqlite':
User.query(
sql='CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(256));'
)
)
else:
User.query(
sql='CREATE TABLE users (id serial PRIMARY KEY, name varchar(256));'
Expand Down
3 changes: 3 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from mock import patch
import pandas as pd
from freezegun import freeze_time
from datetime import datetime, timedelta
Expand All @@ -11,6 +12,7 @@
from tests import transaction

from tests.models import JardinTestModel
from support.mydatetime import _mydatetime


class Project(JardinTestModel):
Expand Down Expand Up @@ -163,6 +165,7 @@ def test_having(self):
users = User.select(select='name', group='name', having='COUNT(*) > 1')
self.assertEqual(len(users), 1)

@patch('pandas.datetime', _mydatetime) #hack to fix https://github.com/spulec/freezegun/issues/242
@transaction(model=User)
def test_touch(self):
user = User.insert(values={'name': 'Jardin'})
Expand Down