def create(): """Create application.""" form = ApplicationForm() if form.validate_on_submit(): OAuthClient.create(user=current_user, name=form.name.data, desc=form.desc.data, website=form.website.data, redirect_uri=form.redirect_uri.data) flash(gettext('You have created an application!'), 'success') return redirect(url_for('.index')) return render_template('profile/applications/create.html', form=form)
def create(): """Create application.""" form = ApplicationForm() if form.validate_on_submit(): OAuthClient.create( user=current_user, name=form.name.data, desc=form.desc.data, website=form.website.data, redirect_uri=form.redirect_uri.data, ) flash(gettext("You have created an application!"), "success") return redirect(url_for(".index")) return render_template("profile/applications/create.html", form=form)
def create_dummy_client(self, user): client = OAuthClient.create( user=user, name="Dummy Client", desc="Created for testing the webservice", website="http://example.com/", redirect_uri="http://example.com/redirect/", ) return client
def test_delete(self): oauth_client = OAuthClient.create( user=self.user, name=u'Test App', desc=u'Application for testing.', website=u'https://example.com', redirect_uri=u'https://example.com/oauth', ) self.assertEqual(OAuthClient.query.count(), 1) oauth_client.delete() self.assertEqual(OAuthClient.query.count(), 0)
def test_create(self): self.assertEqual(OAuthClient.query.count(), 0) new_client = OAuthClient.create( user=self.user, name=u'Test App', desc=u'Application for testing.', website=u'https://example.com', redirect_uri=u'https://example.com/oauth', ) clients = OAuthClient.query.all() self.assertEqual(len(clients), 1) self.assertEqual(clients[0].name, u'Test App') self.assertEqual(len(clients[0].client_id), 20) self.assertEqual(len(clients[0].client_secret), 40)
def test_to_dict(self): oauth_client = OAuthClient.create( user=self.user, name=u'Test App', desc=u'Application for testing.', website=u'https://example.com', redirect_uri=u'https://example.com/oauth', ) self.assertDictEqual( oauth_client.to_dict(), { 'client_id': oauth_client.client_id, 'client_secret': oauth_client.client_secret, 'user_id': oauth_client.user_id, 'name': oauth_client.name, 'desc': oauth_client.desc, 'website': oauth_client.website, 'redirect_uri': oauth_client.redirect_uri, })
def test_to_dict(self): oauth_client = OAuthClient.create( user=self.user, name=u'Test App', desc=u'Application for testing.', website=u'https://example.com', redirect_uri=u'https://example.com/oauth', ) self.assertDictEqual( oauth_client.to_dict(), { 'client_id': oauth_client.client_id, 'client_secret': oauth_client.client_secret, 'user_id': oauth_client.user_id, 'name': oauth_client.name, 'desc': oauth_client.desc, 'website': oauth_client.website, 'redirect_uri': oauth_client.redirect_uri, } )
def test_update(self): oauth_client = OAuthClient.create( user=self.user, name=u'Test App', desc=u'Application for testing.', website=u'https://example.com', redirect_uri=u'https://example.com/oauth', ) oauth_client.update( name=u'Updated App', desc=u'Completely new app for testing.', website=u'https://example.org', redirect_uri=u'https://example.org/oauth', ) client = OAuthClient.query.all()[0] self.assertEqual(client.name, u'Updated App') self.assertEqual(client.desc, u'Completely new app for testing.') self.assertEqual(client.website, u'https://example.org') self.assertEqual(client.redirect_uri, u'https://example.org/oauth')
def create_dummy_application(self): return OAuthClient.create(user=self.user, **self.application)