Пример #1
0
def init_db():
    db.drop_all()
    db.create_all()
    db.session.add(User('User1', 'Level_A', 1, 0, 2))
    db.session.add(User('User2', 'Level_B', 10, 5, 3))
    db.session.add(User('Level_C', 'Level_C', 30, 4, 6))
    db.session.add(User('Halil', 'Halil', 0, 0, 0))
    db.session.commit()
Пример #2
0
def init_db():
    db.drop_all()
    db.create_all()
    db.session.add(User('Level_A', 'Level_A', 1, 0, 2))
    db.session.add(User('Level_B', 'Level_B', 16, 7, 3))
    db.session.add(User('Level_C', 'Level_C', 30, 4, 6))
    db.session.add(User('eelco', 'eelco', 0, 0, 0))
    db.session.commit()
Пример #3
0
class LoginTests(unittest.TestCase):

    user = User('Foo', 'bar', 10, 10, 5)

    @classmethod
    def setUpClass(cls):
        db.session.add(cls.user)

    @classmethod
    def tearDownClass(cls):
        db.session.rollback()
        db.session.query(User).delete()
        db.session.commit()

    def test_check_login(self):
        self.assertTrue(user_exists('Foo', 'bar'))
        self.assertFalse(user_exists('bar', 'baz'))

    # valid username and password
    def test_login(self):
        self.browser.visit("http://localhost:5555/login")
        self.browser.fill('username', 'Foo')
        self.browser.fill('password', 'bar')
        self.browser.find_by_value("Login").click()
        from webbrowser import browser
        assert browser.is_text_present("Succesfull")
Пример #4
0
class DatabaseLayerTests(unittest.TestCase):

    user_1 = User('Test_A', 'level_A', 1, 0, 0)
    params = {'1': 'work', '2': 'work', '3': 'work', '4': 'work', '5': 'work'}
    client = app.test_client()
    request = client.post('/nouns',
                          environ_base={'HTTP_USER_AGENT': 'Chrome, etc'})
    request.params = params

    @classmethod
    def setUpClass(cls):
        db.session.add(cls.user_1)

    @classmethod
    def tearDownClass(cls):
        db.session.rollback()
        db.session.query(User).delete()
        db.session.commit()

    def test_allowed_in_level(self):
        self.assertEqual(0, correct_answers_in_post(self.params))
        self.assertEqual(5, incorrect_answers_in_post(self.params))

    def test_update_user_results(self):
        update_user_results('Test_A', 5, 5)
        self.assertEqual(
            6,
            db.session.query(User).filter_by(
                username='******').first().amountCorrect)
        self.assertEqual(
            5,
            db.session.query(User).filter_by(
                username='******').first().amountIncorrect)
class AuthenticationTests(unittest.TestCase):

    user = User('Foo', 'bar', 10, 10, 5)

    @classmethod
    def setUpClass(cls):
        db.session.add(cls.user)

    @classmethod
    def tearDownClass(cls):
        db.session.rollback()
        db.session.query(User).delete()
        db.session.commit()

    def test_get_user(self):
        self.assertEqual(self.user.username, get_user('Foo', 'bar').username)
        self.assertEqual(self.user.password, get_user('Foo', 'bar').password)
        self.assertEqual(None, get_user('No', 'user'))

    def test_check_login(self):
        self.assertTrue(user_exists('Foo', 'bar'))
        self.assertFalse(user_exists('bar', 'baz'))

    def test_registered_user(self):
        self.assertEqual(0, register_user('Foo', 'bar'))

    def test_register_user(self):
        self.assertEqual(1, register_user('new', 'user'))
        self.assertEqual(
            'new',
            db.session.query(User).filter_by(username='******').first().username)
Пример #6
0
def register_user(userName, passWord):
    if user_exists(userName, passWord) is False:
        new_user = User(userName, passWord, 0, 0, 0)
        db.session.add(new_user)
        db.session.commit()
        return 1
    else:
        return 0
Пример #7
0
class LevelAccessTests(unittest.TestCase):

    user_1 = User('Test_A', 'level_A', 1, 0, 0)
    user_2 = User('Test_B', 'level_A', 16, 7, 4)
    user_3 = User('Test_C', 'level_A', 22, 0, 14)

    @classmethod
    def setUpClass(cls):
        db.session.add(cls.user_1)
        db.session.add(cls.user_2)
        db.session.add(cls.user_3)

    @classmethod
    def tearDownClass(cls):
        db.session.rollback()
        db.session.query(User).delete()
        db.session.commit()

    def test_allowed_in_level(self):
        self.assertTrue(allowed_in_level('A', 0))
        self.assertTrue(allowed_in_level('A', 10))
        self.assertTrue(allowed_in_level('A', 20))
        self.assertTrue(allowed_in_level('A', 30))
        self.assertFalse(allowed_in_level('B', 0))
        self.assertFalse(allowed_in_level('B', 10))
        self.assertTrue(allowed_in_level('B', 20))
        self.assertTrue(allowed_in_level('B', 30))
        self.assertFalse(allowed_in_level('C', 0))
        self.assertFalse(allowed_in_level('C', 10))
        self.assertFalse(allowed_in_level('C', 20))
        self.assertTrue(allowed_in_level('C', 30))

    def test_get_correct_answers(self):
        self.assertEqual(get_correct_answers(self.user_2.username), 16)

    def test_get_incorrect_answers(self):
        self.assertEqual(get_incorrect_answers(self.user_2.username), 7)

    def test_calculate_score(self):
        self.assertEqual(11.13, calculate_score(self.user_2.username))