Skip to content

Commit

Permalink
Merge pull request #28 from winged/do_not_expect_timestamp_in_snapsho…
Browse files Browse the repository at this point in the history
…t_dict

Do not expect dict-snapshots to contain timestamps
  • Loading branch information
Jean-Louis Fuchs committed Sep 26, 2016
2 parents c315d60 + 8e09e16 commit c31601c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pyaptly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,9 @@ def snapshot_spec_to_name(cfg, snapshot):
delta = datetime.timedelta(seconds=1)
if hasattr(snapshot, 'items'):
name = snapshot['name']
if 'timestamp' not in snapshot:
return name

ts = snapshot['timestamp']
back_ref = back_reference_map.get(ts)
if back_ref is None:
Expand Down
25 changes: 22 additions & 3 deletions pyaptly/aptly_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import freezegun
import testfixtures

from pyaptly import Command, SystemStateReader, call_output, main
from pyaptly import (Command, SystemStateReader, call_output, main,
snapshot_spec_to_name)

from . import test

Expand Down Expand Up @@ -739,12 +740,12 @@ def test_publish_updating_basic():
'fakerepo02-20121006T0000Z',
'fakerepo01-20121010T0000Z',
])
assert expect == state.snapshots
assert expect == state.snapshots
expect = {
'fakerepo02 main': set(['fakerepo02-20121006T0000Z']),
'fakerepo01 main': set(['fakerepo01-20121011T0000Z'])
}
assert expect == state.publish_map
assert expect == state.publish_map


def do_repo_create(config):
Expand Down Expand Up @@ -815,3 +816,21 @@ def test_repo_create_basic():
b"repo.yml",
)) as (tyml, config):
do_repo_create(config)


def test_snapshot_spec_as_dict():
"Test various snapshot formats for snapshot_spec_to_name()"

snap_string = 'snapshot-foo'
snap_dict = {
'name': 'foo'
}

cfg = {
'snapshot': {
'foo': {},
}
}

assert snapshot_spec_to_name(cfg, snap_string) == snap_string
assert snapshot_spec_to_name(cfg, snap_dict) == 'foo'

0 comments on commit c31601c

Please sign in to comment.