示例#1
0
 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>')
示例#2
0
    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")
示例#3
0
 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>')
示例#4
0
 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')
示例#5
0
 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)
示例#6
0
 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')
示例#7
0
 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')
示例#8
0
 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')
示例#9
0
 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': []
     }])
示例#10
0
 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')
示例#11
0
 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')
示例#12
0
 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')
示例#13
0
 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')
示例#14
0
 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'], [])
示例#15
0
 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'], [])
示例#16
0
 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')
示例#17
0
 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')
示例#18
0
    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")
示例#19
0
    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")
示例#20
0
 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)
示例#21
0
 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')
示例#22
0
 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')
示例#23
0
 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': []}])
示例#24
0
 def generate_token(self, *a, **kw):
     from euphorie.client.api.authentication import generate_token
     return generate_token(*a, **kw)
示例#25
0
 def generate_token(self, *a, **kw):
     from euphorie.client.api.authentication import generate_token
     return generate_token(*a, **kw)