119 |
119 |
def filetype(request):
|
120 |
120 |
return request.param
|
121 |
121 |
|
|
122 |
@pytest.fixture
|
|
123 |
def sheet_name(filetype):
|
|
124 |
return 'Feuille2' if filetype != 'data.csv' else ''
|
|
125 |
|
|
126 |
|
|
127 |
@pytest.fixture
|
|
128 |
def file_content(filetype):
|
|
129 |
with get_file_content(filetype) as fd:
|
|
130 |
yield fd.read()
|
|
131 |
|
|
132 |
|
122 |
133 |
def test_default_column_keynames(setup, filetype):
|
123 |
134 |
csvdata = CsvDataSource.objects.create(csv_file=File(get_file_content(filetype), filetype),
|
124 |
135 |
sheet_name='Feuille2',
|
... | ... | |
855 |
866 |
app = login(app)
|
856 |
867 |
response = app.get(csvdata.get_absolute_url())
|
857 |
868 |
assert 'Oct. 27, 2019, 2:20 a.m.' in response
|
|
869 |
|
|
870 |
|
|
871 |
def test_view_manage_create(app, admin_user, filetype, file_content, sheet_name):
|
|
872 |
app = login(app)
|
|
873 |
response = app.get(reverse('create-connector', kwargs={'connector': 'csvdatasource'}))
|
|
874 |
response.form.set('title', 'test title')
|
|
875 |
response.form.set('slug', 'test-slug')
|
|
876 |
response.form.set('description', 'test description')
|
|
877 |
response.form.set('csv_file', webtest.Upload(filetype, file_content, 'application/octet-stream'))
|
|
878 |
response.form.set('columns_keynames', 'a,b,c,d,e')
|
|
879 |
if sheet_name:
|
|
880 |
response.form.set('sheet_name', sheet_name)
|
|
881 |
response = response.form.submit()
|
|
882 |
assert response.location
|
|
883 |
response = response.follow()
|
|
884 |
assert 'test title' in response
|
|
885 |
assert 'test description' in response
|
|
886 |
assert CsvDataSource.objects.count() == 1
|
|
887 |
resource = CsvDataSource.objects.get()
|
|
888 |
assert resource.title == 'test title'
|
|
889 |
assert resource.slug == 'test-slug'
|
|
890 |
assert resource.description == 'test description'
|
|
891 |
assert resource.csv_file.read() == file_content
|
|
892 |
assert resource.columns_keynames == 'a,b,c,d,e'
|
|
893 |
assert resource.sheet_name == sheet_name
|
858 |
|
-
|