def test_details_view(self):
     """Details page displays all the fields Title, Date, Time Spent, What You Learned, Resources to Remember."""
     journal_entry_data = {
         'title':
         'testing new journal entries',
         'date':
         datetime.datetime.now().strftime('%Y-%m-%d'),
         'time_spent':
         '2',
         'what_i_learned':
         'how to test flask views',
         'resources_to_remember':
         'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
     }
     with test_database(TEST_DB, (User, JournalEntry)):
         UserModelTestCase.create_users(1)
         journal_entry_data['user'] = User.select().get()
         JournalEntry.create(**journal_entry_data)
         self.app.post('/login', data=USER_DATA)
         rv = self.app.get('/details/{}'.format(JournalEntry.get().id))
         self.assertIn(journal_entry_data['title'],
                       rv.get_data(as_text=True))
         self.assertIn(journal_entry_data['date'],
                       rv.get_data(as_text=True))
         self.assertIn(journal_entry_data['time_spent'],
                       rv.get_data(as_text=True))
         self.assertIn(journal_entry_data['what_i_learned'],
                       rv.get_data(as_text=True))
         self.assertIn(journal_entry_data['resources_to_remember'],
                       rv.get_data(as_text=True))
 def test_journal_entry_creation(self):
     """Test creating a JournalEntry"""
     with test_database(TEST_DB, (User, JournalEntry)):
         UserModelTestCase.create_users()
         user = User.select().get()
         JournalEntry.create(
             user=user,
             title='Testing Journal Entries',
             date=datetime.datetime.now().strftime('%Y-%m-%d'),
             time_spent='22',
             what_i_learned='Hopefully, I learn if this works or not!',
             resources_to_remember='teamtreehouse.com')
         self.assertEqual(JournalEntry.select().count(), 1)
         self.assertEqual(JournalEntry.user, user)
