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

feat(storage): add support of daysSinceNoncurrentTime and noncurrentTimeBefore #162

Merged
merged 21 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8677bdf
feat(storage): add support of daysSinceNoncurrentTime and noncurrentT…
HemangChothani May 27, 2020
463c75d
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani May 27, 2020
d6351ab
feat(storage): fix code coverage
HemangChothani May 28, 2020
8b5b67f
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani May 28, 2020
b866ffc
feat(storage): add custom method to convert datetime to string
HemangChothani May 28, 2020
39ff644
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jun 12, 2020
be50284
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jun 17, 2020
73030c6
feat(storage): remove custom method as server support microsec
HemangChothani Jun 23, 2020
1e8c3e0
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jun 23, 2020
26c3990
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Jun 24, 2020
63f90dd
Merge branch 'master' into storage_issue_159
jkwlui Jul 7, 2020
f1b3fed
feat(storage): change the return type of noncurrent_time_before
HemangChothani Jul 17, 2020
a51ebf0
Merge branch 'storage_issue_159' of https://github.com/q-logic/python…
HemangChothani Jul 17, 2020
c314fa2
feat(storage): change non_current_time type from datetime to date
HemangChothani Aug 7, 2020
6ca1e26
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 7, 2020
0f25ddf
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 13, 2020
465af75
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 17, 2020
5494c57
Merge branch 'master' into storage_issue_159
frankyn Aug 24, 2020
4b51e38
feat: nit
HemangChothani Aug 25, 2020
bd2edda
Merge branch 'storage_issue_159' of https://github.com/q-logic/python…
HemangChothani Aug 25, 2020
c805a01
Merge branch 'master' of https://github.com/googleapis/python-storage…
HemangChothani Aug 25, 2020
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
Prev Previous commit
Next Next commit
feat(storage): change non_current_time type from datetime to date
  • Loading branch information
HemangChothani committed Aug 7, 2020
commit c314fa2e8c4ef297f589a35a95407db1240c79fc
16 changes: 7 additions & 9 deletions google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class LifecycleRuleConditions(dict):
will become eligible for lifecycle action as soon as it becomes
non current.

:type noncurrent_time_before: :class:`datetime.datetime`
:param noncurrent_time_before: (Optional) Datetime object parsed from RFC3339 valid timestamp, apply
rule action to items whose non current time is before this timestamp.
:type noncurrent_time_before: :class:`datetime.date`
:param noncurrent_time_before: (Optional) Date object parsed from iso8601 valid date, apply
Copy link
Contributor

@frankyn frankyn Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use RFC3339 and provide an example: 2019-03-16

rule action to items whose non current time is before this date.
This condition is relevant only for versioned objects.

:raises ValueError: if no arguments are passed.
Expand Down Expand Up @@ -221,9 +221,7 @@ def __init__(
conditions["daysSinceNoncurrentTime"] = days_since_noncurrent_time

if noncurrent_time_before is not None:
conditions["noncurrentTimeBefore"] = _datetime_to_rfc3339(
noncurrent_time_before
)
conditions["noncurrentTimeBefore"] = noncurrent_time_before.isoformat()

super(LifecycleRuleConditions, self).__init__(conditions)

Expand Down Expand Up @@ -276,9 +274,9 @@ def days_since_noncurrent_time(self):
@property
def noncurrent_time_before(self):
"""Conditon's 'noncurrent_time_before' value."""
timestamp = self.get("noncurrentTimeBefore")
if timestamp is not None:
return _rfc3339_to_datetime(timestamp)
before = self.get("noncurrentTimeBefore")
if before is not None:
return datetime_helpers.from_iso8601_date(before)


class LifecycleRuleDelete(dict):
Expand Down
2 changes: 1 addition & 1 deletion tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_lifecycle_rules(self):
from google.cloud.storage import constants

new_bucket_name = "w-lifcycle-rules" + unique_resource_id("-")
noncurrent_before = datetime.datetime.now() + datetime.timedelta(days=10)
noncurrent_before = datetime.date(2018, 8, 1)
self.assertRaises(
exceptions.NotFound, Config.CLIENT.get_bucket, new_bucket_name
)
Expand Down
16 changes: 4 additions & 12 deletions tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,15 @@ def test_ctor_w_days_since_noncurrent_time(self):

def test_ctor_w_noncurrent_time_before(self):
import datetime
import pytz
from google.cloud._helpers import _datetime_to_rfc3339

noncurrent_before = datetime.datetime.utcnow().replace(
tzinfo=pytz.UTC
) + datetime.timedelta(days=10)
noncurrent_before = datetime.date(2018, 8, 1)
conditions = self._make_one(
number_of_newer_versions=3, noncurrent_time_before=noncurrent_before
)

expected = {
"numNewerVersions": 3,
"noncurrentTimeBefore": _datetime_to_rfc3339(noncurrent_before),
"noncurrentTimeBefore": noncurrent_before.isoformat(),
}
self.assertEqual(dict(conditions), expected)
self.assertIsNone(conditions.age)
Expand All @@ -128,12 +124,8 @@ def test_ctor_w_noncurrent_time_before(self):

def test_from_api_repr(self):
import datetime
import pytz
from google.cloud._helpers import _datetime_to_rfc3339

noncurrent_before = datetime.datetime.utcnow().replace(
tzinfo=pytz.UTC
) + datetime.timedelta(days=10)
noncurrent_before = datetime.date(2018, 8, 1)
before = datetime.date(2018, 8, 1)
klass = self._get_target_class()

Expand All @@ -144,7 +136,7 @@ def test_from_api_repr(self):
"matchesStorageClass": ["COLDLINE"],
"numNewerVersions": 3,
"daysSinceNoncurrentTime": 2,
"noncurrentTimeBefore": _datetime_to_rfc3339(noncurrent_before),
"noncurrentTimeBefore": noncurrent_before.isoformat(),
}
conditions = klass.from_api_repr(resource)
self.assertEqual(conditions.age, 10)
Expand Down