Exemple #1
0
    def _patch_method(self,
                      endpoint,
                      patch,
                      safe=True,
                      if_match=None,
                      data=None,
                      permissions=None):
        """Utility method for implementing PATCH methods."""
        if not patch:
            # Backwards compatibility: the changes argument was
            # introduced in 9.1.0, and covers both ``data`` and
            # ``permissions`` arguments. Support the old style of
            # passing dicts by casting them into a BasicPatch.
            patch = BasicPatch(data=data, permissions=permissions)

        if not isinstance(patch, PatchType):
            raise TypeError("couldn't understand patch body {}".format(patch))

        body = patch.body
        content_type = patch.content_type
        headers = self._get_cache_headers(safe, if_match=if_match) or {}
        headers['Content-Type'] = content_type

        resp, _ = self.session.request('patch',
                                       endpoint,
                                       payload=body,
                                       headers=headers)
        return resp
Exemple #2
0
 def setUp(self):
     self.logger.info("Vérifications Kinto")
     client = kinto_http.Client(server_url=KINTO_SERVER,
                                auth=(KINTO_ADMIN_LOGIN,
                                      KINTO_ADMIN_PASSWORD))
     try:
         info = client.server_info()
     except ConnectionError as err:
         raise KintoImporterError(
             f"Connection au serveur Kinto impossible: {err}. Vérifiez la documentation pour paramétrer l'accès."
         )
     if "schema" not in info["capabilities"]:
         raise KintoImporterError(
             "Le serveur Kinto ne supporte pas la validation par schéma.")
     else:
         self.logger.success("Validation de schéma activée.")
     if self.truncate:
         if self.usePrompt and not prompt(
                 self.logger,
                 "Confimer la suppression et recréation de la collection existante ?",
                 "non"):
             raise KintoImporterError("Commande annulée.")
         self.logger.warn("Suppression de la collection Kinto existante...")
         client.delete_collection(id=KINTO_COLLECTION, bucket=KINTO_BUCKET)
         self.logger.success("La collection précédente a été supprimée.")
     try:
         coll = client.get_collection(id=KINTO_COLLECTION,
                                      bucket=KINTO_BUCKET)
         self.logger.success("La collection existe.")
     except KintoException as err:
         self.logger.warn("La collection n'existe pas, création")
         try:
             coll = client.create_collection(id=KINTO_COLLECTION,
                                             data={"schema": self.schema},
                                             bucket=KINTO_BUCKET)
             self.logger.success("La collection a été crée.")
         except KintoException as err:
             raise KintoImporterError(
                 f"Impossible de créer la collection {KINTO_BUCKET}/{KINTO_COLLECTION}: {err}"
             )
     if "schema" not in coll["data"]:
         self.logger.warn(
             "La collection ne possède pas schéma de validation JSON.")
         self.logger.info(
             f"Ajout du schéma à la collection {KINTO_COLLECTION}.")
         try:
             patch = BasicPatch(data={"schema": self.schema})
             client.patch_collection(id=KINTO_COLLECTION,
                                     bucket=KINTO_BUCKET,
                                     changes=patch)
             self.logger.info(
                 "Le schéma de validation JSON a été ajouté à la collection."
             )
         except (KintoException, TypeError, KeyError, ValueError) as err:
             raise KintoImporterError(
                 f"Impossible d'ajouter le schéma de validation à la collection {KINTO_COLLECTION}: {err}"
             )
     return client