예제 #1
0
    def run(self):
        access = self.load_config()
        if not access:
            try:
                access = self.get_access()
            except TokenRequestDenied as e:
                print('Fail to validate the verifier.')

        if not access:
            self.save_config()
            return

        self.client = Client(PMR2ROOT,
                             session=self.auth_client.session,
                             use_default_headers=True)

        try:
            self.client()
        except ValueError as e:
            # JSON decoding error
            print('Credentials are invalid and are purged.  Quitting')
            self.auth_client.session._client.client.resource_owner_key = ''
            self.auth_client.session._client.client.resource_owner_secret = ''
            self.scope = DEFAULT_SCOPE
            self.save_config()
            return

        self.active = True
        print('Starting PMR2 Demo Shell...')
        self.save_config()
        self.shell()
예제 #2
0
    def test_client_state(self):
        session = DummySession()
        client = Client('http://pmr.example.com', session)
        result = client()
        state = result.get('workspace-add')

        self.assertEqual(sorted(state.keys()), [u'actions', u'fields'])
예제 #3
0
 def tryURL(self, url):
     state = None
     if self.client:
         state = self.client(target=url)
     else:
         self.client = Client(use_default_headers=True)
         state = self.client(target=url)
     return state
예제 #4
0
    def test_client_state_post(self):
        session = DummySession()
        client = Client('http://pmr.example.com', session)
        result = client()
        state = result.get('workspace-add')
        next_state = state.post(action='add',
                                fields={
                                    'storage': 'mercurial',
                                    'description': 'test workspace',
                                    'title': 'test'
                                })

        self.assertEqual(next_state.value()['description'], 'test workspace')
        self.assertRaises(TypeError, next_state.post, action='test', fields={})
예제 #5
0
 def setVerifier(self, verifier):
     self.auth_client.set_verifier(verifier=verifier)
     token = self.auth_client.fetch_access_token()
     print(token)
     self._awaitingVerifier = False
     self.client = Client(PMR2ROOT,
                          session=self.auth_client.session,
                          use_default_headers=True)
     try:
         self.client()
     except ValueError as e:
         # JSON decoding error
         print('Credentials are invalid and are purged.  Quitting')
         self.auth_client.session._client.client.resource_owner_key = ''
         self.auth_client.session._client.client.resource_owner_secret = ''
         self.scope = DEFAULT_SCOPE
         self.save_config()
         return
     self.active = True
예제 #6
0
    def test_client_dashboard(self):
        session = DummySession()
        client = Client('http://pmr.example.com', session)
        result = client()

        self.assertEqual(result.keys(), ['workspace-home', 'workspace-add'])