def test_no_user(self): """ If we try to get info without a login, get an error back """ self.request.user = None result = sessions_delete_view(self.request)['d'] self.assertEqual( result, error_dict('api_errors', 'not authenticated for this request'))
def test_non_our_token_provided(self): """ If the token exists but isn't ours, say so """ self.request.json_body = {'token': 'badtoken'} self.datautils.create_session() self.datautils.create_session() result = sessions_delete_view(self.request)['d'] self.assertIsInstance(result, dict) self.assertEqual(result, error_dict('api_errors', 'no valid token provided'))
def test_good_token(self): """ If the token is valid, return {} and the token should be deleted """ s = self.datautils.create_session() self.assertEqual( self.session.query(Session).filter(Session.id == s.id).count(), 1) self.request.json_body = {'token': s.token} result = sessions_delete_view(self.request)['d'] self.assertIsInstance(result, dict) self.assertEqual(result, {}) self.assertEqual( self.session.query(Session).filter(Session.id == s.id).count(), 0)
def test_no_token_provided(self): """ If we do not provide a token, get an error """ self.request.json_body = {} self.datautils.create_user({ 'username': '******', 'password': '******' }) result = sessions_delete_view(self.request)['d'] self.assertIsInstance(result, dict) self.assertEqual(result, error_dict('api_errors', 'no valid token provided'))