Commit 1cf07f65 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[test] extract setup_database and use BytesIO instead of StringIO

parent e2e69b5a8fed
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from StringIO import StringIO
from io import BytesIO
from cubicweb.web import Redirect
from cubicweb.devtools.testlib import CubicWebTC
......@@ -23,16 +23,18 @@ from cubicweb.devtools.testlib import CubicWebTC
class ViewsTC(CubicWebTC):
def test_flat_scheme_concepts_import(self):
def setup_database(self):
with self.admin_access.client_cnx() as cnx:
scheme = cnx.create_entity('ConceptScheme', title=u'musique')
cnx.create_entity('ConceptScheme', title=u'musique')
cnx.commit()
def test_flat_scheme_concepts_import(self):
with self.admin_access.web_request() as req:
scheme = req.entity_from_eid(scheme.eid)
scheme = req.find('ConceptScheme', title=u'musique').one()
# simply test the form properly render and is well formed
self.view('skos.scheme.import', rset=scheme.as_rset(), req=req, template=None)
req.form = self.fake_form('skos.scheme.import', {
'stream': ('filename.txt', StringIO('\n\nélectro\nhip-hop\nrap\njazz\nclassique\n')),
'stream': ('filename.txt', BytesIO('\n\nélectro\nhip-hop\nrap\njazz\nclassique\n')),
'encoding': u'utf-8',
'language_code': u'fr',
'format': u'simple',
......@@ -47,11 +49,8 @@ class ViewsTC(CubicWebTC):
set(['fr']))
def test_lcsv_scheme_concepts_import(self):
with self.admin_access.client_cnx() as cnx:
scheme = cnx.create_entity('ConceptScheme', title=u'gni')
cnx.commit()
with self.admin_access.web_request() as req:
scheme = req.entity_from_eid(scheme.eid)
scheme = req.find('ConceptScheme', title=u'musique').one()
# simply test the form properly render and is well formed
self.view('skos.scheme.import', rset=scheme.as_rset(), req=req,
template=None)
......@@ -67,7 +66,7 @@ class ViewsTC(CubicWebTC):
self.assertRaises(Redirect, scheme.view, 'skos.scheme.import')
# check that the concept were added
with self.admin_access.client_cnx() as cnx:
scheme = cnx.find('ConceptScheme', title=u'gni').one()
scheme = cnx.find('ConceptScheme', title=u'musique').one()
self.assertEqual(len(scheme.top_concepts), 2)
concepts = cnx.find('Concept')
self.assertEqual(len(concepts), 5)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment