Let's explore and test quills.core.interfaces...

(N.B. These tests are written assuming that the implementation being tested
provides IWorkflowedWeblogEntry.)

The test-case class should have made self.weblog available to us.  We'll check
that (and save a few keystrokes in this file) and make sure it implements the
correct interface.

  >>> weblog = self.weblog
  >>> from quills.core.interfaces import IWeblog
  >>> IWeblog.providedBy(weblog)
  True

There shouldn't be any published entries in this weblog yet.

  >>> len(weblog.getEntries())
  0

There aren't any drafts either.

  >>> len(weblog.getDrafts())
  0

Now we'll add a weblog entry.

  >>> entry1 = weblog.addEntry(title='The First Title',
  ...                          excerpt='A little excerpting',
  ...                          text='foo bar baz',
  ...                          topics=['aTopic', 'bTopic'])

Of course, the new entry should implement the required interface.

  >>> from quills.core.interfaces import IWorkflowedWeblogEntry
  >>> IWorkflowedWeblogEntry.providedBy(entry1)
  True

The weblog now has a draft entry, but no published entries.

  >>> len(weblog.getDrafts())
  1
  >>> len(weblog.getEntries())
  0

We can check its workflow state and manipulate it.

  >>> entry1.isPublished()
  False
  >>> entry1.publish()

Publishing the entry should make it show up in the weblog.

  >>> len(weblog.getDrafts())
  0
  >>> len(weblog.getEntries())
  1

It's ok to publish something that's already published - it'll have no effect.

  >>> entry1.isPublished()
  True
  >>> entry1.publish()
  >>> entry1.isPublished()
  True

We can retract as well.

  >>> entry1.retract()
  >>> len(weblog.getDrafts())
  1
  >>> len(weblog.getEntries())
  0

It's ok to retract something twice as well.

  >>> entry1.isPublished()
  False
  >>> entry1.retract()
  >>> entry1.isPublished()
  False

When we created the entry, we gave it a title, an excerpt, some text, and some
topics.

  >>> entry1.getTitle()
  'The First Title'
  >>> entry1.getExcerpt()
  'A little excerpting'
  >>> entry1.getText()
  'foo bar baz'
  >>> entry1_topics = entry1.getTopics()
  >>> from quills.core.interfaces import ITopic
  >>> for topic in entry1_topics:
  ...   ITopic.providedBy(topic)
  True
  True

ITopic makes no requirement as to the order in which topics are returned.

  >>> entry1_topics = [topic.getId() for topic in entry1_topics]
  >>> entry1_topics.sort()
  >>> entry1_topics
  ['aTopic', 'bTopic']

The weblog should also be aware of these topics.

  >>> weblog_topics = weblog.getTopics()
  >>> for topic in weblog_topics:
  ...   ITopic.providedBy(topic)
  True
  True
  >>> weblog_topics = [topic.getId() for topic in weblog_topics]
  >>> weblog_topics.sort()
  >>> weblog_topics == entry1_topics
  True

We can get a topic by id from the weblog, and that topic will know about the
entries associated with it, but only when they are published.

  >>> aTopic = weblog.getTopicById('aTopic')
  >>> len(aTopic.getEntries())
  0
  >>> entry1.publish()
  >>> aTopic_entries = aTopic.getEntries()
  >>> len(aTopic_entries)
  1
  >>> aTopic_entries[0].getTitle() == entry1.getTitle()
  True
  >>> entry1.retract()

We get an empty topic if we ask for one that doesn't really 'exist' yet.

  >>> non_existant = weblog.getTopicById('wowowowow')
  >>> ITopic.providedBy(non_existant)
  True
  >>> len(non_existant.getEntries())
  0

There are also author topics, that act like topics for individual authors.

  >>> auth_topics = weblog.getAuthors()

After we've published our entry, there will only be one author topic.

  >>> len(auth_topics)
  0
  >>> entry1.publish()
  >>> auth_topics = weblog.getAuthors()
  >>> len(auth_topics)
  1

We can look-up entries on author topics just like we can with normal topics.

  >>> auth_topic = auth_topics[0]
  >>> len(auth_topic)
  1
  >>> auth_topic.getEntries()[0].getTitle() == entry1.getTitle()
  True
  >>> entry1.retract()

IWeblogEntry objects can also tell us about their authors.

  >>> authors = entry1.getAuthors()
  >>> len(authors)
  1
  >>> from quills.core.interfaces import IAuthorTopic
  >>> IAuthorTopic.providedBy(authors[0])
  True

The weblog has an archive feature.

  >>> archives = weblog.getSubArchives()

As the weblog entry isn't published, it won't show up in the archives.

  >>> len(archives)
  0

So we'll publish it and then check again.

  >>> entry1.publish()
  >>> archives = weblog.getSubArchives()
  >>> len(archives)
  1
  >>> year_archive = archives[0]
  >>> from quills.core.interfaces import IWeblogArchive
  >>> IWeblogArchive.providedBy(year_archive)
  True
  >>> archive_entries = year_archive.getEntries()
  >>> len(archive_entries)
  1
  >>> archive_entries[0].getTitle() == entry1.getTitle()
  True

The archive is deeper than just the year archive.  There are also 'month' and
'day' archives, too, and they should have access to the weblog entry as well.

  >>> month_archives = year_archive.getSubArchives()
  >>> len(month_archives)
  1
  >>> month_archive = month_archives[0]
  >>> len(month_archive)
  1
  >>> month_archive.getEntries()[0].getTitle() == entry1.getTitle()
  True

  >>> day_subarchives = month_archive.getSubArchives()
  >>> len(day_subarchives)
  1
  >>> day_archive = day_subarchives[0]
  >>> len(day_archive)
  1
  >>> day_archive.getEntries()[0].getTitle() == entry1.getTitle()
  True
