-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efc006c
commit 1582036
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
from sqlalchemy import text | ||
from uuid import uuid4 | ||
|
||
from db import db | ||
from journalist_app import create_app | ||
from .helpers import random_datetime | ||
|
||
|
||
class UpgradeTester: | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
self.app = create_app(config) | ||
|
||
def load_data(self): | ||
''' | ||
We load nothing because this migration simply creates a table. | ||
''' | ||
pass | ||
|
||
def check_upgrade(self): | ||
''' | ||
We check nothing because this migration simply creates a table. | ||
''' | ||
pass | ||
|
||
|
||
class DowngradeTester: | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
self.app = create_app(config) | ||
|
||
def load_data(self): | ||
with self.app.app_context(): | ||
jid = self.add_journalist() | ||
self.add_revoked_token(jid) | ||
|
||
def add_journalist(self): | ||
params = { | ||
'username': 'test user', | ||
'uuid': str(uuid4()), | ||
'pw_salt': 'testtesttesttest', | ||
'pw_hash': 'testtesttesttest', | ||
'is_admin': False, | ||
'otp_secret': 'abcd1234', | ||
'is_totp': False, | ||
'hotp_counter': 0, | ||
'last_token': '1234', | ||
'created_on': random_datetime(nullable=True), | ||
'last_access': random_datetime(nullable=True), | ||
'passphrase_hash': 'abcd1234', | ||
} | ||
sql = '''INSERT INTO journalists (username, uuid, pw_salt, pw_hash, is_admin, otp_secret, | ||
is_totp, hotp_counter, last_token, created_on, last_access, passphrase_hash) | ||
VALUES (:username, :uuid, :pw_salt, :pw_hash, :is_admin, :otp_secret, :is_totp, | ||
:hotp_counter, :last_token, :created_on, :last_access, :passphrase_hash); | ||
''' | ||
return db.engine.execute(text(sql), **params).lastrowid | ||
|
||
def add_revoked_token(self, jid): | ||
params = { | ||
'journalist_id': jid, | ||
'token': 'abc123', | ||
} | ||
sql = '''INSERT INTO revoked_tokens (journalist_id, token) | ||
VALUES (:journalist_id, :token) | ||
''' | ||
db.engine.execute(text(sql), **params) | ||
|
||
def check_downgrade(self): | ||
''' | ||
We check nothing because this migration simply drops a table. As long as the migration | ||
passes, we are ok. | ||
''' | ||
pass |