aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-02 17:50:58 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-02 17:50:58 +0100
commit3945aab1bc696a0a410d95ab65fddec70e9ee2f1 (patch)
treefa54a30f980523fed61edc9045bd2ee0669a0691
parent9a7168c0262da9a2b4a6338a5179ce644a84fb15 (diff)
When creating a new empty entry, write the fields in order
-rw-r--r--lesana/collection.py14
-rw-r--r--tests/data/complex/settings.yaml16
-rw-r--r--tests/data/simple/settings.yaml2
-rw-r--r--tests/test_collection.py5
4 files changed, 29 insertions, 8 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index cf6c505..6e32929 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -28,16 +28,18 @@ class Entry(object):
self.fname = self.uid + '.yaml'
def empty_data(self):
- data = {}
+ data = ''
for field in self.collection.settings['fields']:
t = field['type']
- if t in ['string', 'text']:
- data[field['name']] = ''
+ if t == 'string':
+ data += ("{name}: ''\n".format(**field))
+ elif t == 'text':
+ data += ("{name}: |\n\n".format(**field))
elif t == 'integer':
- data[field['name']] = 0
+ data += ("{name}: 0\n".format(**field))
else:
- data[field['name']] = None
- return data
+ data += ("{name}: \n".format(**field))
+ return ruamel.yaml.load(data, Loader=ruamel.yaml.RoundTripLoader)
@property
def yaml_data(self):
diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml
new file mode 100644
index 0000000..57a1773
--- /dev/null
+++ b/tests/data/complex/settings.yaml
@@ -0,0 +1,16 @@
+name: "Fully featured lesana collection"
+lang: 'english'
+fields:
+ - name: name
+ type: string
+ prefix: S
+ index: free
+ - name: description
+ type: text
+ prefix: XD
+ index: free
+ - name: position
+ type: string
+ index: facet
+ - name: something
+ type: yaml
diff --git a/tests/data/simple/settings.yaml b/tests/data/simple/settings.yaml
index 36c4e3e..fc405a1 100644
--- a/tests/data/simple/settings.yaml
+++ b/tests/data/simple/settings.yaml
@@ -13,3 +13,5 @@ fields:
- name: quantity
type: integer
index: no
+ - name: other
+ type: yaml
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 45c1efc..e732f9c 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -27,7 +27,7 @@ class testCollectionLoading(unittest.TestCase):
self.collection.settings['name'],
"Simple lesana collection"
)
- self.assertEqual(len(self.collection.settings['fields']), 4)
+ self.assertEqual(len(self.collection.settings['fields']), 5)
self.assertEqual(len(self.collection.indexed_fields), 2)
self.collection.update_cache()
@@ -125,13 +125,14 @@ class testComplexCollection(unittest.TestCase):
self.collection.settings['name'],
"Fully featured lesana collection"
)
- self.assertEqual(len(self.collection.settings['fields']), 3)
+ self.assertEqual(len(self.collection.settings['fields']), 4)
self.assertIsNotNone(self.collection.stemmer)
self.assertEqual(len(self.collection.indexed_fields), 2)
def test_index(self):
self.collection.update_cache()
+
class testCollectionCreation(unittest.TestCase):
def test_init(self):
tmpdir = tempfile.mkdtemp()