Ejemplo n.º 1
0
class TestFlash(unittest.TestCase):

    f1 = Flash("test", MSG_TYPE.SUCCESS)
    f2 = Flash("test", MSG_TYPE.FAIL)
    f3 = Flash(1, MSG_TYPE.FAIL)

    def test_equals1(self):
        f1_copy = Flash("test", MSG_TYPE.SUCCESS)
        self.assertTrue(self.f1.equals(f1_copy))

    def test_equals2(self):
        f1_copy = Flash("test 2", MSG_TYPE.SUCCESS)
        self.assertFalse(self.f1.equals(f1_copy))

    def test_equals3(self):  #testing the isinstance
        self.assertFalse(self.f1.equals(2))
        self.assertFalse(self.f1.equals('asdf'))
        self.assertFalse(self.f1.equals({}))
        self.assertFalse(self.f1.equals([2]))

    def test_equals4(self):
        self.assertFalse(self.f1.equals(self.f2))

    def test_gm1(self):
        self.assertEqual(self.f1.get_msg(), 'test')

    def test_gmt2(self):
        self.assertEqual(self.f1.get_msg_type(), MSG_TYPE.SUCCESS)

    def test_gmt3(self):
        self.assertEqual(self.f2.get_msg_type(), MSG_TYPE.FAIL)
Ejemplo n.º 2
0
 def register(self, can_register, form):
     if can_register:
         name = form.name.data
         email = form.email.data
         username = form.username.data
         password = sha256_crypt.encrypt(str(form.password.data))
         if self.model.user_existed(name):
             route = Route(True, 'register')
             flash = Flash('Username {0} already existed.'.format(username),
                           MSG_TYPE.FAIL)
             return PresentView(route, flash)
         else:
             self.model.register_user((name, email, username, password))
             route = Route(True, 'login')
             flash = Flash('You have registered.', MSG_TYPE.SUCCESS)
             return PresentView(route, flash)
     args = {'form': form}
     route = Route(False, 'register.html', args)
     return PresentView(route)
Ejemplo n.º 3
0
    def add_article(self, can_add_art, form):
        if can_add_art:
            title = form.title.data
            body = form.body.data
            link = form.link.data

            self.model.add_art((title, body, session['username'], link))
            flash = Flash('Article created', MSG_TYPE.SUCCESS)
            route = Route(True, 'dashboard')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'add_article.html', args)
        return PresentView(route)
Ejemplo n.º 4
0
    def edit_article(self, id, can_edit, form):

        article = self.model.art('articles', id)
        form.title.data = article['title']
        form.body.data = article['body']

        if can_edit:
            title = request.form['title']
            body = request.form['body']

            self.model.update_art((title, body, id))
            flash = Flash('Article Updated', MSG_TYPE.SUCCESS)
            route = Route(True, 'dashboard')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'edit_article.html', args)
        return PresentView(route)
Ejemplo n.º 5
0
    def add_course(self, can_add, form):
        if can_add:
            course_name = form.course_name.data
            term = form.term.data
            time = form.time.data
            instructor = form.instructor.data
            rating = form.rating.data
            difficulty = form.difficulty.data
            review = form.review.data

            params = (course_name, term, time, instructor, rating, difficulty,
                      review)
            self.model.insert_course(params)
            flash = Flash('Course created', MSG_TYPE.SUCCESS)
            route = Route(True, 'course')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'add_course.html', args)
        return PresentView(route)
Ejemplo n.º 6
0
 def login(self, request_method, request_form):
     if request_method:
         username = request_form['username']
         password_candidate = request_form['password']
         can_login = self.model.auth_login(username, password_candidate)
         if can_login[0]:
             #compare password
             if can_login[1]:
                 session['logged_in'] = True
                 session['username'] = username
                 flash = Flash('You are now logged in.', MSG_TYPE.SUCCESS)
                 route = Route(True, 'dashboard')
                 return PresentView(route, flash)
             else:
                 error = {'error': 'Invalid login'}
                 route = Route(False, 'login.html', error)
                 return PresentView(route)
         else:
             error = {'error': 'USER DOES NOT EXIST!'}
             route = Route(False, 'login.html', error)
             return PresentView(route)
     route = Route(False, 'login.html')
     return PresentView(route)
