Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #362 from alphagov/fix-integer-auto-id-error
Browse files Browse the repository at this point in the history
Fix integer auto id error
  • Loading branch information
robyoung committed Sep 23, 2014
2 parents 0f07512 + d8e0022 commit 610ba68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backdrop/core/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _generate_auto_id(record, auto_id_keys):
', '.join(missing_keys)))

return b64encode('.'.join(
record[key] for key in auto_id_keys))
str(record[key]) for key in auto_id_keys))


def parse_timestamp(record):
Expand Down
20 changes: 20 additions & 0 deletions tests/core/test_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from unittest import TestCase
from hamcrest import assert_that, is_
from nose.tools import assert_raises
from backdrop.core.records import _generate_auto_id
from backdrop.core.errors import ValidationError


class TestRecords(TestCase):
def test__generate_auto_id_generates_auto_ids_correctly_for_standard_case(self):
assert_that(_generate_auto_id({'foo': 'foo'}, ['foo']), is_('Zm9v'))

def test__generate_auto_id_generates_auto_ids_correctly_for_integers(self):
assert_that(_generate_auto_id({'foo': 1, 'bar': 'foo'}, ['foo', 'bar']), is_('MS5mb28='))

def test__generate_auto_id_throws_error_when_key_not_matched(self):
assert_raises(
ValidationError,
_generate_auto_id,
{'foo': 1},
['bar'])

0 comments on commit 610ba68

Please sign in to comment.