Skip to content

Commit

Permalink
- use same method to get worksheet throughout tests
Browse files Browse the repository at this point in the history
- delete workbook if it exists before creating a new one
- Remove debug code
  • Loading branch information
elipe17 committed Oct 21, 2024
1 parent 8a25b39 commit 46eabe1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 7 additions & 11 deletions tdrs-backend/tdpservice/data_files/test/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for DataFiles Application."""
import os
from rest_framework import status
import pytest
import base64
Expand Down Expand Up @@ -82,6 +83,9 @@ def get_spreadsheet(response):
"""Return error report."""
decoded_response = base64.b64decode(response.data['xls_report'])

if os.path.exists('mycls.xlsx'):
os.remove('mycls.xlsx')

# write the excel file to disk
with open('mycls.xlsx', 'wb') as f:
f.write(decoded_response)
Expand All @@ -100,7 +104,7 @@ def assert_error_report_tanf_file_content_matches_with_friendly_names(response):

assert ws.cell(row=1, column=1).value == "Please refer to the most recent versions of the coding " \
+ "instructions (linked below) when looking up items and allowable values during the data revision process"
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == (
assert ws.cell(row=7, column=COL_ERROR_MESSAGE).value == (
"No records created.")

@staticmethod
Expand All @@ -118,21 +122,13 @@ def assert_error_report_ssp_file_content_matches_with_friendly_names(response):
@staticmethod
def assert_error_report_file_content_matches_without_friendly_names(response):
"""Assert the error report file contents match expected without friendly names."""
decoded_response = base64.b64decode(response.data['xls_report'])

# write the excel file to disk
with open('mycls.xlsx', 'wb') as f:
f.write(decoded_response)

# read the excel file from disk
wb = openpyxl.load_workbook('mycls.xlsx')
ws = wb.get_sheet_by_name('Sheet1')
ws = DataFileAPITestBase.get_spreadsheet(response)

COL_ERROR_MESSAGE = 4

assert ws.cell(row=1, column=1).value == "Please refer to the most recent versions of the coding " \
+ "instructions (linked below) when looking up items and allowable values during the data revision process"
assert ws.cell(row=8, column=COL_ERROR_MESSAGE).value == (
assert ws.cell(row=7, column=COL_ERROR_MESSAGE).value == (
"No records created."
)

Expand Down
2 changes: 0 additions & 2 deletions tdrs-backend/tdpservice/data_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def download_error_report(self, request, pk=None):
"""Generate and return the parsing error report xlsx."""
datafile = self.get_object()
all_errors = ParserError.objects.filter(file=datafile).order_by('-pk')
for e in all_errors:
print(e.pk, e.error_message)
filtered_errors = None
user = self.request.user
is_active = "Active" in datafile.section
Expand Down

0 comments on commit 46eabe1

Please sign in to comment.