def test_daily_to_rss_feed(self):
        daily = Daily(url='an url')

        daily_entry = DailyEntry(date='2015-12-28', type='reading', subject='a book about bonsai')
        daily.add_entry(daily_entry)

        daily_entry = DailyEntry(date='2015-12-30', type='studying', subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily_entry.add_reference(source='http://somewhere/blog.html', type='blog')
        daily.add_entry(daily_entry)

        expected_rss = '''<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Daily Activity Log: an url</title>
    <link>an url</link>
    <description>RSS feed generated from: an url</description>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>python-feedgen</generator>
    <language>en</language>
    <item>
      <title>studying: a book about trees</title>
      <description>&lt;a href=\'http://somewhere\'&gt;source&lt;/a&gt;&lt;br/&gt;&lt;a href=\'http://somewhere/blog.html\'&gt;blog&lt;/a&gt;&lt;br/&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:00:00 +0000</pubDate>
    </item>
    <item>
      <title>reading: a book about bonsai</title>
      <pubDate>Mon, 28 Dec 2015 00:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>
'''

        rss = daily_to_rss(daily)

        self.assertEqual(expected_rss, exclude_tag('lastBuildDate', rss))
 def __daily_entry_from(self, event):
     action = event.find('action')
     entry = DailyEntry(date=event.attrib['date'], type=action.attrib['type'], subject=action.text)
     references = event.find('references')
     if references is not None:
         for reference in references:
             entry.add_reference(source=reference.attrib['src'], type=reference.attrib['type'])
     return entry
示例#3
0
 def __daily_entry_from(self, event):
     action = event.find('action')
     entry = DailyEntry(date=event.attrib['date'],
                        type=action.attrib['type'],
                        subject=action.text)
     references = event.find('references')
     if references is not None:
         for reference in references:
             entry.add_reference(source=reference.attrib['src'],
                                 type=reference.attrib['type'])
     return entry
    def test_when_daily_is_found_returns_rss(self):
        daily = Daily(url='an url')
        daily_entry = DailyEntry(date='2015-12-30', type='reading', subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily.add_entry(daily_entry)

        when(self.repository).find_by('an url').thenReturn(daily)

        status, message = self.action.execute('an url')

        self.assertEqual('ok', status)
        self.assertTrue(message.startswith("<rss "))
def save_to_db(user_id, current_question, ds, body):
    if current_question == 'mood_score':
        try:
            body = int(body)
            assert body <= 5
            assert body >= 1
        except (ValueError, AssertionError):
            return MOOD_SCORE_FAILURE_MESSAGE
        # write to db
        entry = DailyEntry(user_id, ds, body)
        db.session.add(entry)
        db.session.commit()
    elif current_question == 'mood_reason':
        entry = DailyEntry.get_by_userid_and_ds(user_id, ds)
        entry.mood_reason = body
        db.session.add(entry)
        db.session.commit()
    elif current_question == 'daily_updates':
        updates = parse_updates_and_tags(body)
        # get entryid
        entry = DailyEntry.get_by_userid_and_ds(user_id, ds)
        entry_id = entry.id
        # save all updates
        for update in updates:
            update_obj = DailyUpdate(user_id, entry_id, ds, update['update'])
            db.session.add(update_obj)
            # auto populate next ID into update_obj
            db.session.flush()
            for tag in update['tags']:
                tag_obj = DailyTag(user_id, entry_id, update_obj.id, ds, tag)
                db.session.add(tag_obj)
        db.session.commit()
    elif current_question == 'weekly_updates':
        updates = parse_updates_and_tags(body)
        for update in updates:
            update_obj = WeeklyUpdate(user_id, ds, update['update'])
            db.session.add(update_obj)
            # auto populate next ID into update_obj
            db.session.flush()
            for tag in update['tags']:
                tag_obj = WeeklyTag(user_id, update_obj.id, ds, tag)
                db.session.add(tag_obj)
        db.session.commit()
    return None
    def test_daily_to_rss_feed(self):
        daily = Daily(url='an url')

        daily_entry = DailyEntry(date='2015-12-28',
                                 type='reading',
                                 subject='a book about bonsai')
        daily.add_entry(daily_entry)

        daily_entry = DailyEntry(date='2015-12-30',
                                 type='studying',
                                 subject='a book about trees')
        daily_entry.add_reference(source='http://somewhere', type='source')
        daily_entry.add_reference(source='http://somewhere/blog.html',
                                  type='blog')
        daily.add_entry(daily_entry)

        expected_rss = '''<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Daily Activity Log: an url</title>
    <link>an url</link>
    <description>RSS feed generated from: an url</description>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>python-feedgen</generator>
    <language>en</language>
    <item>
      <title>studying: a book about trees</title>
      <description>&lt;a href=\'http://somewhere\'&gt;source&lt;/a&gt;&lt;br/&gt;&lt;a href=\'http://somewhere/blog.html\'&gt;blog&lt;/a&gt;&lt;br/&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:00:00 +0000</pubDate>
    </item>
    <item>
      <title>reading: a book about bonsai</title>
      <pubDate>Mon, 28 Dec 2015 00:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>
'''

        rss = daily_to_rss(daily)

        self.assertEqual(expected_rss, exclude_tag('lastBuildDate', rss))
 def full_daily(self):
     daily = Daily(url=AN_URL)
     first_entry = DailyEntry("2015-06-23", "trying", "My daily activity log")
     first_entry.add_reference("http://somewhere.internet/page.html", "source")
     second_entry = DailyEntry("2015-06-20", "reading", "A new book")
     second_entry.add_reference("http://somewhere.internet/page2.html", "source")
     second_entry.add_reference("http://somewhere.internet/page2.html", "other source")
     third_entry = DailyEntry("2015-06-18", "watching", "A movie")
     daily.add_entry(first_entry)
     daily.add_entry(second_entry)
     daily.add_entry(third_entry)
     return daily