def make_proxy(options=None): """ Usage:: hammer proxy create [OPTIONS] Options:: --name NAME --url URL """ args = { u'name': generate_name(), } args = update_dictionary(args, options) if options and 'url' in options: args.update(create_object(Proxy, args)) else: newport = random.randint(9191, 49090) with default_url_on_new_port(9090, newport) as url: args['url'] = url args.update(create_object(Proxy, args)) return args
def make_proxy(options=None): """ Usage:: hammer proxy create [OPTIONS] Options:: --name NAME --url URL """ args = {u"name": generate_name()} args = update_dictionary(args, options) if options and "url" in options: args.update(create_object(Proxy, args)) else: newport = random.randint(9191, 49090) try: with default_url_on_new_port(9090, newport) as url: args["url"] = url args.update(create_object(Proxy, args)) except SSHTunnelError as err: raise CLIFactoryError("Failed to create ssh tunnel: {0}".format(err)) return args
def test_proxy_update(self, data): """@Test: Proxy name update with the home proxy @Feature: Smart Proxy @Assert: Proxy has the name updated """ try: proxy = make_proxy({u'name': data['name']}) except CLIFactoryError as err: self.fail(err) self.assertEquals(proxy['name'], data['name'], "Input and output name should be consistent") with default_url_on_new_port(9090, random.randint(9091, 49090)) as url: result = Proxy.update({ u'id': proxy['id'], u'name': data['update'], u'url': url }) self.assertEqual(result.return_code, 0, "Proxy should be updated") result = Proxy.info({u'id': proxy['id']}) self.assertEqual(result.return_code, 0, "Proxy should be found") self.assertEqual(result.stdout['name'], data['update'], "Proxy name should be updated")
def test_positive_refresh_features_by_id(self): """Refresh smart proxy features, search for proxy by id @Feature: Smart Proxy @Assert: Proxy features are refreshed """ proxy = make_proxy() # parse the port number so we can reopen the SSH tunnel port_regexp = re.search(u':([0-9]+)', proxy['url']) if port_regexp: port = port_regexp.group(1) with default_url_on_new_port(9090, port): Proxy.refresh_features({u'id': proxy['id']}) else: raise ValueError('Unable to parse port number from proxy URL')
def test_positive_update_name(self): """Proxy name update with the home proxy @Feature: Smart Proxy @Assert: Proxy has the name updated """ proxy = make_proxy({u'name': gen_alphanumeric()}) newport = random.randint(9091, 49090) for new_name in valid_data_list(): with self.subTest(new_name): with default_url_on_new_port(9090, newport) as url: Proxy.update({ u'id': proxy['id'], u'name': new_name, u'url': url, }) proxy = Proxy.info({u'id': proxy['id']}) self.assertEqual(proxy['name'], new_name)
def test_proxy_update(self, data): """@Test: Proxy name update with the home proxy @Feature: Smart Proxy @Assert: Proxy has the name updated """ try: proxy = make_proxy({u'name': data['name']}) except CLIFactoryError as err: self.fail(err) self.assertEquals( proxy['name'], data['name'], "Input and output name should be consistent") with default_url_on_new_port(9090, random.randint(9091, 49090)) as url: result = Proxy.update({ u'id': proxy['id'], u'name': data['update'], u'url': url}) self.assertEqual( result.return_code, 0, "Proxy should be updated" ) result = Proxy.info({u'id': proxy['id']}) self.assertEqual( result.return_code, 0, "Proxy should be found" ) self.assertEqual( result.stdout['name'], data['update'], "Proxy name should be updated" )