def test_with_introduction(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.client.api.authentication import generate_token from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) survey = self.portal.client['nl']['ict']['software-development'] survey.introduction = u'<p>Fancy intro.</p>' account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions/1') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertTrue('introduction' in response) self.assertEqual(response['introduction'], u'<p>Fancy intro.</p>')
def test_get_no_company_data_present(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token from Products.Five.testbrowser import Browser self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password="******") survey_session = SurveySession( title=u"Dummy session", created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path="nl/ict/software-development", account=account, ) Session.add(survey_session) browser = Browser() browser.addHeader("X-Euphorie-Token", generate_token(account)) browser.open("http://nohost/plone/client/api/users/1/sessions/1/company") self.assertEqual(browser.headers["Content-Type"], "application/json") response = json.loads(browser.contents) self.assertEqual(response["type"], "company")
def test_browser(self): import datetime from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.client.api.authentication import generate_token from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.handleErrors = False browser.open('http://nohost/plone/client/api/users/1/' 'sessions/1/report-timeline') self.assertEqual( browser.headers['Content-Type'], 'application/vnd.openxmlformats-' 'officedocument.spreadsheetml.sheet')
def test_browser_get(self): import datetime from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token from tno.euphorie.model import DutchCompany from Products.Five.testbrowser import Browser self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) survey_session.dutch_company = DutchCompany( title=u'Acme B.V.', employees='40h', email='*****@*****.**', submit_date=datetime.date(2012, 6, 6)) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.handleErrors = False browser.open( 'http://nohost/plone/client/api/users/1/sessions/1/' 'report-actionplan') self.assertEqual(browser.headers['Content-Type'], 'application/rtf') self.assertTrue('Bedrijfsnaam' in browser.contents)
def test_get_no_company_data_present(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token from Products.Five.testbrowser import Browser self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open( 'http://nohost/plone/client/api/users/1/sessions/1/company') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual(response['type'], 'company')
def test_get(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import Company from euphorie.client.model import SurveySession from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token from Products.Five.testbrowser import Browser self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account, company=Company(country='nl', employees='1-9', referer='other')) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open( 'http://nohost/plone/client/api/users/1/sessions/1/company') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual(response['type'], 'company')
def test_get_empty_profile(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.content.tests.utils import PROFILE_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token self.loginAsPortalOwner() addSurvey(self.portal, PROFILE_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open( 'http://nohost/plone/client/api/users/1/sessions/1/profile') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual(set(response), set(['id', 'type', 'title', 'profile'])) self.assertEqual(response['id'], 1) self.assertEqual(response['type'], 'profile') self.assertEqual(response['title'], u'Dummy session') self.assertEqual(response['profile'], [{ 'id': u'1', 'question': u'List all your departments:', 'value': [] }])
def test_get(self): import json from euphorie.client.api.authentication import generate_token self.loginAsPortalOwner() (account, survey, survey_session) = _setup_session(self.portal) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions/1/1/1') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual(response['type'], 'risk')
def test_user_info(self): import json from euphorie.client.tests.utils import addAccount from euphorie.client.api.authentication import generate_token account = addAccount() browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.handleErrors = False browser.open('http://nohost/plone/client/api/users/1') response = json.loads(browser.contents) self.assertEqual(response['type'], 'user')
def test_do_GET_basic(self): import json from euphorie.client.api.authentication import generate_token from euphorie.client.tests.utils import addAccount account = addAccount() browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual(set(response), set(['sessions'])) self.assertEqual(response['sessions'], [])
def test_get_translation(self): import json from euphorie.client.api.authentication import generate_token self.loginAsPortalOwner() (account, survey, survey_session) = _setup_session(self.portal) survey.language = 'nl' browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions/1/1/1') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) options = dict((opt['value'], opt['title']) for opt in response['frequency-options']) self.assertEqual(options['constant'], u'Voortdurend')
def test_get_translation(self): import json from euphorie.client.api.authentication import generate_token self.loginAsPortalOwner() (account, survey, survey_session) = _setup_session(self.portal) survey.language = "nl" browser = Browser() browser.addHeader("X-Euphorie-Token", generate_token(account)) browser.open("http://nohost/plone/client/api/users/1/sessions/1/1/1") self.assertEqual(browser.headers["Content-Type"], "application/json") response = json.loads(browser.contents) options = dict((opt["value"], opt["title"]) for opt in response["frequency-options"]) self.assertEqual(options["constant"], u"Voortdurend")
def test_get(self): import datetime import json from sqlalchemy.orm import object_session from euphorie.client.model import Risk from euphorie.client.model import ActionPlan from euphorie.client.api.authentication import generate_token from euphorie.client.api.tests.test_risk import _setup_session self.loginAsPortalOwner() (account, survey, survey_session) = _setup_session(self.portal) risk = object_session(survey_session).query(Risk).one() risk.action_plans.append(ActionPlan(action_plan=u"This is the plan", planning_start=datetime.date(2012, 6, 3))) browser = Browser() browser.addHeader("X-Euphorie-Token", generate_token(account)) browser.open("http://nohost/plone/client/api/users/1/" "sessions/1/1/1/actionplans/1") self.assertEqual(browser.headers["Content-Type"], "application/json") response = json.loads(browser.contents) self.assertEqual(response["plan"], u"This is the plan")
def test_get(self): import datetime import json from sqlalchemy.orm import object_session from euphorie.client.model import Risk from euphorie.client.model import ActionPlan from euphorie.client.api.authentication import generate_token from euphorie.client.api.tests.test_risk import _setup_session self.loginAsPortalOwner() (account, survey, survey_session) = _setup_session(self.portal) risk = object_session(survey_session).query(Risk).one() risk.action_plans.append( ActionPlan(action_plan=u'This is the plan', planning_start=datetime.date(2012, 6, 3))) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/' 'sessions/1/1/1/actionplans') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertTrue('action-plans' in response)
def test_get(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.client.api.authentication import generate_token from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions/1') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual( set(response), set([ 'id', 'survey', 'type', 'created', 'modified', 'title', 'next-step' ])) self.assertEqual(response['id'], 1) self.assertEqual(response['survey'], 'nl/ict/software-development') self.assertEqual(response['type'], 'session') self.assertEqual(response['title'], 'Dummy session') self.assertEqual(response['created'], '2012-04-22T23:05:12') self.assertEqual(response['modified'], '2012-04-23T11:50:30') self.assertEqual( response['next-step'], 'http://nohost/plone/client/api/users/1/sessions/1/' 'identification')
def test_get(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.client.api.authentication import generate_token from euphorie.content.tests.utils import BASIC_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey self.loginAsPortalOwner() addSurvey(self.portal, BASIC_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open('http://nohost/plone/client/api/users/1/sessions/1') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual( set(response), set(['id', 'survey', 'type', 'created', 'modified', 'title', 'next-step'])) self.assertEqual(response['id'], 1) self.assertEqual(response['survey'], 'nl/ict/software-development') self.assertEqual(response['type'], 'session') self.assertEqual(response['title'], 'Dummy session') self.assertEqual(response['created'], '2012-04-22T23:05:12') self.assertEqual(response['modified'], '2012-04-23T11:50:30') self.assertEqual( response['next-step'], 'http://nohost/plone/client/api/users/1/sessions/1/' 'identification')
def test_get_empty_profile(self): import datetime import json from z3c.saconfig import Session from euphorie.client.model import SurveySession from euphorie.content.tests.utils import PROFILE_SURVEY from euphorie.client.tests.utils import addAccount from euphorie.client.tests.utils import addSurvey from euphorie.client.api.authentication import generate_token self.loginAsPortalOwner() addSurvey(self.portal, PROFILE_SURVEY) account = addAccount(password='******') survey_session = SurveySession( title=u'Dummy session', created=datetime.datetime(2012, 4, 22, 23, 5, 12), modified=datetime.datetime(2012, 4, 23, 11, 50, 30), zodb_path='nl/ict/software-development', account=account) Session.add(survey_session) browser = Browser() browser.addHeader('X-Euphorie-Token', generate_token(account)) browser.open( 'http://nohost/plone/client/api/users/1/sessions/1/profile') self.assertEqual(browser.headers['Content-Type'], 'application/json') response = json.loads(browser.contents) self.assertEqual( set(response), set(['id', 'type', 'title', 'profile'])) self.assertEqual(response['id'], 1) self.assertEqual(response['type'], 'profile') self.assertEqual(response['title'], u'Dummy session') self.assertEqual( response['profile'], [{'id': u'1', 'question': u'List all your departments:', 'value': []}])
def generate_token(self, *a, **kw): from euphorie.client.api.authentication import generate_token return generate_token(*a, **kw)