Browse Source

[#87] Added the delete method to LeRelation

Roland Haroutiounian 9 years ago
parent
commit
d5169cf9a1
2 changed files with 12 additions and 3 deletions
  1. 9
    0
      leapi/lerelation.py
  2. 3
    3
      leapi/test/test_lerelation.py

+ 9
- 0
leapi/lerelation.py View File

@@ -79,6 +79,15 @@ class _LeRelation(lecrud._LeCrud):
79 79
 
80 80
         return (res, rel)
81 81
 
82
+    @classmethod
83
+    ## @brief deletes a relation between two objects
84
+    # @param filters_list list
85
+    # @param target_class str
86
+    def delete(cls, filters_list, target_class):
87
+        filters, rel_filters = cls._prepare_filters(filters_list)
88
+        ret = cls._datasource.delete(target_class, filters)
89
+        return True if ret == 1 else False
90
+
82 91
 ## @brief Abstract class to handle hierarchy relations
83 92
 class _LeHierarch(_LeRelation):
84 93
     def __init__(self, rel_id):

+ 3
- 3
leapi/test/test_lerelation.py View File

@@ -67,14 +67,14 @@ class LeRelationTestCase(TestCase):
67 67
             for i in range(3):
68 68
                 self.assertEqual(filter_res[i], res[i], "%s != %s"%(filter_res, res))
69 69
 
70
-    @unittest.skip("Wait LeRelation._prepare_filters() and LeRelation.delete() to unskip")
70
+    # @unittest.skip("Wait LeRelation._prepare_filters() and LeRelation.delete() to unskip")
71 71
     @patch('DataSource.dummy.leapidatasource.DummyDatasource.delete')
72 72
     def test_delete(self, dsmock):
73 73
         """ Testing LeHierarch insert method """
74 74
         from dyncode import LeCrud, Publication, Numero, Personnes, LeObject, Rubrique, LeHierarch, LeRelation
75 75
         
76
-        LeRelation.delete([LeRelation.sup_filter(Numero(42)), 'nature = "parent"'], 'LeHierarch')
77
-        dsmock.assert_called_once_with(LeHierarch, [('lesup', '=', Numero(42)), ('nature','=','parent')])
76
+        LeRelation.delete([LeRelation.sup_filter(Numero(42)), 'nature = "parent"'], LeHierarch)
77
+        dsmock.assert_called_once_with(LeHierarch, [('lesup', '=', Numero(42)), ('nature','=','"parent"')])
78 78
         dsmock.reset_mock()
79 79
 
80 80
 

Loading…
Cancel
Save