Browse Source

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

prieto 8 years ago
parent
commit
955e327215
5 changed files with 56 additions and 9 deletions
  1. 5
    1
      em_test.py
  2. BIN
      examples/em_test.pickle
  3. 1
    1
      lodel/leapi/leobject.py
  4. BIN
      tests/editorial_model.pickle
  5. 50
    7
      tests/leapi/test_leobject.py

+ 5
- 1
em_test.py View File

@@ -106,6 +106,8 @@ person.new_field(   'alias',
106 106
                     },
107 107
                     data_handler = 'set',
108 108
                     allowed_classes = [person],
109
+                    default = None,
110
+                    nullable = True,
109 111
 )
110 112
 
111 113
 
@@ -272,7 +274,9 @@ person.new_field(   'linked_texts',
272 274
                     data_handler = 'list',
273 275
                     back_reference = ('Text', 'linked_persons'),
274 276
                     group = editorial_person_group,
275
-                    allowed_classes = [text])
277
+                    allowed_classes = [text],
278
+                    default = None,
279
+                    nullable = True)
276 280
 
277 281
 text.new_field( 'linked_persons',
278 282
                 display_name = {

BIN
examples/em_test.pickle View File


+ 1
- 1
lodel/leapi/leobject.py View File

@@ -145,7 +145,7 @@ class LeObject(object):
145 145
         try:
146 146
             return getattr(mod, leobject_name)
147 147
         except AttributeError:
148
-            raise NameError("No LeObject named '%s'" % leobject_name)
148
+            raise LeApiError("No LeObject named '%s'" % leobject_name)
149 149
     
150 150
     @classmethod
151 151
     def is_abstract(cls):

BIN
tests/editorial_model.pickle View File


+ 50
- 7
tests/leapi/test_leobject.py View File

@@ -3,13 +3,12 @@ import unittest
3 3
 import tests.loader_utils
4 4
 from tests.leapi.query.utils import dyncode_module as dyncode
5 5
 
6
-from lodel.leapi.leobject import LeApiDataCheckError
6
+from lodel.leapi.leobject import LeObject
7 7
 from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
8 8
 from lodel.leapi.exceptions import *
9 9
 
10
-class LeFilteredQueryTestCase(unittest.TestCase):
11
-
12
-    q_classes = [ LeDeleteQuery, LeUpdateQuery, LeGetQuery ]
10
+class LeObjectDummyTestCase(unittest.TestCase):
11
+    """ Testing LeObject method with a dummy datasource """
13 12
 
14 13
     def test_init(self):
15 14
         """ Testing LeObject child class __init__ """
@@ -36,7 +35,40 @@ class LeFilteredQueryTestCase(unittest.TestCase):
36 35
         with self.assertRaises(LeApiError):
37 36
             dyncode.Person(lastname = "foo", firstname = "bar")
38 37
 
38
+    def test_data_accessor(self):
39
+        """ Testing data accessor method """
40
+        inst = dyncode.Person(lodel_id = 1, lastname = "foo")
41
+        self.assertEqual(inst.data('lodel_id'), 1)
42
+        self.assertEqual(inst.data('lastname'), 'foo')
43
+
44
+    def test_data_accessor_fails(self):
45
+        """ Testing that data accessor detects unitialized fields """
46
+        inst = dyncode.Person(lodel_id = 1, lastname = "foo")
47
+        with self.assertRaises(RuntimeError):
48
+            inst.data('firstname')
49
+
50
+    def test_name2class(self):
51
+        """ Testing the class method that returns a dynamic object given it's
52
+            name """
53
+        self.assertEqual(dyncode.Object.name2class('Person'), dyncode.Person)
54
+        self.assertEqual(dyncode.Object.name2class('Object'), dyncode.Object)
39 55
     
56
+    def test_bad_name2class(self):
57
+        """ Testing failures of the class method that returns a dynamic object
58
+            given it's name """
59
+        badnames = ['foobar', 'LeObject', 'str', str, None, 42]
60
+        callers = [dyncode.Object, dyncode.Person, dyncode.Entitie]
61
+        for caller in callers:
62
+            for badname in badnames:
63
+                with self.assertRaises(LeApiError):
64
+                    caller.name2class(badname)
65
+
66
+    def test_abstract_name2class(self):
67
+        with self.assertRaises(NotImplementedError):
68
+            LeObject.name2class('Person')
69
+        with self.assertRaises(NotImplementedError):
70
+            LeObject.name2class(42)
71
+
40 72
     def test_initilized(self):
41 73
         """ Testing initialized method """
42 74
         inst = dyncode.Person(
@@ -53,11 +85,22 @@ class LeFilteredQueryTestCase(unittest.TestCase):
53 85
             {'lastname', 'linked_texts', 'firstname', 'alias'})
54 86
 
55 87
     def test_insert(self):
88
+        """ Testing insert method """
56 89
         dyncode.Person.insert({'lastname': 'foo', 'firstname': 'bar'})
57 90
     
58
-    @unittest.skip("wait")
59 91
     def test_bad_insert(self):
60 92
         """ Insert with bad arguments """
61
-        dyncode.Person.insert({})
62
-        dyncode.Person.insert({'lodel_id': 1,'lastname': 'foo', 'firstname': 'bar'})
93
+        badargs = [
94
+            {},
95
+            {'lodel_id': 1,'lastname': 'foo', 'firstname': 'bar'}]
96
+        
97
+        for arg in badargs:
98
+            with self.assertRaises(LeApiDataCheckErrors):
99
+                dyncode.Person.insert(arg)
100
+
101
+    def test_delete_instance(self):
102
+        """ Testing instance method delete """
103
+        inst = dyncode.Person(
104
+            lodel_id = 1, firstname = "foo", lastname = "bar")
105
+        inst.delete()
63 106
 

Loading…
Cancel
Save