def modify(self, args, config, connection): if args['json'] is not None: amp = self._read(args['json']) else: amp = Amp() self._handle_args(amp, args) self._handle_properties(amp, args) amp.update(connection=connection)
def get(self, args, config, connection): amp = Amp() self._handle_args(amp, args) self._handle_properties(amp, args) if not amp.exists(connection=connection): print("Error: Amp does not exist: {0}".format(args['name'])) sys.exit(1) amp.read(connection=connection) self.jprint(amp)
def amp(self, local_name=None, namespace=None, document_uri=None, \ connection=None): """ Get a particular amp. """ if connection is None: amp = Amp.lookup(self.connection, local_name, namespace, document_uri) amp.set_connection(self.connection, self.save_connection) else: amp = Amp.lookup(connection, local_name, namespace, document_uri) return amp
def amps(self, connection=None): """ Get a list of amps. """ if connection is None: connection = self.connection return Amp.list(connection)
def create(self, args, config, connection): if args['json'] is not None: amp = self._read(args['json']) else: amp = Amp() self._handle_args(amp, args) self._handle_properties(amp, args) if amp.exists(connection=connection): print("Error: Amp already exists: {0}".format(amp.local_name())) sys.exit(1) amp.create(connection=connection) print("Created amp {}".format(amp.local_name()))
def delete(self, args, config, connection): amp = Amp() self._handle_args(amp, args) self._handle_properties(amp, args) amp.delete(connection=connection)
def list(self, args, config, connection): names = Amp.list(connection) print(json.dumps(names, sort_keys=True, indent=2))
def _read(self, jsonfile): jf = open(jsonfile).read() data = json.loads(jf) amp = Amp.unmarshal(data) return amp
def test_create_amp(self): beforeAmps = Amp.list(self.connection) amp = Amp("test-amp", "http://example.com", "/MarkLogic/test-amp.xqy", \ connection=self.connection) amp.create() afterAmps = Amp.list(self.connection) assert len(afterAmps) > len(beforeAmps) newAmp = Amp.lookup(self.connection, amp.local_name(), \ amp.namespace(), amp.document_uri()) assert isinstance(newAmp, Amp) for key in amp._config: assert newAmp._config[key] == amp._config[key] amp.set_role_names(["manage-admin"]) amp.update(connection=self.connection) newAmp.set_document_uri("/MarkLogic/no-can-do") try: newAmp.update(connection=self.connection) except UnexpectedManagementAPIResponse: pass except: raise amp.delete() afterAmps = Amp.list(self.connection) assert len(afterAmps) == len(beforeAmps) newAmp = Amp.lookup(self.connection, amp.local_name(), \ amp.namespace(), amp.document_uri()) assert newAmp is None
def test_list_amps(self): amps = Amp.list(self.connection) assert len(amps) > 100