Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unittest #58

Merged
merged 4 commits into from
Feb 26, 2020
Merged
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
4 changes: 2 additions & 2 deletions pydataapi/pydataapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ def create_sql_parameter(key: str, value: Any) -> Dict[str, Any]:
converted_value = {STRING_VALUE: str(value)}
type_hint = DECIMAL_TYPE_HINT
elif isinstance(value, datetime):
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d %H:%M:%S.%f')[:23]}
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d %H:%M:%S.%f')}
type_hint = TIMESTAMP_TYPE_HINT
elif isinstance(value, time):
converted_value = {STRING_VALUE: value.strftime('%H:%M:%S.%f')[:12]}
converted_value = {STRING_VALUE: value.strftime('%H:%M:%S.%f')}
type_hint = TIME_TYPE_HINT
elif isinstance(value, date):
converted_value = {STRING_VALUE: value.strftime('%Y-%m-%d')}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.1'

services:
local-data-api-mysql:
image: koxudaxi/local-data-api:0.4.1
image: koxudaxi/local-data-api:0.4.7
restart: always
environment:
MYSQL_HOST: mysql
Expand Down
10 changes: 3 additions & 7 deletions tests/integration/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def db_connection(module_scoped_container_getter) -> Connection:
def create_table(db_connection) -> None:
db_connection.execute('drop table if exists pets;')
db_connection.execute(
'create table pets (id int auto_increment not null primary key, name varchar(10), seen_at TIMESTAMP null);'
'create table pets (id int auto_increment not null primary key, name varchar(10), seen_at TIMESTAMP(6) null);'
)


Expand Down Expand Up @@ -230,14 +230,10 @@ def test_dialect(create_table) -> None:
Session.configure(bind=engine)
session = Session()

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

session.add(dog)
session.commit()

result = list(engine.execute('select * from pets'))
assert result[0] == (
1,
'dog',
'2020-01-02 03:04:05',
) # TODO Update local-data-api to support typeHint
assert result[0] == (1, 'dog', '2020-01-02 03:04:05.678912',)
8 changes: 4 additions & 4 deletions tests/pydataapi/test_pydataapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def __str__(self):
}

assert create_sql_parameter(
'datetime', datetime.datetime(2020, 1, 2, 3, 4, 5, 678900)
'datetime', datetime.datetime(2020, 1, 2, 3, 4, 5, 678912)
) == {
'name': 'datetime',
'typeHint': 'TIMESTAMP',
'value': {'stringValue': '2020-01-02 03:04:05.678'},
'value': {'stringValue': '2020-01-02 03:04:05.678912'},
}

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

assert create_sql_parameter('time', datetime.time(3, 4, 5, 678900)) == {
assert create_sql_parameter('time', datetime.time(3, 4, 5, 678912)) == {
'name': 'time',
'typeHint': 'TIME',
'value': {'stringValue': '03:04:05.678'},
'value': {'stringValue': '03:04:05.678912'},
}


Expand Down