Beispiel #1
0
def fill_db():
    create_roles()
    u1 = User('u1', 'p1', 'Us', 'Er1')
    u2 = User('u2', 'p2', 'Us', 'Er2')
    u3 = User('u3', 'p3', 'Us', 'Er3')

    admin = User('admin', 'admin', 'Ad', 'Min')
    admin.roles.append(Role.admin())
    user_manager = User('manager', 'manager', 'Man', 'Ager')
    user_manager.roles.append(Role.manager())

    today = datetime.date.today()
    one_day = datetime.timedelta(days=1)
    one_month = datetime.timedelta(days=30)
    two_months = one_day + one_month

    t1 = Trip('D1', utils.print_date(today), utils.print_date(today + one_day),
              'C1', u1)
    t2 = Trip('D2', utils.print_date(today + one_day),
              utils.print_date(today + two_months), 'C1', u1)
    t3 = Trip('D3', utils.print_date(today - one_month),
              utils.print_date(today - one_day), 'C1', u1)

    db.session.add_all([u1, u2, u3, admin, user_manager, t1, t2, t3])
    db.session.commit()
Beispiel #2
0
    def test_generate_rest_token_happy(self):
        expected_user = utils.create_and_save_user()

        user_token = expected_user.generate_rest_auth_token()

        actual_user = User.get_user_given_rest_token(user_token)
        self.assertEqual(expected_user.id, actual_user.id)
Beispiel #3
0
def _verify_token(token):
    g.user = None
    u = User.get_user_given_rest_token(token)
    if u:
        g.user = u
        return True
    return False
Beispiel #4
0
    def test_generate_rest_token_timeout(self):
        exp_time = 1
        expected_user = utils.create_and_save_user()

        token = expected_user.generate_rest_auth_token(exp_time)
        time.sleep(2)

        self.assertIsNone(User.get_user_given_rest_token(token))
Beispiel #5
0
def register_user():
    user = None
    try:
        user = User.create_from_json(request.get_json())
    except ValidationError:
        abort(400)

    if user:
        db.session.add(user)
        db.session.commit()
        return jsonify(user.as_dict()), 201
Beispiel #6
0
    def test_create_user_from_request(self):
        # Arrange
        user_data = {
            'username': '******',
            'password': '******',
            'first_name': 'a',
            'last_name': 'z'
        }

        # Act
        user = User.create_from_json(user_data)

        # Assert
        self.assertEqual(user.username, 'test1')
        self.assertEqual(user.first_name, 'a')
Beispiel #7
0
 def test_generate_rest_token_bad_token(self):
     actual_user = User.get_user_given_rest_token(
         'phony_token2123345wafweqrfds')
     self.assertIsNone(actual_user)
Beispiel #8
0
def create_user(user='******', password='******', first_name='Us', last_name='Ser'):
    return User(user, password, first_name, last_name)