Skip to content

Commit

Permalink
fix datetime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BondarenkoStas committed Feb 11, 2021
1 parent a5761bb commit 7ec9b92
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
11 changes: 8 additions & 3 deletions src/codemagic/apple/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from dataclasses import dataclass
from datetime import datetime
from datetime import timezone
from typing import Any
from typing import Dict
from typing import List
Expand Down Expand Up @@ -73,8 +74,10 @@ class Links(DictSerializable):
_OMIT_IF_NONE_KEYS = ('related',)

def __init__(_self, self: Optional[str] = None, related: Optional[str] = None):
_self.self = self
_self.related = related
if self:
_self.self = self
if related:
_self.related = related


class ResourceLinks(DictSerializable):
Expand Down Expand Up @@ -221,7 +224,9 @@ def to_iso_8601(cls, dt: datetime) -> str:
def to_iso_8601(cls, dt: Optional[datetime]):
if dt is None:
return None
return dt.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + '+0000'
if dt.tzinfo == timezone.utc:
return dt.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + '+0000'
return dt.isoformat()

def _format_attribute_name(self, name: str) -> str:
type_prefix = self.type.value.rstrip('s')
Expand Down
2 changes: 1 addition & 1 deletion src/codemagic/utilities/argument_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def get_binary_arguments_value(value, not_value):
if not value and not not_value:
return None

return value or not not_value
return value or not not_value
23 changes: 0 additions & 23 deletions tests/apple/app_store_connect/builds/conftest.py

This file was deleted.

4 changes: 4 additions & 0 deletions tests/apple/resources/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import pytest

@pytest.fixture
def api_build() -> Dict:
mock_path = pathlib.Path(__file__).parent / 'mocks' / 'build.json'
return json.loads(mock_path.read_text())

@pytest.fixture
def api_bundle_id() -> Dict:
Expand Down
8 changes: 8 additions & 0 deletions tests/apple/resources/test_build_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

from codemagic.apple.resources import Build


def test_build_initialization(api_build):
build = Build(api_build)
assert build.dict() == api_build
3 changes: 2 additions & 1 deletion tests/apple/resources/test_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from datetime import datetime
from datetime import timedelta
from datetime import timezone

import pytest
Expand All @@ -22,7 +23,7 @@ def test_to_iso_8601(iso_8601_timestamp, expected_datetime):
@pytest.mark.parametrize('given_datetime, expected_iso_8601_timestamp', [
(None, None),
('2020-08-04T11:44:12.000+0000', datetime(2020, 8, 4, 11, 44, 12, tzinfo=timezone.utc)),
('2020-08-04T11:44:12+0000', datetime(2020, 8, 4, 11, 44, 12, tzinfo=timezone.utc)),
('2021-01-28T06:01:32-08:00', datetime(2021, 1, 28, 6, 1, 32, tzinfo=timezone(timedelta(days=-1, seconds=57600)))),
('1970-01-01T00:00:00.000+0000', datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone.utc)),
])
def test_from_iso_8601(given_datetime, expected_iso_8601_timestamp):
Expand Down

0 comments on commit 7ec9b92

Please sign in to comment.