Ejemplo n.º 7
0
 def logout(self):
     flash = Flash('You are now logged out.', MSG_TYPE.SUCCESS)
     route = Route(True, 'login')
     return PresentView(route, flash)
Ejemplo n.º 8
0
 def delete_article(self, id):
     self.model.delete_art(id)
     flash = Flash('Article Deleted', MSG_TYPE.SUCCESS)
     route = Route(True, 'dashboard')
     return PresentView(route, flash)
Ejemplo n.º 9
0
 def test_get_flash3(self):  # pointer equality
     temp = Flash("test", MSG_TYPE.SUCCESS)
     self.assertNotEqual(self.v11.get_flash(), temp)
Ejemplo n.º 10
0
 def test_get_flash1(self):
     temp = Flash("test", MSG_TYPE.FAIL)
     self.assertTrue(self.v22.get_flash().equals(temp))
Ejemplo n.º 11
0
class TestPresentView(unittest.TestCase):

    r1 = Route(True, 'test', {})
    r2 = Route(True, 'test', {0: 1, 1: 'obj'})

    f1 = Flash("test", MSG_TYPE.SUCCESS)
    f2 = Flash("test", MSG_TYPE.FAIL)

    v11 = PresentView(r1, f1)
    v12 = PresentView(r1, f2)
    v21 = PresentView(r2, f1)
    v22 = PresentView(r2, f2)

    def test_get_route1(self):  #deep equality
        temp = Route(True, 'test', {})
        self.assertTrue(self.v11.get_route().equals(temp))

    def test_get_route2(self):  # pointer equality
        self.assertEqual(self.v11.get_route(), self.r1)

    def test_get_route3(self):  # pointer equality
        temp = Route(True, 'test', {})
        self.assertNotEqual(self.v11.get_route(), temp)

    def test_get_flash1(self):
        temp = Flash("test", MSG_TYPE.FAIL)
        self.assertTrue(self.v22.get_flash().equals(temp))

    def test_get_flash2(self):  # pointer equality
        self.assertEqual(self.v11.get_flash(), self.f1)

    def test_get_flash3(self):  # pointer equality
        temp = Flash("test", MSG_TYPE.SUCCESS)
        self.assertNotEqual(self.v11.get_flash(), temp)

    def test_get_flash4(self):  # pointer equality
        temp = PresentView(self.r2)
        self.assertEqual(temp.get_flash(), None)

    #
    def test_equals1(self):
        self.assertFalse(self.v11.equals(self.v12))

    def test_equals2(self):
        self.assertFalse(self.v11.equals(2))

    def test_equals3(self):
        self.assertTrue(self.v11.equals(self.v11))

    def test_equals4(self):
        temp = PresentView(self.r2, self.f1)
        self.assertTrue(self.v21.equals(temp))

    def test_equals5(self):
        temp = Flash("FAILLL", MSG_TYPE.SUCCESS)
        temp = PresentView(self.r2, temp)
        self.assertFalse(self.v21.equals(temp))

    def test_equals6(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(temp.equals(self.v11))

    def test_equals7(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(self.v22.equals(temp))

    def test_equals8(self):  # None flash
        temp = PresentView(self.r2)
        temp2 = PresentView(self.r2)
        self.assertFalse(temp.equals(temp2))

    def test_equals9(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(temp.equals(temp))
Ejemplo n.º 12
0
 def test_equals2(self):
     f1_copy = Flash("test 2", MSG_TYPE.SUCCESS)
     self.assertFalse(self.f1.equals(f1_copy))
Ejemplo n.º 13
0
 def test_equals1(self):
     f1_copy = Flash("test", MSG_TYPE.SUCCESS)
     self.assertTrue(self.f1.equals(f1_copy))
Ejemplo n.º 14
0
 def test_equals5(self):
     temp = Flash("FAILLL", MSG_TYPE.SUCCESS)
     temp = PresentView(self.r2, temp)
     self.assertFalse(self.v21.equals(temp))