diff --git a/Readme.rst b/Readme.rst index f50ccd6..002bb5e 100644 --- a/Readme.rst +++ b/Readme.rst @@ -67,7 +67,7 @@ about in the database by hand, and I wanted a structure that was easy to perceive and modify. I explicitly did not aim for efficiency. The underlying code is -object-happy and probably extremely inefficient. +object-happy and probably very inefficient. Why is it called that? diff --git a/kosokoso.py b/kosokoso.py index 10a3ecf..74a3901 100644 --- a/kosokoso.py +++ b/kosokoso.py @@ -75,6 +75,10 @@ class Tag(Base): def __repr__(self): return "kk_tag %s: %s" % (self.db_id, self.text) + # i'm not sure this is really what we want. + def __eq__(self, other): + return self.text == other.text + def _get_class_by_tablename(self, tablename): """Return class reference mapped to table. @@ -164,6 +168,7 @@ class Taggable(Base): def delete_before_insert(mapper, conn, target): + # TODO figure out where exactly transactions happen. r = conn.execute("SELECT db_id FROM kk_tags WHERE text='%s'" % target.text) if r: diff --git a/tests/test_basic.py b/tests/test_basic.py index bc85d62..e82dff9 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -11,13 +11,15 @@ import unittest import libkosokoso as kk -class Foo(kk.Taggable): +class DummyBase = sa.ext.declarative.declarative_base() + +class Foo(DummyBase, kk.Taggable): __tablename__ = 'foos' db_id = sa.Column(sa.Integer, primary_key=True) def __repr__(self): return "foo: id %s" % self.db_id -class Bar(kk.Taggable): +class Bar(DummyBase, kk.Taggable): __tablename__ = 'bars' db_id = sa.Column(sa.Integer, primary_key=True) def __repr__(self): @@ -289,7 +291,15 @@ class ks_basic(unittest.TestCase): # print(pd.read_sql_query("SELECT * FROM kk_tags", # self.engine)) - # TODO test access to Tag objects + def test_tag_object_access(self): + a1 = Foo() + for i in ['tag1', 'tag2', 'tag3']: + a1.tags.append(i) + (t1, t2, t3) = [ta.tag_obj for ta in a1.kk_tag_associations] + self.assertEqual(t1, kk.Tag('tag1')) + self.assertEqual(t2, kk.Tag('tag2')) + self.assertEqual(t3, kk.Tag('tag3')) + # TODO test concurrent setting the same tag from different # processes.