Пример #1
0
 def handle(self, *args, **options):
     if len(args) < 1:
         self.stderr.write('Please provide a directory containing the files '+
                           'relative to PROJECT_DIR.')
 
     textbook_dir = os.path.join(settings.PROJECT_DIR, '..', args[0])
     listing = os.listdir( textbook_dir )
     
     # Iterate over all of the filenames.
     for slug in listing:
         try:
             data = ""
             f = open(os.path.join(textbook_dir, slug))
             data = f.read()
             f.close()
             
             # Now try to make a page Model.
             try: page = Page.objects.get(title=slug)
             except: page = Page(title=slug)
             page.content = data
             page.save()
             
             self.stdout.write('Wrote textbook page: %s\n'%slug)
             
         except: self.stderr.write('Skipped textbook page: %s\n'%slug)
     
     self.stdout.write('Successfully compiled textbook pages\n')
Пример #2
0
class TextBookTests(TestCase):
    def setUp(self):
        self.c = Client()
        self.t1 = Page( title="index",
                        content="sup" )
        self.t2 = Page( title="epic",
                        content="""
                        = This is a truly epic tale.
                        == OMG
                        === fur reals
                          
                        It stars **Ishara** //Alexis// and __Allen__.
                         
                        --THE END--
                        """)
        self.t1.save()
        self.t2.save()
       
    # Check the wiki page rendering. 
    def test_can_read_textbook(self):
        response = self.c.get("/textbook/epic/")
        self.assertEqual(response.status_code, 200)

    # When a non-existant page is loaded, a 404 error is returned.
    def test_404(self):
        response = self.c.get("/textbook/fake/")
        self.assertEqual(response.status_code, 404)
    
    # When you don't specify a page, we redirect to the index.
    def test_redirect_index(self):
        response = self.c.get("/textbook/", follow=True)
        self.assertEqual(response.redirect_chain, [(u'http://testserver/textbook/index/', 302)])
Пример #3
0
 def setUp(self):
     self.c = Client()
     self.t1 = Page( title="index",
                     content="sup" )
     self.t2 = Page( title="epic",
                     content="""
                     = This is a truly epic tale.
                     == OMG
                     === fur reals
                       
                     It stars **Ishara** //Alexis// and __Allen__.
                      
                     --THE END--
                     """)
     self.t1.save()
     self.t2.save()
