-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from GSA-TTS/dev-utilities
Development Utilities and Misc Fixes
- Loading branch information
Showing
12 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
alembic/versions/dc3dd97eae46_remove_username_column_from_users_table.py
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,29 @@ | ||
"""Remove username column from users table | ||
Revision ID: dc3dd97eae46 | ||
Revises: 945ca77479d1 | ||
Create Date: 2024-03-05 13:21:29.812837 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "dc3dd97eae46" | ||
down_revision: Union[str, None] = "945ca77479d1" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade(): | ||
op.drop_column("users", "username") | ||
|
||
|
||
def downgrade(): | ||
op.add_column( | ||
"users", | ||
sa.Column("username", sa.String, nullable=True), | ||
) |
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
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
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
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
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
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
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
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,45 @@ | ||
import os | ||
from alembic.config import Config | ||
from alembic import command | ||
from boto3.session import Session | ||
from botocore.client import Config as BotocoreConfig | ||
from nad_ch.config.development_local import ( | ||
S3_ENDPOINT, | ||
S3_ACCESS_KEY, | ||
S3_SECRET_ACCESS_KEY, | ||
S3_BUCKET_NAME, | ||
) | ||
|
||
|
||
def main(): | ||
if os.getenv("APP_ENV") != "dev_local": | ||
raise Exception("This script can only be run in a local dev environment.") | ||
|
||
current_script_path = os.path.abspath(__file__) | ||
project_root = os.path.dirname(os.path.dirname(current_script_path)) | ||
alembic_cfg_path = os.path.join(project_root, "alembic.ini") | ||
|
||
alembic_cfg = Config(alembic_cfg_path) | ||
command.downgrade(alembic_cfg, "base") | ||
|
||
# flush storage | ||
session = Session() | ||
minio_client = session.client( | ||
"s3", | ||
endpoint_url=S3_ENDPOINT, | ||
aws_access_key_id=S3_ACCESS_KEY, | ||
aws_secret_access_key=S3_SECRET_ACCESS_KEY, | ||
aws_session_token=None, | ||
region_name="us-east-1", | ||
verify=False, | ||
config=BotocoreConfig(signature_version="s3v4"), | ||
) | ||
response = minio_client.list_objects_v2(Bucket=S3_BUCKET_NAME) | ||
|
||
for object in response["Contents"]: | ||
print("Deleting", object["Key"]) | ||
minio_client.delete_object(Bucket=S3_BUCKET_NAME, Key=object["Key"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,19 @@ | ||
import os | ||
from alembic.config import Config | ||
from alembic import command | ||
|
||
|
||
def main(): | ||
if os.getenv("APP_ENV") != "dev_local": | ||
raise Exception("This script can only be run in a local dev environment.") | ||
|
||
current_script_path = os.path.abspath(__file__) | ||
project_root = os.path.dirname(os.path.dirname(current_script_path)) | ||
alembic_cfg_path = os.path.join(project_root, "alembic.ini") | ||
|
||
alembic_cfg = Config(alembic_cfg_path) | ||
command.upgrade(alembic_cfg, "head") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,54 @@ | ||
import os | ||
import zipfile | ||
from nad_ch.config import create_app_context, OAUTH2_CONFIG | ||
from nad_ch.domain.entities import DataProducer, DataSubmission, User | ||
|
||
|
||
def zip_directory(folder_path, zip_path): | ||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf: | ||
for root, dirs, files in os.walk(folder_path): | ||
for file in files: | ||
zipf.write( | ||
os.path.join(root, file), | ||
os.path.relpath( | ||
os.path.join(root, file), os.path.join(folder_path, "..") | ||
), | ||
) | ||
|
||
|
||
def main(): | ||
if os.getenv("APP_ENV") != "dev_local": | ||
raise Exception("This script can only be run in a local dev environment.") | ||
|
||
ctx = create_app_context() | ||
|
||
new_producer = DataProducer(name="New Jersey") | ||
saved_producer = ctx.producers.add(new_producer) | ||
|
||
new_user = User( | ||
email="[email protected]", | ||
login_provider="cloudgov", | ||
logout_url=OAUTH2_CONFIG["cloudgov"]["logout_url"], | ||
) | ||
ctx.users.add(new_user) | ||
|
||
current_script_path = os.path.abspath(__file__) | ||
project_root = os.path.dirname(os.path.dirname(current_script_path)) | ||
gdb_path = os.path.join( | ||
project_root, "tests", "test_data", "geodatabases", "Naperville.gdb" | ||
) | ||
zipped_gdb_path = os.path.join( | ||
project_root, "tests", "test_data", "geodatabases", "Naperville.gdb.zip" | ||
) | ||
zip_directory(gdb_path, zipped_gdb_path) | ||
|
||
filename = DataSubmission.generate_filename(zipped_gdb_path, saved_producer) | ||
ctx.storage.upload(zipped_gdb_path, filename) | ||
new_submission = DataSubmission(filename, saved_producer) | ||
ctx.submissions.add(new_submission) | ||
|
||
os.remove(zipped_gdb_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
|
@@ -26,9 +26,7 @@ def test_get_or_create_user_existing_user(app_context): | |
app_context.auth.make_login_url = lambda x: "test" | ||
email = "[email protected]" | ||
login_provider = "test" | ||
user = User( | ||
username="johnny", email=email, login_provider=login_provider, logout_url="test" | ||
) | ||
user = User(email=email, login_provider=login_provider, logout_url="test") | ||
app_context.users.add(user) | ||
result = get_or_create_user(app_context, login_provider, email) | ||
assert result == user | ||
|
@@ -40,7 +38,6 @@ def test_get_or_create_user_new_user(app_context): | |
result = get_or_create_user(app_context, login_provider, email) | ||
assert isinstance(result, User) | ||
assert result.email == email | ||
assert result.username == "johnny" | ||
assert result.login_provider == login_provider | ||
|
||
|
||
|