API - update migration (date_format as non-nullable & add default value)
This commit is contained in:
parent
f4d405ef3d
commit
3777ac0a11
@ -11,15 +11,18 @@ import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'bf13b8f5589d'
|
||||
down_revision = '84d840ce853b'
|
||||
down_revision = '5b936821326d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('users', sa.Column('date_format', sa.String(length=50), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
op.add_column(
|
||||
'users', sa.Column('date_format', sa.String(length=50), nullable=True)
|
||||
)
|
||||
op.execute("UPDATE users SET date_format = 'MM/dd/yyyy'")
|
||||
op.alter_column('users', 'date_format', nullable=False)
|
||||
|
||||
|
||||
|
||||
def downgrade():
|
@ -235,6 +235,27 @@ class TestUserRegistration(ApiTestCaseMixin):
|
||||
assert data['status'] == 'success'
|
||||
assert 'auth_token' not in data
|
||||
|
||||
def test_it_creates_user_with_default_date_format(
|
||||
self, app: Flask
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
username = self.random_string()
|
||||
|
||||
client.post(
|
||||
'/api/auth/register',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
username=username,
|
||||
email=self.random_email(),
|
||||
password=self.random_string(),
|
||||
)
|
||||
),
|
||||
content_type='application/json',
|
||||
)
|
||||
|
||||
new_user = User.query.filter_by(username=username).first()
|
||||
assert new_user.date_format == 'MM/dd/yyyy'
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'input_language,expected_language',
|
||||
[('en', 'en'), ('fr', 'fr'), ('invalid', 'en'), (None, 'en')],
|
||||
|
@ -173,7 +173,7 @@ def register_user() -> Union[Tuple[Dict, int], HttpResponse]:
|
||||
if not user:
|
||||
new_user = User(username=username, email=email, password=password)
|
||||
new_user.timezone = 'Europe/Paris'
|
||||
new_user.date_format = 'dd/MM/yyyy'
|
||||
new_user.date_format = 'MM/dd/yyyy'
|
||||
new_user.confirmation_token = secrets.token_urlsafe(30)
|
||||
new_user.language = language
|
||||
db.session.add(new_user)
|
||||
@ -781,7 +781,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"bio": null,
|
||||
"birth_date": null,
|
||||
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
|
||||
"date_format": "dd/MM/yyyy",
|
||||
"date_format": "MM/dd/yyyy",
|
||||
"display_ascent": true,
|
||||
"email": "sam@example.com",
|
||||
"first_name": null,
|
||||
|
Loading…
Reference in New Issue
Block a user