Skip to content

Commit

Permalink
fix: convert datetime back to proto for unit tests (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored Jul 10, 2020
1 parent c7c63f2 commit e1c787d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from unittest import mock
import grpc
import math
import pytest
from proto.marshal.rules.dates import DurationRule, TimestampRule

{# Import the service itself as well as every proto module that it imports. -#}
{% filter sort_lines -%}
Expand Down Expand Up @@ -371,7 +372,13 @@ def test_{{ method.name|snake_case }}_flattened():
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
{% for key, field in method.flattened_fields.items() -%}{%- if not field.oneof or field.proto3_optional %}
{% if field.ident|string() == 'timestamp.Timestamp' -%}
assert TimestampRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% elif field.ident|string() == 'duration.Duration' -%}
assert DurationRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% else -%}
assert args[0].{{ key }} == {{ field.mock_value }}
{% endif %}
{% endif %}{% endfor %}
{%- for oneofs in method.flattened_oneof_fields().values() %}
{%- with field = oneofs[-1] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import grpc
from grpc.experimental import aio
import math
import pytest
from proto.marshal.rules.dates import DurationRule, TimestampRule

{# Import the service itself as well as every proto module that it imports. -#}
{% filter sort_lines -%}
Expand Down Expand Up @@ -574,7 +575,13 @@ def test_{{ method.name|snake_case }}_flattened():
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
{% for key, field in method.flattened_fields.items() -%}{%- if not field.oneof or field.proto3_optional %}
{% if field.ident|string() == 'timestamp.Timestamp' -%}
assert TimestampRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% elif field.ident|string() == 'duration.Duration' -%}
assert DurationRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% else -%}
assert args[0].{{ key }} == {{ field.mock_value }}
{% endif %}
{% endif %}{% endfor %}
{%- for oneofs in method.flattened_oneof_fields().values() %}
{%- with field = oneofs[-1] %}
Expand Down Expand Up @@ -653,7 +660,13 @@ async def test_{{ method.name|snake_case }}_flattened_async():
assert len(call.mock_calls)
_, args, _ = call.mock_calls[0]
{% for key, field in method.flattened_fields.items() -%}{%- if not field.oneof or field.proto3_optional %}
{% if field.ident|string() == 'timestamp.Timestamp' -%}
assert TimestampRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% elif field.ident|string() == 'duration.Duration' -%}
assert DurationRule().to_proto(args[0].{{ key }}) == {{ field.mock_value }}
{% else -%}
assert args[0].{{ key }} == {{ field.mock_value }}
{% endif %}
{% endif %}{% endfor %}
{%- for oneofs in method.flattened_oneof_fields().values() %}
{%- with field = oneofs[-1] %}
Expand Down

0 comments on commit e1c787d

Please sign in to comment.