Skip to content

Commit

Permalink
Translating the output plus controller and messages. Added some tests…
Browse files Browse the repository at this point in the history
… over the output_plus controller
  • Loading branch information
puria committed Jun 11, 2017
1 parent 608021e commit efc2cba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
23 changes: 10 additions & 13 deletions ksweb/ksweb/controllers/output_plus.py
Expand Up @@ -3,41 +3,40 @@
from bson import ObjectId
from ksweb.controllers.resolve import ResolveController
from tg import expose, RestController, predicates, request, decode_params
from tg.i18n import ugettext as _
from ksweb import model


class OutputPlusController(RestController):
# Uncomment this line if your controller requires an authenticated user
allow_only = predicates.not_anonymous()

@expose('json')
@decode_params('json')
def post(self, highlighted_text=u'', workspace=None, list_=None):
first_5_worlds = u' '.join(highlighted_text.split())
first_5_worlds = u' '.join(first_5_worlds.split(" ")[:5])
def post(self, highlighted_text=u'', workspace=None, list_=[]):
first_5_words = u' '.join(highlighted_text.split())
first_5_words = u' '.join(first_5_words.split(" ")[:5])

user = request.identity['user']
#category = model.Category.query.find({'name': 'Altro'}).first()

qa = model.Qa(
_owner=user._id,
_category=workspace,
_parent_precondition=None,
title=u'Domanda per l\'Output ' + first_5_worlds,
question=u'Inserisci ' + first_5_worlds,
title=_(u'Domanda per l\'Output ') + first_5_words,
question=_(u'Inserisci ') + first_5_words,
tooltip=None,
link=None,
type='multi',
answers=[u'Attiva ' + first_5_worlds],
answers=[_(u'Attiva ') + first_5_words],
public=True,
visible=True)

precondition = model.Precondition(
_owner=user._id,
_category=workspace,
title=u'Filtro per l\'Output ' + first_5_worlds,
title=_(u'Filtro per l\'Output ') + first_5_words,
type='simple',
condition=[qa._id, u'Attiva ' + first_5_worlds])
condition=[qa._id, _(u'Attiva ') + first_5_words])

content = []
for elem in list_:
Expand All @@ -50,8 +49,7 @@ def post(self, highlighted_text=u'', workspace=None, list_=None):
'content': _id
})


title = u'Output ' + first_5_worlds
title = _(u'Output ') + first_5_words
output = model.Output(
_owner=user._id,
_category=workspace,
Expand All @@ -63,4 +61,3 @@ def post(self, highlighted_text=u'', workspace=None, list_=None):
html=highlighted_text
)
return dict(_id=str(output._id), title=title)

29 changes: 29 additions & 0 deletions ksweb/ksweb/tests/functional/test_output.py
Expand Up @@ -184,3 +184,32 @@ def test_human_readable_details(self):
resp = self.app.get('/output/human_readable_details', params={'_id': out1._id})
assert 'human_readbale_content' in resp
assert out1._id in resp

class TestOutputPlus(TestController):
application_under_test = 'main'

def setUp(self):
TestController.setUp(self)
self.category = self._get_category('Categoria 1')

def test_output_plus_creation(self):
self._login_lawyer()
self.app.get('/output_plus/post', params=dict(
highlighted_text='output_plus',
workspace=str(self.category._id),
), status=200)

qa = self._get_qa_by_title('Domanda per l\'Output output_plus')
assert qa

def test_output_plus_with_nested_output(self):
self._login_lawyer()
nested_output = self._create_fake_output("nested_output")
self.app.post_json('/output_plus/post', params=dict(
highlighted_text='output_plus',
workspace=str(self.category._id),
list_=["output_%s" % str(nested_output._id)],
), status=200)

qa = self._get_qa_by_title('Domanda per l\'Output output_plus')
assert qa

0 comments on commit efc2cba

Please sign in to comment.