Пример #1
0
    def testStop(self):

        '''
        A GET request should stop the slicer for a haiku.
        '''

        # Create an admin and haiku.
        admin = User.createAdministrator('username', 'password')
        haiku = Haiku.createHaiku(admin.id, 'test', 1000, 1, 5, 100, 30, 1000)

        # Start the slicer
        sched.createSlicer(haiku, slicer.slice)

        with self.app as c:

            # Re-get the haiku.
            haiku = Haiku.getHaikuBySlug('test')

            # Push in a user id.
            with c.session_transaction() as s:
                s['user_id'] = admin.id

            # Hit the route, check for redirect back to browse.
            rv = c.get('/admin/stop/' + str(haiku.id), follow_redirects=True)
            self.assertTemplateUsed('admin/browse.html')

            # Check that the slicer is not present.
            job = sched.getJobByHaiku(haiku)
            self.assertFalse(job)
Пример #2
0
    def testGetHaikuBySlug(self):

        '''
        getHaikuBySlug() should get a record by the url slug.
        '''

        # Create records.
        user = User.createAdministrator('username', 'password')
        haiku = Haiku.createHaiku(user.id, 'test', 1000, 1, 5, 100, 30, 1000)

        # Fetch and check.
        retrievedHaiku = Haiku.getHaikuBySlug('test')
        self.assertEquals(haiku.id, retrievedHaiku.id)
Пример #3
0
    def testDelete(self):

        '''
        A GET request should delete the haiku.
        '''

        # Create an admin and haiku.
        admin = User.createAdministrator('username', 'password')

        # Create 2 haiku.
        haiku1 = Haiku.createHaiku(admin.id, 'test1', 1000, 1, 5, 100, 30, 1000)
        haiku2 = Haiku.createHaiku(admin.id, 'test2', 1000, 1, 5, 100, 30, 1000)

        with self.app as c:

            # Re-get the haiku.
            haiku1 = Haiku.getHaikuBySlug('test1')
            haiku2 = Haiku.getHaikuBySlug('test2')

            # Push in a user id.
            with c.session_transaction() as s:
                s['user_id'] = admin.id

            # At the start, 2 records.
            self.assertEquals(Haiku.query.count(), 2)

            # Hit the route.
            rv = c.get('/admin/delete/' + str(haiku1.id), follow_redirects=True)
            self.assertTemplateUsed('admin/browse.html')

            # 1 record.
            self.assertEquals(Haiku.query.count(), 1)

            # Check that the right record was deleted.
            haiku = Haiku.query.first()
            self.assertEquals(haiku.id, haiku2.id)