In [1]:
from agora import Forum
from agora.models import Base

In [2]:
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

In [3]:
# set up in-memory sqlite database for persistence
engine = create_engine('sqlite:///:memory:')
# create the database tables defined in agora.models
Base.metadata.create_all(engine)

In [4]:
# create an sqlalchemy scoped session
# and bind it to the engine
# (scoped sessions manage transactions internally)
DBSession = scoped_session(sessionmaker())
DBSession.configure(bind=engine)

In [ ]:


In [5]:
# instantiate the forum
forum = Forum(DBSession)

In [6]:
forum.get_ideas()


Out[6]:
[]

In [ ]:


In [7]:
forum.add_author(username='schmoe', fullname='Joe Schmoe', email='schmoe@example.com')


Out[7]:
1

In [8]:
forum.add_author(username='misinformation', fullname='Miss Information', email='misinformation@example.com')


Out[8]:
2

In [9]:
forum.get_authors()


Out[9]:
[Joe Schmoe, March 03, 2016, Miss Information, March 03, 2016]

In [10]:
forum.get_author(1)


Out[10]:
Joe Schmoe, March 03, 2016

In [ ]:


In [11]:
forum.add_idea(title='First Idea!', idea='This is my idea.', author_id=1)


Out[11]:
1

In [12]:
forum.add_idea(title='My First Idea!', idea='This is my idea.', author_id=2)


Out[12]:
2

In [13]:
forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=1)


Out[13]:
3

In [14]:
forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=2)


Out[14]:
4

In [15]:
forum.get_ideas()


Out[15]:
[First Idea!, Joe Schmoe, March 03, 2016,
 My First Idea!, Miss Information, March 03, 2016,
 Another Idea!, Joe Schmoe, March 03, 2016,
 Another Idea!, Miss Information, March 03, 2016]

In [16]:
forum.get_idea(1)


Out[16]:
First Idea!, Joe Schmoe, March 03, 2016

In [ ]:


In [ ]:
forum.get_ideas(filters={'author': forum.get_author(1)})

In [ ]:
forum.get_ideas(filters={'title': 'First Idea!'})

In [ ]:
forum.get_ideas(filters={'title': 'Another Idea!'})

In [ ]:
forum.get_ideas(filters={'author': forum.get_author(2), 'title': 'Another Idea!'})

In [ ]:


In [ ]:
forum.get_ideas()

In [ ]:
forum.delete_idea(1)

In [ ]:
forum.get_ideas()

In [ ]: