small additions

This commit is contained in:
chris t 2018-07-18 22:42:11 -07:00
parent c053fa7074
commit d6ffe96b30
3 changed files with 19 additions and 4 deletions

View File

@ -67,7 +67,7 @@ about in the database by hand, and I wanted a structure that was easy
to perceive and modify. to perceive and modify.
I explicitly did not aim for efficiency. The underlying code is 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? Why is it called that?

View File

@ -75,6 +75,10 @@ class Tag(Base):
def __repr__(self): def __repr__(self):
return "kk_tag %s: %s" % (self.db_id, self.text) 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): def _get_class_by_tablename(self, tablename):
"""Return class reference mapped to table. """Return class reference mapped to table.
@ -164,6 +168,7 @@ class Taggable(Base):
def delete_before_insert(mapper, conn, target): 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'" % r = conn.execute("SELECT db_id FROM kk_tags WHERE text='%s'" %
target.text) target.text)
if r: if r:

View File

@ -11,13 +11,15 @@ import unittest
import libkosokoso as kk import libkosokoso as kk
class Foo(kk.Taggable): class DummyBase = sa.ext.declarative.declarative_base()
class Foo(DummyBase, kk.Taggable):
__tablename__ = 'foos' __tablename__ = 'foos'
db_id = sa.Column(sa.Integer, primary_key=True) db_id = sa.Column(sa.Integer, primary_key=True)
def __repr__(self): def __repr__(self):
return "foo: id %s" % self.db_id return "foo: id %s" % self.db_id
class Bar(kk.Taggable): class Bar(DummyBase, kk.Taggable):
__tablename__ = 'bars' __tablename__ = 'bars'
db_id = sa.Column(sa.Integer, primary_key=True) db_id = sa.Column(sa.Integer, primary_key=True)
def __repr__(self): def __repr__(self):
@ -289,7 +291,15 @@ class ks_basic(unittest.TestCase):
# print(pd.read_sql_query("SELECT * FROM kk_tags", # print(pd.read_sql_query("SELECT * FROM kk_tags",
# self.engine)) # 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 # TODO test concurrent setting the same tag from different
# processes. # processes.