def test_context_auth_traditional(self): """Test authentication within context - the traditional way.""" with op.context(api_key='1_1R_3', host=self.api_host) as ctx: self.assertEqual(ctx.me.user_name, 'August Admin') self.assertEqual(ctx.me.realm_id, 1) self.assertEqual(ctx.me.realm_name, 'grin') self.assertEqual(ctx.me.app_name, None) self.assertEqual(ctx.me.app_id, None)
def test_context_auth_api_key(self): """Test authentication within context with api-key.""" with op.context(host=self.api_host) as ctx: ctx.auth(api_key='1_1R_3') self.assertEqual(ctx.me.user_name, 'August Admin') self.assertEqual(ctx.me.realm_id, 1) self.assertEqual(ctx.me.realm_name, 'grin') self.assertEqual(ctx.me.app_id, None) self.assertEqual(ctx.me.app_name, None)
def test_context_auth_world(self): """Test authentication within context with app_id and app_secret.""" with op.context(host=self.api_host) as ctx: ctx.auth(realm_id=1) self.assertEqual(ctx.me.user_name, None) self.assertEqual(ctx.me.realm_id, 1) self.assertEqual(ctx.me.realm_name, 'grin') self.assertEqual(ctx.me.app_id, None) self.assertEqual(ctx.me.app_name, None)
def test_context_auth_app_name(self): """Test authentication within context with app_name and app_secret.""" with op.context(host=self.api_host) as ctx: ctx.auth(app_name='parkteam', app_secret='app-secret-100') self.assertEqual(ctx.me.user_name, None) self.assertEqual(ctx.me.realm_id, None) self.assertEqual(ctx.me.realm_name, None) self.assertEqual(ctx.me.app_id, 100) self.assertEqual(ctx.me.app_name, "Parkteam")
def test_context_auth_user_name_password(self): """Test authentication within context with username/password.""" with op.context(host=self.api_host) as ctx: ctx.auth(email='*****@*****.**', password='******', realm_id=1) self.assertEqual(ctx.me.user_name, 'August Admin') self.assertEqual(ctx.me.realm_id, 1) self.assertEqual(ctx.me.realm_name, 'grin') self.assertEqual(ctx.me.app_id, None) self.assertEqual(ctx.me.app_name, None)
def test_new_realm(self): """Test authentication within context with a newly created realm.""" new_realm = create_realm() self.assertEqual(type(new_realm['realm_id']), int) self.assertGreater(new_realm['realm_id'], 0) with op.context(host=self.api_host, api_key=new_realm['api_key']) as ctx: self.assertEqual(ctx.me.realm_id, new_realm['realm_id']) self.assertEqual(ctx.me.realm_name, new_realm['realm_name']) self.assertEqual(ctx.me.app_id, None) self.assertEqual(ctx.me.app_name, None)
def authenticate(self): """Authenticate as an app.""" with op.context(host=self.api_host) as ctx: ctx.auth(app_id=100, app_secret="app-secret-100") return ctx.auth_context.auth_token