Fix TO upload tests
This commit is contained in:
@@ -7,10 +7,13 @@ import boto3
|
||||
|
||||
|
||||
def build_uploader(config):
|
||||
if config["CSP"] == "aws":
|
||||
csp = config.get("CSP")
|
||||
if csp == "aws":
|
||||
return AwsUploader(config)
|
||||
elif config["CSP"] == "azure":
|
||||
elif csp == "azure":
|
||||
return AzureUploader(config)
|
||||
else:
|
||||
return MockUploader(config)
|
||||
|
||||
|
||||
class Uploader:
|
||||
@@ -21,6 +24,14 @@ class Uploader:
|
||||
return str(uuid4())
|
||||
|
||||
|
||||
class MockUploader(Uploader):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def get_token(self):
|
||||
return ({}, self.object_name())
|
||||
|
||||
|
||||
class AzureUploader(Uploader):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
@@ -2,20 +2,17 @@ from wtforms.fields import (
|
||||
BooleanField,
|
||||
DecimalField,
|
||||
FieldList,
|
||||
FileField,
|
||||
FormField,
|
||||
StringField,
|
||||
HiddenField
|
||||
HiddenField,
|
||||
)
|
||||
from wtforms.fields.html5 import DateField
|
||||
from wtforms.validators import Required, Optional
|
||||
from flask_wtf.file import FileAllowed
|
||||
from flask_wtf import FlaskForm
|
||||
|
||||
from .data import JEDI_CLIN_TYPES
|
||||
from .fields import SelectField
|
||||
from .forms import BaseForm
|
||||
from atst.forms.validators import FileLength
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
@@ -70,7 +67,11 @@ class AttachmentForm(BaseForm):
|
||||
|
||||
class TaskOrderForm(BaseForm):
|
||||
number = StringField(label=translate("forms.task_order.number_description"))
|
||||
pdf = FormField(AttachmentForm, label=translate("task_orders.form.supporting_docs_size_limit"), description=translate("task_orders.form.supporting_docs_size_limit"))
|
||||
pdf = FormField(
|
||||
AttachmentForm,
|
||||
label=translate("task_orders.form.supporting_docs_size_limit"),
|
||||
description=translate("task_orders.form.supporting_docs_size_limit"),
|
||||
)
|
||||
clins = FieldList(FormField(CLINForm))
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,16 @@ class Attachment(Base, mixins.TimestampsMixin):
|
||||
|
||||
return attachment
|
||||
|
||||
@classmethod
|
||||
def get_or_create(cls, object_name, params):
|
||||
try:
|
||||
return db.session.query(Attachment).filter_by(object_name=object_name).one()
|
||||
except NoResultFound:
|
||||
new_attachment = cls(**params)
|
||||
db.session.add(new_attachment)
|
||||
db.session.commit()
|
||||
return new_attachment
|
||||
|
||||
@classmethod
|
||||
def get(cls, id_):
|
||||
try:
|
||||
|
||||
@@ -9,7 +9,6 @@ from werkzeug.datastructures import FileStorage
|
||||
from atst.models import Attachment, Base, mixins, types
|
||||
from atst.models.clin import JEDICLINType
|
||||
from atst.utils.clock import Clock
|
||||
from atst.database import db
|
||||
|
||||
|
||||
class Status(Enum):
|
||||
@@ -56,15 +55,18 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
||||
self._pdf = self._set_attachment(new_pdf, "_pdf")
|
||||
|
||||
def _set_attachment(self, new_attachment, attribute):
|
||||
if isinstance(new_attachment, dict):
|
||||
attachment = Attachment(**new_attachment)
|
||||
db.session.add(attachment)
|
||||
db.session.commit
|
||||
return attachment
|
||||
if isinstance(new_attachment, Attachment):
|
||||
return new_attachment
|
||||
elif isinstance(new_attachment, FileStorage):
|
||||
return Attachment.attach(new_attachment, "task_order", self.id)
|
||||
elif isinstance(new_attachment, dict):
|
||||
if new_attachment["filename"] and new_attachment["object_name"]:
|
||||
attachment = Attachment.get_or_create(
|
||||
new_attachment["object_name"], new_attachment
|
||||
)
|
||||
return attachment
|
||||
else:
|
||||
return None
|
||||
elif not new_attachment and hasattr(self, attribute):
|
||||
return None
|
||||
else:
|
||||
|
||||
@@ -6,9 +6,6 @@ from flask import (
|
||||
url_for,
|
||||
current_app,
|
||||
)
|
||||
from azure.storage.common import CloudStorageAccount
|
||||
from azure.storage.blob import ContainerPermissions
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from . import task_orders_bp
|
||||
from atst.domain.authz.decorator import user_can_access_decorator as user_can
|
||||
@@ -100,7 +97,6 @@ def edit(task_order_id):
|
||||
@task_orders_bp.route("/task_orders/<task_order_id>/form/step_1")
|
||||
@user_can(Permissions.CREATE_TASK_ORDER, message="view task order form")
|
||||
def form_step_one_add_pdf(portfolio_id=None, task_order_id=None):
|
||||
|
||||
return render_task_orders_edit(
|
||||
"task_orders/step_1.html",
|
||||
portfolio_id=portfolio_id,
|
||||
|
||||
Reference in New Issue
Block a user