diff options
| -rw-r--r-- | lesana/collection.py | 4 | ||||
| -rw-r--r-- | lesana/types.py | 8 | ||||
| -rw-r--r-- | tests/test_collection.py | 4 | ||||
| -rw-r--r-- | tests/test_types.py | 46 | 
4 files changed, 31 insertions, 31 deletions
| diff --git a/lesana/collection.py b/lesana/collection.py index cb43d1d..a78de2b 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -118,7 +118,7 @@ class Entry(object):          except jinja2.exceptions.TemplateSyntaxError as e:              raise TemplatingError('Template Syntax Error: ' + str(e)) -    def update(self): +    def auto(self):          """          Update all fields of this entry, as required by the field settings. @@ -129,7 +129,7 @@ class Entry(object):          need to save the entry yourself.          """          for name, field in self.collection.fields.items(): -            self.data[name] = field.update(self.data.get(name, None)) +            self.data[name] = field.auto(self.data.get(name, None))  class Collection(object): diff --git a/lesana/types.py b/lesana/types.py index da67781..3e9450a 100644 --- a/lesana/types.py +++ b/lesana/types.py @@ -27,7 +27,7 @@ class LesanaType:      def empty(self):          raise NotImplementedError -    def update(self, value): +    def auto(self, value):          """          Return an updated value, as appropriate for the field. @@ -133,7 +133,7 @@ class LesanaInt(LesanaType):          """          return xapian.sortable_serialise(value) -    def update(self, value): +    def auto(self, value):          """          Return an updated value. @@ -250,7 +250,7 @@ class LesanaDatetime(LesanaType):          return None -    def update(self, value): +    def auto(self, value):          """          Return an updated value. @@ -290,7 +290,7 @@ class LesanaDate(LesanaType):          return None -    def update(self, value): +    def auto(self, value):          """          Return an updated value. diff --git a/tests/test_collection.py b/tests/test_collection.py index 84c535d..c792f29 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -122,7 +122,7 @@ class testEntries(unittest.TestCase):          eid = '11189ee47ddf4796b718a483b379f976'          entry = self.collection.entry_from_eid(eid)          old_data = entry.data.copy() -        entry.update() +        entry.auto()          self.assertEqual(old_data, entry.data) @@ -429,7 +429,7 @@ class testComplexCollection(unittest.TestCase):          self.assertEqual(entry.data['updated'], None)          self.assertEqual(entry.data['version'], 0) -        entry.update() +        entry.auto()          # after the update, fields that were not supposed to be updated          # are equal to what they were before, while updated has been diff --git a/tests/test_types.py b/tests/test_types.py index 1efcde1..32340d5 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -42,7 +42,7 @@ class testTypes(unittest.TestCase):          s = checker.load(None)          self.assertEqual(s, None) -        v = checker.update("Hello World!") +        v = checker.auto("Hello World!")          self.assertEqual(v, "Hello World!")      def test_text(self): @@ -57,7 +57,7 @@ class testTypes(unittest.TestCase):          s = checker.load(None)          self.assertEqual(s, None) -        v = checker.update("Hello World!") +        v = checker.auto("Hello World!")          self.assertEqual(v, "Hello World!")      def test_int(self): @@ -79,7 +79,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(10) +        v = checker.auto(10)          self.assertEqual(v, 10)      def test_datetime_auto_increment(self): @@ -90,25 +90,25 @@ class testTypes(unittest.TestCase):          v = checker.empty()          self.assertEqual(v, 0) -        v = checker.update(0) +        v = checker.auto(0)          self.assertEqual(v, 1)          field_def['increment'] = -1          checker = types.LesanaInt(field_def, {}) -        v = checker.update(0) +        v = checker.auto(0)          self.assertEqual(v, -1)          field_def['increment'] = 0.5          checker = types.LesanaInt(field_def, {})          with self.assertLogs() as cm: -            v = checker.update(0) +            v = checker.auto(0)          self.assertIn('WARNING', cm.output[0])          self.assertIn('Invalid configuration value', cm.output[0])          self.assertEqual(v, 0)          field_def['auto'] = 'false'          checker = types.LesanaInt(field_def, {}) -        v = checker.update(0) +        v = checker.auto(0)          self.assertEqual(v, 0)      def test_float(self): @@ -133,7 +133,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(10.5) +        v = checker.auto(10.5)          self.assertEqual(v, 10.5)      def test_decimal(self): @@ -158,7 +158,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(decimal.Decimal("10.5")) +        v = checker.auto(decimal.Decimal("10.5"))          self.assertEqual(v, decimal.Decimal("10.5"))      def test_timestamp(self): @@ -191,7 +191,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(today) +        v = checker.auto(today)          self.assertEqual(v, today)      def test_datetime(self): @@ -223,7 +223,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(now) +        v = checker.auto(now)          self.assertEqual(v, now)      def test_datetime_auto(self): @@ -259,7 +259,7 @@ class testTypes(unittest.TestCase):          now = datetime.datetime.now()          past = datetime.datetime(2016, 12, 10, 21, 2)          # we pass a date in the past -        v = checker.update(past) +        v = checker.auto(past)          self.assertIsInstance(v, datetime.datetime)          self.assertEqual(v.tzinfo, datetime.timezone.utc)          # and we want to get a date in the present @@ -269,14 +269,14 @@ class testTypes(unittest.TestCase):          field_def['auto'] = False          checker = types.LesanaDatetime(field_def, {}) -        v = checker.update(past) +        v = checker.auto(past)          self.assertEqual(v, past)          # and the same should happen with auto=creation          field_def['auto'] = 'creation'          checker = types.LesanaDatetime(field_def, {}) -        v = checker.update(past) +        v = checker.auto(past)          self.assertEqual(v, past)      def test_date(self): @@ -308,7 +308,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(today) +        v = checker.auto(today)          self.assertEqual(v, today)      def test_date_auto(self): @@ -343,7 +343,7 @@ class testTypes(unittest.TestCase):          today = datetime.date.today()          past = datetime.date(2016, 12, 10)          # we pass a date in the past -        v = checker.update(past) +        v = checker.auto(past)          self.assertIsInstance(v, datetime.date)          # and we want to get a date in the present          self.assertEqual(v, today) @@ -352,14 +352,14 @@ class testTypes(unittest.TestCase):          field_def['auto'] = False          checker = types.LesanaDate(field_def, {}) -        v = checker.update(past) +        v = checker.auto(past)          self.assertEqual(v, past)          # and the same should happen with auto=creation          field_def['auto'] = 'creation'          checker = types.LesanaDate(field_def, {}) -        v = checker.update(past) +        v = checker.auto(past)          self.assertEqual(v, past)      def test_boolean(self): @@ -378,7 +378,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(True) +        v = checker.auto(True)          self.assertEqual(v, True)      def test_file(self): @@ -395,7 +395,7 @@ class testTypes(unittest.TestCase):          # TODO: check for invalid file paths -        v = checker.update("relative/path/to/file") +        v = checker.auto("relative/path/to/file")          self.assertEqual(v, "relative/path/to/file")      def test_url(self): @@ -412,7 +412,7 @@ class testTypes(unittest.TestCase):          # TODO: check for invalid URLs -        v = checker.update("http://example.org") +        v = checker.auto("http://example.org")          self.assertEqual(v, "http://example.org")      def test_yaml(self): @@ -431,7 +431,7 @@ class testTypes(unittest.TestCase):          v = checker.load(None)          self.assertEqual(v, None) -        v = checker.update(some_data) +        v = checker.auto(some_data)          self.assertEqual(v, some_data)      def test_list(self): @@ -454,7 +454,7 @@ class testTypes(unittest.TestCase):              with self.assertRaises(types.LesanaValueError):                  checker.load(d) -        v = checker.update(some_data) +        v = checker.auto(some_data)          self.assertEqual(v, some_data)      def test_list_unknown_subtype(self): | 
