def execute(self, args): manager = CDNManager(self.client) media_type = args.get('--type', 'http') if not media_type: media_type = 'http' manager.add_origin(args.get('<account>'), media_type, args.get('<url>'), args.get('--cname', None))
def execute(self, args): manager = CDNManager(self.client) origins = manager.get_origins(args.get('<account>')) table = Table(['id', 'media_type', 'cname', 'origin_url']) for origin in origins: table.add_row([origin['id'], origin['mediaType'], origin.get('cname', blank()), origin['originUrl']]) return table
def execute(self, args): manager = CDNManager(self.client) account = manager.get_account(args.get('<account>')) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' table.add_row(['id', account['id']]) table.add_row(['account_name', account['cdnAccountName']]) table.add_row(['type', account['cdnSolutionName']]) table.add_row(['status', account['status']['name']]) table.add_row(['created', account['createDate']]) table.add_row(['notes', account.get('cdnAccountNote', blank())]) return table
def execute(self, args): manager = CDNManager(self.client) accounts = manager.list_accounts() table = Table(['id', 'account_name', 'type', 'created', 'notes']) for account in accounts: table.add_row([ account['id'], account['cdnAccountName'], account['cdnSolutionName'], account['createDate'], account.get('cdnAccountNote', blank()) ]) table.sortby = args['--sortby'] return table
def setUp(self): self.client = FixtureClient() self.cdn_client = CDNManager(self.client)
class CDNTests(unittest.TestCase): def setUp(self): self.client = FixtureClient() self.cdn_client = CDNManager(self.client) def test_list_accounts(self): accounts = self.cdn_client.list_accounts() self.assertEqual(accounts, Account.getCdnAccounts) def test_get_account(self): account = self.cdn_client.get_account(12345) account_fixtures = self.client['Network_ContentDelivery_Account'].\ getObject(id=12345) self.assertEqual(account, account_fixtures) def test_get_origins(self): origins = self.cdn_client.get_origins(12345) origins_fixture = self.client['Network_ContentDelivery_Account'].\ getOriginPullMappingInformation(id=12345) self.assertEqual(origins, origins_fixture) def test_add_origin(self): account_id = 12345 media_type = 'http' origin_url = 'http://localhost/', cname = 'self.local' secure = False self.cdn_client.add_origin(account_id, media_type, origin_url, cname, secure) service = self.client['Network_ContentDelivery_Account'] service.createOriginPullMapping.assert_called_once_with({ 'mediaType': media_type, 'originUrl': origin_url, 'cname': cname, 'isSecureContent': secure}, id=account_id) def test_remove_origin(self): account_id = 12345 id = 12345 mcall = call(account_id, id=id) service = self.client['Network_ContentDelivery_Account'] self.cdn_client.remove_origin(account_id, id) service.deleteOriginPullRule.assert_has_calls(mcall) def test_load_content(self): account_id = 12345 urls = ['http://a/img/0x001.png', 'http://b/img/0x002.png', 'http://c/img/0x004.png', 'http://d/img/0x008.png', 'http://e/img/0x010.png', 'http://e/img/0x020.png'] self.cdn_client.load_content(account_id, urls) service = self.client['Network_ContentDelivery_Account'] self.assertEqual(service.loadContent.call_count, ceil(len(urls) / float(MAX_URLS_PER_LOAD))) def test_load_content_single(self): account_id = 12345 url = 'http://geocities.com/Area51/Meteor/12345/under_construction.gif' self.cdn_client.load_content(account_id, url) service = self.client['Network_ContentDelivery_Account'] service.loadContent.assert_called_once_with([url], id=account_id) def test_load_content_failure(self): account_id = 12345 urls = ['http://z/img/0x004.png', 'http://y/img/0x002.png', 'http://x/img/0x001.png'] service = self.client['Network_ContentDelivery_Account'] service.loadContent.return_value = False self.cdn_client.load_content(account_id, urls) self.assertEqual(service.loadContent.call_count, ceil(len(urls) / float(MAX_URLS_PER_LOAD))) def test_purge_content(self): account_id = 12345 urls = ['http://z/img/0x020.png', 'http://y/img/0x010.png', 'http://x/img/0x008.png', 'http://w/img/0x004.png', 'http://v/img/0x002.png', 'http://u/img/0x001.png'] self.cdn_client.purge_content(account_id, urls) service = self.client['Network_ContentDelivery_Account'] self.assertEqual(service.purgeContent.call_count, ceil(len(urls) / float(MAX_URLS_PER_PURGE))) def test_purge_content_failure(self): account_id = 12345 urls = ['http://z/img/0x004.png', 'http://y/img/0x002.png', 'http://x/img/0x001.png'] service = self.client['Network_ContentDelivery_Account'] service.purgeContent.return_value = False self.cdn_client.purge_content(account_id, urls) self.assertEqual(service.purgeContent.call_count, ceil(len(urls) / float(MAX_URLS_PER_PURGE))) def test_purge_content_single(self): account_id = 12345 url = 'http://geocities.com/Area51/Meteor/12345/under_construction.gif' service = self.client['Network_ContentDelivery_Account'] self.cdn_client.purge_content(account_id, url) service.purgeContent.assert_called_once_with([url], id=account_id)
def execute(self, args): manager = CDNManager(self.client) return str(manager.load_content(args.get('<account>'), args.get('<content_url>')))
def execute(self, args): manager = CDNManager(self.client) manager.remove_origin(args.get('<account>'), args.get('<origin_id>'))
def execute(self, args): manager = CDNManager(self.client) manager.purge_content(args.get('<account>'), args.get('<content_url>'))