class CharmPublisherTest(VCRTestCase): def _get_vcr_kwargs(self): """ This removes the authorization header from VCR so we don't record auth parameters """ return {"filter_headers": ["Authorization", "Macaroons"]} def setUp(self): self.client = CharmPublisher() return super().setUp() def test_get_macaroon(self): macaroon = self.client.get_macaroon() self.assertIsInstance(macaroon, str) def test_whoami(self): """ Check whoami response """ response = self.client.whoami(publisher_auth=publisher_auth) self.assertEqual(response["username"], "jkfran") def test_get_account_packages_all_charms(self): charms = self.client.get_account_packages( publisher_auth=publisher_auth, package_type="charm") for charm in charms: self.assertEqual(charm["type"], "charm") def test_get_account_packages_registered_charms(self): registered_charms = self.client.get_account_packages( publisher_auth=publisher_auth, package_type="charm", status="registered", ) for charm in registered_charms: self.assertEqual(charm["type"], "charm") self.assertEqual(charm["status"], "registered") def test_get_account_packages_published_charms(self): published_charms = self.client.get_account_packages( publisher_auth=publisher_auth, package_type="charm", status="published", ) for charm in published_charms: self.assertEqual(charm["type"], "charm") self.assertEqual(charm["status"], "published")
render_template, request, session, url_for, ) from webapp.config import DETAILS_VIEW_REGEX from webapp.decorators import login_required from webapp.helpers import get_licenses publisher = Blueprint( "publisher", __name__, template_folder="/templates", static_folder="/static", ) publisher_api = CharmPublisher(talisker.requests.get_session()) @publisher.route("/account/details") @login_required def get_account_details(): return render_template("publisher/account-details.html") @publisher.route("/charms") @publisher.route("/bundles") @login_required def list_page(): publisher_charms = publisher_api.get_account_packages( session["publisher-auth"], "charm", include_collaborations=True)
from webapp.helpers import is_safe_url from webapp import authentication login = flask.Blueprint( "login", __name__, template_folder="/templates", static_folder="/static" ) LOGIN_URL = os.getenv("LOGIN_URL", "https://login.ubuntu.com") LOGIN_LAUNCHPAD_TEAM = os.getenv( "LOGIN_LAUNCHPAD_TEAM", "canonical-webmonkeys" ) request_session = talisker.requests.get_session() candid = CandidClient(request_session) publisher_api = CharmPublisher(request_session) @login.route("/logout") def logout(): authentication.empty_session(flask.session) return flask.redirect("/") @login.route("/login/") def publisher_login(): # Get a bakery v2 macaroon from the publisher API to be discharged # and save it in the session flask.session["publisher-macaroon"] = publisher_api.get_macaroon() login_url = candid.get_login_url(
def setUp(self): self.client = CharmPublisher() return super().setUp()