Skip to content

Commit

Permalink
Add delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ejesse committed Jul 24, 2015
1 parent 5693fad commit 9a51218
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 5 additions & 2 deletions models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def rid(self):

@classmethod
def get(cls, rid, client=None):
return Model.from_orient(load(rid, client=client))
resp = load(rid, client=client)
if resp.oRecordData == {}:
return None
return Model.from_orient(resp)

def _set_rid(self, rid):
# temporarily remove the '#' if it is there
Expand Down Expand Up @@ -140,4 +143,4 @@ def save(self, client=None):
if self.rid is None:
insert(self, client=client)
else:
update(self, client=client)
update(self, client=client)
6 changes: 5 additions & 1 deletion models/orient_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ def update(obj, client=None):


def delete(rid, client=None):
pass

if client is None:
client = get_connection()

return client.record_delete(rid)
16 changes: 14 additions & 2 deletions tests/orient_sql_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from models.fields import IntegerField, FloatField, StringField, \
DateTimeField, BinaryField, to_java_case
from models.model_utils import get_orient_valid_class_name
from models.orient_sql import create_class, insert, load, update
from models.orient_sql import create_class, insert, load, update, delete
from tests import OgormTest
from utils import get_logger_for_name

Expand Down Expand Up @@ -59,6 +59,10 @@ class Foo(Model):
pass


class ClassToDelete(Model):

str_field = StringField()

class TestModels(OgormTest):


Expand Down Expand Up @@ -210,4 +214,12 @@ def test_record_update(self):
class_to_update.datetime_field.timestamp)
self.assertFalse(class_to_update._py_to_orient_field_mapping['float_field'] in r.oRecordData)


def test_delete_record(self):

create_class(ClassToDelete, client=self.client)
ctd = ClassToDelete()
ctd.str_field = 'jfksfjdsl'
ctd.save(client=self.client)
self.assertTrue(delete(ctd.rid, client=self.client))
self.assertIsNone(ClassToDelete.get(ctd.rid, client=self.client))

0 comments on commit 9a51218

Please sign in to comment.