Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: GitHub Actions CI
name: GitHub Actions CI

on: [pull_request]

Expand All @@ -15,16 +15,14 @@ jobs:

- name: Install dependencies
run: |
# python -m pip install --upgrade setuptools pip
python -m pip install --upgrade pip
python -m pip install --upgrade wheel setuptools==57 pip
pip install -U -r requirements.txt
pip install -U -r dev-requirements.txt


- name: Test with pytest
run: |
py.test

- name: Upload coverage data to coveralls.io
run: coveralls
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
local_config.py
python
# Mac specific files
.DS_Store
.DS_Store
.venv/
Binary file not shown.
Binary file not shown.
18 changes: 16 additions & 2 deletions authoraffsrv/tests/unittests/test_author_affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from flask_testing import TestCase
import unittest
import mock
import openpyxl
from io import BytesIO

import authoraffsrv.app as app
from authoraffsrv.tests.unittests.stubdata import solrdata, formatted, export
Expand Down Expand Up @@ -50,14 +52,26 @@ def test_export_csv_div_format(self):
def test_export_excel_format(self):
# format the stubdata using the code
exported_data = Export(export.form_data).format(EXPORT_FORMATS[2])
with open(str(PROJECT_HOME)+'/authoraffsrv/tests/unittests/stubdata/ADS_Author-Affiliation.xlsx', 'rb') as f:
test_xlsx = f.read()
test_wbk = openpyxl.Workbook(BytesIO(test_xlsx))
test_sheet = test_wbk.active
exported_wbk = openpyxl.Workbook(BytesIO(exported_data))
exported_sheet = exported_wbk.active
# now compare it with an already formatted data that we know is correct
self.assertEqual(len(exported_data), 5632)
self.assertEqual(exported_sheet, test_sheet)

def test_export_excel_div_format(self):
# format the stubdata using the code
exported_data = Export(export.form_data).format(EXPORT_FORMATS[3])
with open(str(PROJECT_HOME)+'/authoraffsrv/tests/unittests/stubdata/ADS_Author-Affiliation-Div.xlsx', 'rb') as f:
test_xlsx = f.read()
test_wbk = openpyxl.Workbook(BytesIO(test_xlsx))
test_sheet = test_wbk.active
exported_wbk = openpyxl.Workbook(BytesIO(exported_data))
exported_sheet = exported_wbk.active
# now compare it with an already formatted data that we know is correct
self.assertEqual(len(exported_data), 5632)
self.assertEqual(exported_sheet, test_sheet)

def test_export_text_format(self):
# format the stubdata using the code
Expand Down
27 changes: 7 additions & 20 deletions authoraffsrv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import datetime
import re
import json
import xlwt
import openpyxl
import uuid
import unidecode

Expand Down Expand Up @@ -122,21 +122,16 @@ def __export_to_excel(self):
:return:
"""
# Create workbook and worksheet
wbk = xlwt.Workbook(encoding='UTF-8')
sheet = wbk.add_sheet(self.EXPORT_FILENAME)
wbk = openpyxl.Workbook()
sheet = wbk.active

row = 0
authors = list(self.selected_authors.keys())
authors.sort()
for author in authors:
sheet.write(row, 0, author)
col = 1
for value in self.selected_authors[author]:
[affiliation, last_active] = value.split('|')
sheet.write(row, col, affiliation)
sheet.write(row, col+1, last_active)
col += 2
row += 1
sheet.append([author, affiliation, last_active])

# save the spreadsheet to a temporary file
filename = self.TMP_EXCEL_FOLDER + self.EXPORT_FILENAME + str(uuid.uuid4())
Expand All @@ -155,10 +150,9 @@ def __export_to_excel_div(self):
:return:
"""
# Create workbook and worksheet
wbk = xlwt.Workbook(encoding='UTF-8')
sheet = wbk.add_sheet(self.EXPORT_FILENAME)
wbk = openpyxl.Workbook()
sheet = wbk.active

row = 0
authors = list(self.selected_authors.keys())
authors.sort()
for author in authors:
Expand All @@ -169,16 +163,9 @@ def __export_to_excel_div(self):
except IndexError:
author_split.append('')
# write the author name
sheet.write(row, 0, author_split[0])
sheet.write(row, 1, author_split[1])
# write the affiliations
col = 2
for value in self.selected_authors[author]:
[affiliation, last_active] = value.split('|')
sheet.write(row, col, affiliation)
sheet.write(row, col+1, last_active)
col += 2
row += 1
sheet.append([author_split[0], author_split[1], affiliation, last_active])

# save the spreadsheet to a temporary file
filename = self.TMP_EXCEL_FOLDER + self.EXPORT_FILENAME + str(uuid.uuid4())
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
git+https://github.com/adsabs/ADSMicroserviceUtils.git@v1.1.9
git+https://github.com/adsabs/ADSMicroserviceUtils.git@v1.2.3
future==0.18.2
itsdangerous==2.0.1
jinja2==3.0.3
xlwt==1.3.0
unidecode===1.2.0
werkzeug==2.0.2
werkzeug==2.0.2
openpyxl==3.1.5