コード例 #1
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_token_process_with_valid_action(self, mock_handler):
     self.payload['action'] = 'approve_registration_approval'
     token = TokenHandler.from_payload(self.payload)
     token.to_response()
     assert_true(
         mock_handler.called_with('registration', 'approve', self.payload,
                                  self.encoded_token))
コード例 #2
0
 def test_sanction_handler(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     with mock_auth(self.user):
         with mock.patch('osf.utils.tokens.handlers.{0}_handler'.format(self.kind)) as mock_handler:
             handler.to_response()
             mock_handler.assert_called_with('approve', self.reg, self.reg.registered_from)
コード例 #3
0
 def test_sanction_handler_no_sanction(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     self.Model.delete(self.sanction)
     with mock_auth(self.user):
         try:
             handler.to_response()
         except HTTPError as e:
             assert_equal(e.code, http.BAD_REQUEST)
             assert_equal(e.data['message_long'], NO_SANCTION_MSG.format(self.Model.DISPLAY_NAME))
コード例 #4
0
 def test_token_process_with_valid_action(self, mock_handler):
     self.payload['action'] = 'approve_registration_approval'
     token = TokenHandler.from_payload(self.payload)
     token.to_response()
     assert_true(
         mock_handler.called_with(
             'registration',
             'approve',
             self.payload,
             self.encoded_token
         )
     )
コード例 #5
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_sanction_handler(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[
         self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     with mock_auth(self.user):
         with mock.patch('osf.utils.tokens.handlers.{0}_handler'.format(
                 self.kind)) as mock_handler:
             handler.to_response()
             mock_handler.assert_called_with('approve', self.reg,
                                             self.reg.registered_from)
コード例 #6
0
 def test_sanction_handler_sanction_rejected(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     self.sanction.state = Sanction.REJECTED
     self.sanction.save()
     with mock_auth(self.user):
         try:
             handler.to_response()
         except HTTPError as e:
             assert_equal(e.code, http.GONE if self.kind in ['embargo', 'registration_approval'] else http.BAD_REQUEST)
             assert_equal(e.data['message_long'], REJECTED_MSG.format(self.sanction.DISPLAY_NAME))
コード例 #7
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_sanction_handler_no_sanction(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[
         self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     self.Model.delete(self.sanction)
     with mock_auth(self.user):
         try:
             handler.to_response()
         except HTTPError as e:
             assert_equal(e.code, http.BAD_REQUEST)
             assert_equal(e.data['message_long'],
                          NO_SANCTION_MSG.format(self.Model.DISPLAY_NAME))
コード例 #8
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_sanction_handler_sanction_approved(self):
     if not self.kind:
         return
     approval_token = self.sanction.approval_state[
         self.user._id]['approval_token']
     handler = TokenHandler.from_string(approval_token)
     self.sanction.state = Sanction.APPROVED
     self.sanction.save()
     with mock_auth(self.user):
         try:
             handler.to_response()
         except HTTPError as e:
             assert_equal(
                 e.code, http.BAD_REQUEST if self.kind
                 in ['embargo', 'registration_approval'] else http.GONE)
             assert_equal(e.data['message_long'],
                          APPROVED_MSG.format(self.sanction.DISPLAY_NAME))
コード例 #9
0
 def test_token_process_for_invalid_action_raises_TokenHandlerNotFound(self):
     self.payload['action'] = 'not a handler'
     token = TokenHandler.from_payload(self.payload)
     with assert_raises(TokenHandlerNotFound):
         token.to_response()
コード例 #10
0
 def test_from_payload(self):
     token = TokenHandler.from_payload(self.payload)
     assert_equal(token.encoded_token, self.encoded_token)
     assert_equal(token.payload, self.payload)
コード例 #11
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_token_process_for_invalid_action_raises_TokenHandlerNotFound(
         self):
     self.payload['action'] = 'not a handler'
     token = TokenHandler.from_payload(self.payload)
     with assert_raises(TokenHandlerNotFound):
         token.to_response()
コード例 #12
0
ファイル: test_tokens.py プロジェクト: xlecours/osf.io
 def test_from_payload(self):
     token = TokenHandler.from_payload(self.payload)
     assert_equal(token.encoded_token, self.encoded_token)
     assert_equal(token.payload, self.payload)