def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    user_table = op.create_table(
        'user', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('username', sa.String(length=32), nullable=False),
        sa.Column('password_hash', sa.String(length=128), nullable=False),
        sa.Column('created',
                  sa.TIMESTAMP(),
                  server_default=sa.text('CURRENT_TIMESTAMP'),
                  nullable=False),
        sa.Column('updated',
                  sa.TIMESTAMP(),
                  server_default=sa.text(
                      'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')),
        sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_user_username'),
                    'user', ['username'],
                    unique=True)
    # ### end Alembic commands ###

    # insert users
    user = UserModel()
    username = app.config['AUTH_USERNAME']
    password = app.config['AUTH_PASSWORD']
    user.hash_password(password)
    hash_password = user.password_hash

    op.bulk_insert(user_table, [{
        'username': username,
        'password_hash': hash_password
    }])
Beispiel #2
0
class TestUserModel(unittest.TestCase):
    def setUp(self):
        self.class_under_test = UserModel()

    @patch('core.models.user.User')
    def test_should_get_all(self, mock_user_get_all):
        user = UserModel()
        user.username = "******"
        user.id = 12
        mock_user_get_all.query.all.return_value = [user]

        users = self.class_under_test.get_all()
        self.assertEqual(1, len(users))

        user = users[0]
        self.assertEqual(12, user.id)
        self.assertEqual('Foo', user.username)

    def test_should_verify_password(self):
        password = '******';
        self.class_under_test.hash_password(password)
        self.assertTrue(self.class_under_test.verify_password(password))

    @patch('core.db.session.commit', return_value=None)
    @patch('core.db.session.add', return_value=None)
    def test_save(self, mock_add, mock_commit):
        user = UserModel()
        user.username = "******"
        user.id = 12

        user.save()
Beispiel #3
0
    def post(username, password):
        if username is None or password is None:
            abort(
                400,
                message="Missing arguments."
            )
        has_user = UserModel \
            .query \
            .filter(UserModel.username == username) \
            .first()
        if has_user is not None:
            abort(
                400,
                message="User with username: "******" already exist."
            )
        user = UserModel(username=username)
        user.hash_password(password)
        user.save()

        return ({'id': user.id, 'username': user.username}, 201)