Skip to content

Commit 17f8d42

Browse files
authored
fix unittest (#58)
* fix unittest * fix typehit * fix styles * fix unittest
1 parent 857343f commit 17f8d42

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

pydataapi/pydataapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ def create_sql_parameter(key: str, value: Any) -> Dict[str, Any]:
170170
converted_value = {STRING_VALUE: str(value)}
171171
type_hint = DECIMAL_TYPE_HINT
172172
elif isinstance(value, datetime):
173-
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d %H:%M:%S.%f')[:23]}
173+
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d %H:%M:%S.%f')}
174174
type_hint = TIMESTAMP_TYPE_HINT
175175
elif isinstance(value, time):
176-
converted_value = {STRING_VALUE: value.strftime('%H:%M:%S.%f')[:12]}
176+
converted_value = {STRING_VALUE: value.strftime('%H:%M:%S.%f')}
177177
type_hint = TIME_TYPE_HINT
178178
elif isinstance(value, date):
179179
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d')}

tests/integration/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.1'
22

33
services:
44
local-data-api-mysql:
5-
image: koxudaxi/local-data-api:0.4.1
5+
image: koxudaxi/local-data-api:0.4.7
66
restart: always
77
environment:
88
MYSQL_HOST: mysql

tests/integration/test_mysql.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def db_connection(module_scoped_container_getter) -> Connection:
5858
def create_table(db_connection) -> None:
5959
db_connection.execute('drop table if exists pets;')
6060
db_connection.execute(
61-
'create table pets (id int auto_increment not null primary key, name varchar(10), seen_at TIMESTAMP null);'
61+
'create table pets (id int auto_increment not null primary key, name varchar(10), seen_at TIMESTAMP(6) null);'
6262
)
6363

6464

@@ -230,14 +230,10 @@ def test_dialect(create_table) -> None:
230230
Session.configure(bind=engine)
231231
session = Session()
232232

233-
dog = Pets(name="dog", seen_at=datetime(2020, 1, 2, 3, 4, 5, 6789))
233+
dog = Pets(name="dog", seen_at=datetime(2020, 1, 2, 3, 4, 5, 678912))
234234

235235
session.add(dog)
236236
session.commit()
237237

238238
result = list(engine.execute('select * from pets'))
239-
assert result[0] == (
240-
1,
241-
'dog',
242-
'2020-01-02 03:04:05',
243-
) # TODO Update local-data-api to support typeHint
239+
assert result[0] == (1, 'dog', '2020-01-02 03:04:05.678912',)

tests/pydataapi/test_pydataapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def __str__(self):
7979
}
8080

8181
assert create_sql_parameter(
82-
'datetime', datetime.datetime(2020, 1, 2, 3, 4, 5, 678900)
82+
'datetime', datetime.datetime(2020, 1, 2, 3, 4, 5, 678912)
8383
) == {
8484
'name': 'datetime',
8585
'typeHint': 'TIMESTAMP',
86-
'value': {'stringValue': '2020-01-02 03:04:05.678'},
86+
'value': {'stringValue': '2020-01-02 03:04:05.678912'},
8787
}
8888

8989
assert create_sql_parameter('date', datetime.date(2020, 1, 2)) == {
@@ -92,10 +92,10 @@ def __str__(self):
9292
'value': {'stringValue': '2020-01-02'},
9393
}
9494

95-
assert create_sql_parameter('time', datetime.time(3, 4, 5, 678900)) == {
95+
assert create_sql_parameter('time', datetime.time(3, 4, 5, 678912)) == {
9696
'name': 'time',
9797
'typeHint': 'TIME',
98-
'value': {'stringValue': '03:04:05.678'},
98+
'value': {'stringValue': '03:04:05.678912'},
9999
}
100100

101101

0 commit comments

Comments
 (0)