Exemplo n.º 3
0
def make_entry(user, content):
    entry = JournalEntry.create(content=content,
                                author=user,
                                timestamp=datetime.now())

    if entry == 1:
        print("Entry Saved Successfully!\n")
    def test_list_view(self):
        """The list view contains a list of journal entries, which displays Title and Date for Entry."""
        journal_entry_data_1 = {
            'title':
            'testing 1',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '4',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        journal_entry_data_2 = {
            'title':
            'testing 123',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '8',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        with test_database(TEST_DB, (User, JournalEntry)):
            UserModelTestCase.create_users(1)
            user = User.select().get()
            journal_entry_data_1['user'] = user
            journal_entry_data_2['user'] = user
            JournalEntry.create(**journal_entry_data_1)
            JournalEntry.create(**journal_entry_data_2)

            self.app.post('/login', data=USER_DATA)
            rv = self.app.get('/entries')
            self.assertNotIn('No Entries...', rv.get_data(as_text=True))
            self.assertIn(journal_entry_data_1['title'],
                          rv.get_data(as_text=True))
            self.assertIn(journal_entry_data_1['date'],
                          rv.get_data(as_text=True))
            self.assertIn(journal_entry_data_2['title'],
                          rv.get_data(as_text=True))
            self.assertIn(journal_entry_data_2['date'],
                          rv.get_data(as_text=True))
 def test_details_link_to_edit(self):
     """Details page includes a link to edit the entry"""
     journal_entry_data = {
         'title':
         'testing new journal entries',
         'date':
         datetime.datetime.now().strftime('%Y-%m-%d'),
         'time_spent':
         '2',
         'what_i_learned':
         'how to test flask views',
         'resources_to_remember':
         'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
     }
     with test_database(TEST_DB, (User, JournalEntry)):
         UserModelTestCase.create_users(1)
         journal_entry_data['user'] = User.select().get()
         JournalEntry.create(**journal_entry_data)
         self.app.post('/login', data=USER_DATA)
         rv = self.app.get('/details/{}'.format(JournalEntry.get().id))
         self.assertIn('href="/entry/', rv.get_data(as_text=True))
    def test_more_entries_button(self):
        """If there's more than 5 entries, the home page should display a More Entries button"""
        journal_entry_data = {
            'title':
            'testing more entries',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '4',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        with test_database(TEST_DB, (User, JournalEntry)):
            UserModelTestCase.create_users(1)
            user = User.select().get()
            journal_entry_data['user'] = user
            for _ in range(6):
                JournalEntry.create(**journal_entry_data)

            self.app.post('/login', data=USER_DATA)
            rv = self.app.get('/')
            self.assertIn('More Entries', rv.get_data(as_text=True))
    def test_list_view_hyperlink(self):
        """The list view Title should be hyperlinked to the detail page for each journal entry."""
        journal_entry_data = {
            'title':
            'testing hyperlink',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '4',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        with test_database(TEST_DB, (User, JournalEntry)):
            UserModelTestCase.create_users(1)
            user = User.select().get()
            journal_entry_data['user'] = user
            JournalEntry.create(**journal_entry_data)

            self.app.post('/login', data=USER_DATA)
            hyperlink = 'href="/details/{}"'.format(JournalEntry.get().id)
            rv = self.app.get('/entries')
            self.assertIn(hyperlink, rv.get_data(as_text=True))
    def test_journal_entry_list(self):
        """Test new Journal Entries display on the home page, and the 'no entries' message does not."""
        journal_entry_data = {
            'title':
            'testing new journal entries',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '2',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        with test_database(TEST_DB, (User, JournalEntry)):
            UserModelTestCase.create_users(1)
            journal_entry_data['user'] = User.select().get()
            JournalEntry.create(**journal_entry_data)
            self.app.post('/login', data=USER_DATA)

            rv = self.app.get('/')
            self.assertNotIn('No Entries...', rv.get_data(as_text=True))
            self.assertIn(journal_entry_data['title'],
                          rv.get_data(as_text=True))
Exemplo n.º 9
0
def make_entry(user, content):
    entry = JournalEntry.create(content=content,
                                author=user,
                                timestamp=datetime.now())
    if entry == 1:
        print("entry saved")
Exemplo n.º 10
0
    def test_many_to_many_relationships(self):
        """Make sure JournalEntries and Tags can have many to many relationships"""
        journal_entry_data_1 = {
            'title': 'entry 1',
            'date': datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent': '111',
            'what_i_learned': 'many to many relationships',
            'resources_to_remember': 'docs.peewee-orm.com'
        }
        journal_entry_data_2 = {
            'title': 'entry 2',
            'date': datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent': '222',
            'what_i_learned': 'many to many relationships',
            'resources_to_remember': 'docs.peewee-orm.com'
        }
        with test_database(TEST_DB,
                           (User, JournalEntry, Tag, JournalEntryTag)):
            # create the user
            UserModelTestCase.create_users(1)

            # create the journal entries
            journal_entry_data_1['user'] = User.select().get()
            journal_entry_data_2['user'] = User.select().get()
            JournalEntry.create(**journal_entry_data_1)
            JournalEntry.create(**journal_entry_data_2)
            entry1 = JournalEntry.get(JournalEntry.title == 'entry 1')
            entry2 = JournalEntry.get(JournalEntry.title == 'entry 2')

            # create the tags
            Tag.create_tag(tag='first')
            Tag.create_tag(tag='both')
            Tag.create_tag(tag='second')
            tag1 = Tag.get(Tag.tag == 'first')
            tag2 = Tag.get(Tag.tag == 'both')
            tag3 = Tag.get(Tag.tag == 'second')

            # tie tags to entries
            entry1.tags.add(
                [Tag.get(Tag.tag == 'first'),
                 Tag.get(Tag.tag == 'both')])

            entry2.tags.add(
                [Tag.get(Tag.tag == 'second'),
                 Tag.get(Tag.tag == 'both')])

            # assertions
            self.assertIn(tag1, entry1.tags)
            self.assertIn(tag2, entry1.tags)
            self.assertNotIn(tag3, entry1.tags)

            self.assertNotIn(tag1, entry2.tags)
            self.assertIn(tag2, entry2.tags)
            self.assertIn(tag3, entry2.tags)

            self.assertIn(entry1, tag1.journal_entries)
            self.assertNotIn(entry2, tag1.journal_entries)

            self.assertIn(entry1, tag2.journal_entries)
            self.assertIn(entry2, tag2.journal_entries)

            self.assertNotIn(entry1, tag3.journal_entries)
            self.assertIn(entry2, tag3.journal_entries)