Refactor attachment setters and add tests
This commit is contained in:
@@ -47,7 +47,7 @@ class TestCSPEstimate:
|
||||
attachment = Attachment(filename="sample.pdf", object_name="sample")
|
||||
to.csp_estimate = attachment
|
||||
|
||||
assert to.attachment_id == attachment.id
|
||||
assert to.csp_attachment_id == attachment.id
|
||||
|
||||
def test_setting_estimate_with_file_storage(self):
|
||||
to = TaskOrder()
|
||||
@@ -77,3 +77,41 @@ class TestCSPEstimate:
|
||||
|
||||
to.csp_estimate = ""
|
||||
assert to.csp_estimate is None
|
||||
|
||||
|
||||
class TestPDF:
|
||||
def test_setting_pdf_with_attachment(self):
|
||||
to = TaskOrder()
|
||||
attachment = Attachment(filename="sample.pdf", object_name="sample")
|
||||
to.pdf = attachment
|
||||
|
||||
assert to.pdf_attachment_id == attachment.id
|
||||
|
||||
def test_setting_pdf_with_file_storage(self):
|
||||
to = TaskOrder()
|
||||
with open(PDF_FILENAME, "rb") as fp:
|
||||
fs = FileStorage(fp, content_type="application/pdf")
|
||||
to.pdf = fs
|
||||
|
||||
assert to.pdf is not None
|
||||
assert to.pdf.filename == PDF_FILENAME
|
||||
|
||||
def test_setting_pdf_with_invalid_object(self):
|
||||
to = TaskOrder()
|
||||
with pytest.raises(TypeError):
|
||||
to.pdf = "invalid"
|
||||
|
||||
def test_setting_pdf_with_empty_value(self):
|
||||
to = TaskOrder()
|
||||
assert to.pdf is None
|
||||
|
||||
to.pdf = ""
|
||||
assert to.pdf is None
|
||||
|
||||
def test_removing_pdf(self):
|
||||
attachment = Attachment(filename="sample.pdf", object_name="sample")
|
||||
to = TaskOrder(pdf=attachment)
|
||||
assert to.pdf is not None
|
||||
|
||||
to.pdf = ""
|
||||
assert to.pdf is None
|
||||
|
@@ -53,7 +53,7 @@ class TestDownloadCSPEstimate:
|
||||
assert expected_contents == response.data
|
||||
|
||||
def test_download_without_attachment(self, client, user_session):
|
||||
self.task_order.attachment_id = None
|
||||
self.task_order.csp_attachment_id = None
|
||||
user_session(self.user)
|
||||
response = client.get(
|
||||
url_for(
|
||||
|
Reference in New Issue
Block a user