Files
notifications-admin/tests/app/models/test_spreadsheet.py
Ben Thorner 4a5345f011 Move Spreadsheet models tests into own file
Previously this class was in app/utils.py, so it made sense for the
tests to be in "utils/test_csv.py". Since the class is now a proper
model [1], we can also move the tests into their own file.

[1]: 2c46d023da (diff-ac7b8d56e509c921efaadb5a776e1c9037531c4d2af78787f06f67a1f3533ae4)
2021-12-03 17:17:15 +00:00

43 lines
1.1 KiB
Python

from collections import OrderedDict
from pathlib import Path
import pytest
from app.models.spreadsheet import Spreadsheet
def test_can_create_spreadsheet_from_large_excel_file():
with open(str(Path.cwd() / 'tests' / 'spreadsheet_files' / 'excel 2007.xlsx'), 'rb') as xl:
ret = Spreadsheet.from_file(xl, filename='xl.xlsx')
assert ret.as_csv_data
def test_can_create_spreadsheet_from_dict():
assert Spreadsheet.from_dict(OrderedDict(
foo='bar',
name='Jane',
)).as_csv_data == (
"foo,name\r\n"
"bar,Jane\r\n"
)
def test_can_create_spreadsheet_from_dict_with_filename():
assert Spreadsheet.from_dict({}, filename='empty.csv').as_dict['file_name'] == "empty.csv"
@pytest.mark.parametrize('args, kwargs', (
(
('hello', ['hello']),
{},
),
(
(),
{'csv_data': 'hello', 'rows': ['hello']}
),
))
def test_spreadsheet_checks_for_bad_arguments(args, kwargs):
with pytest.raises(TypeError) as exception:
Spreadsheet(*args, **kwargs)
assert str(exception.value) == 'Spreadsheet must be created from either rows or CSV data'