Пример #4
0
    def setUp(self):
        self.c = Client()
        self.t1 = Page( title="index",
                        content="sup" )
        self.t2 = Page( title="epic",
                        content="""
                        = This is a truly epic tale.
                        == OMG
                        === fur reals
                          
                        It stars **Ishara** //Alexis// and __Allen__.
                         
                        --THE END--
                        """)
        self.t1.save()
        self.t2.save()

        # Let's create a world with three stages.
        self.W = World( name = "Fun World",
                        shortname = "1",
                        graphic = "foo" )
        self.W.save()
        self.Q = QuizChallenge( shortname = "quiz1",
                                content = "foo" )
        self.Q.save()
        self.l1 = Stage( name = "Fun Level 1",
                         shortname = "1",
                         lesson = self.t2,
                         challenge = self.Q,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo")
        self.l2 = Stage( name = "Fun Level 2",
                         shortname = "2",
                         lesson = self.t2,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo")
        self.l3 = Stage( name = "Fun Level 3",
                         shortname = "3",
                         challenge = self.Q,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo",
                         hidden = True)
        self.l1.save()
        self.l2.save()
        self.l3.save()
        self.l2.prereqs.add(self.l1)
        self.l3.prereqs.add(self.l1)
        self.l2.save()
        self.l3.save()
        
        # Create some test users.
        self.u1 = User.objects.create_user("ishara",
                                           "*****@*****.**",
                                           "ishararulz")
        self.u2 = User.objects.create_user("alexis",
                                           "*****@*****.**",
                                           "alexisrulz")
        self.s1 = Student( user=self.u1 )
        self.s2 = Student( user=self.u2 )
        self.s1.save()
        self.s2.save()
        
        # Give the test users memorable names.
        self.ishara = self.s1
        self.alexis = self.s2
        
        self.l1.completed_by.add(self.alexis)
        self.l1.save()
Пример #5
0
class LessonTests(TestCase):
    def setUp(self):
        self.c = Client()
        self.t1 = Page( title="index",
                        content="sup" )
        self.t2 = Page( title="epic",
                        content="""
                        = This is a truly epic tale.
                        == OMG
                        === fur reals
                          
                        It stars **Ishara** //Alexis// and __Allen__.
                         
                        --THE END--
                        """)
        self.t1.save()
        self.t2.save()

        # Let's create a world with three stages.
        self.W = World( name = "Fun World",
                        shortname = "1",
                        graphic = "foo" )
        self.W.save()
        self.Q = QuizChallenge( shortname = "quiz1",
                                content = "foo" )
        self.Q.save()
        self.l1 = Stage( name = "Fun Level 1",
                         shortname = "1",
                         lesson = self.t2,
                         challenge = self.Q,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo")
        self.l2 = Stage( name = "Fun Level 2",
                         shortname = "2",
                         lesson = self.t2,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo")
        self.l3 = Stage( name = "Fun Level 3",
                         shortname = "3",
                         challenge = self.Q,
                         world = self.W,
                         xlocation = 1,
                         ylocation = 1,
                         graphic = "foo",
                         hidden = True)
        self.l1.save()
        self.l2.save()
        self.l3.save()
        self.l2.prereqs.add(self.l1)
        self.l3.prereqs.add(self.l1)
        self.l2.save()
        self.l3.save()
        
        # Create some test users.
        self.u1 = User.objects.create_user("ishara",
                                           "*****@*****.**",
                                           "ishararulz")
        self.u2 = User.objects.create_user("alexis",
                                           "*****@*****.**",
                                           "alexisrulz")
        self.s1 = Student( user=self.u1 )
        self.s2 = Student( user=self.u2 )
        self.s1.save()
        self.s2.save()
        
        # Give the test users memorable names.
        self.ishara = self.s1
        self.alexis = self.s2
        
        self.l1.completed_by.add(self.alexis)
        self.l1.save()
       
    # Anonymous viewers can not access the pages - they will be redirected
    # to the log-in/sign-up page. 
    def test_anon_lessons(self):
        pass
    
    # When a user visits a stage that doesn't have a lesson, they go directly
    # to the challenge.
    def test_go_challenge(self):
        self.c.login(username="******", password="******")
        response = self.c.get("/world/1/3/", follow=True)
        self.assertEqual(response.redirect_chain, [(u'http://testserver/world/1/3/challenge/', 302)])
        response = self.c.get("/world/1/3/lesson/", follow=True)
        self.assertEqual(response.redirect_chain, [(u'http://testserver/world/1/3/challenge/', 302)])
        
    # When a user visits a stage that doesn't have a challenge, they go directly
    # to the lesson.
    def test_go_challenge(self):
        self.c.login(username="******", password="******")
        response = self.c.get("/world/1/2/", follow=True)
        self.assertEqual(response.redirect_chain, [(u'http://testserver/world/1/2/lesson/', 302)])
        response = self.c.get("/world/1/2/challenge/", follow=True)
        self.assertEqual(response.redirect_chain, [(u'http://testserver/world/1/2/lesson/', 302)])
    
    # Test the world map. Ishara will see two stages, while Alexis will see 3.
    def test_world_map(self):
        self.c.login(username="******", password="******")
        response = self.c.get("/world/1/")
        self.assertTrue( "Fun Level 3" in response.content )
        self.c.logout()
        self.c.login(username="******", password="******")
        response = self.c.get("/world/1/")
        self.assertFalse( "Fun Level 3" in response.content )