|
@@ -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
|
|