Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def amps(self, connection=None):
        """
        Get a list of amps.
        """
        if connection is None:
            connection = self.connection

        return Amp.list(connection)
Exemplo n.º 5
0
    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()))
Exemplo n.º 6
0
    def delete(self, args, config, connection):
        amp = Amp()

        self._handle_args(amp, args)
        self._handle_properties(amp, args)
        amp.delete(connection=connection)
Exemplo n.º 7
0
 def list(self, args, config, connection):
     names = Amp.list(connection)
     print(json.dumps(names, sort_keys=True, indent=2))
Exemplo n.º 8
0
 def _read(self, jsonfile):
     jf = open(jsonfile).read()
     data = json.loads(jf)
     amp = Amp.unmarshal(data)
     return amp
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
 def test_list_amps(self):
     amps = Amp.list(self.connection)
     assert len(amps) > 100