aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2022-11-23 09:33:05 -0500
committerpriscilla <priscilla.huang@efrei.net>2022-11-23 09:33:05 -0500
commit7f1816686e8776f3228cc631c115490ed8028b8a (patch)
tree1882aa76fcc9b4159dc217d9e35614cc25fb1a95 /src
parent088ee12e5bddcf66c1a273995b2799227c73364f (diff)
test template
Diffstat (limited to 'src')
-rw-r--r--src/testing/Makefile.am3
-rw-r--r--src/testing/testing_api_cmd_delete_template.c180
-rw-r--r--src/testing/testing_api_cmd_get_template.c242
-rw-r--r--src/testing/testing_api_cmd_get_templates.c240
-rw-r--r--src/testing/testing_api_cmd_patch_template.c243
-rw-r--r--src/testing/testing_api_cmd_post_templates.c262
6 files changed, 1170 insertions, 0 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 20910048..827373e1 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -17,6 +17,7 @@ check_SCRIPTS = \
test_merchant_order_creation.sh \
test_merchant_transfer_tracking.sh
+
lib_LTLIBRARIES = \
libtalermerchanttesting.la
@@ -37,6 +38,7 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_get_reserves.c \
testing_api_cmd_get_tips.c \
testing_api_cmd_get_transfers.c \
+ testing_api_cmd_get_templates.c \
testing_api_cmd_delete_instance.c \
testing_api_cmd_delete_order.c \
testing_api_cmd_delete_product.c \
@@ -55,6 +57,7 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_post_products.c \
testing_api_cmd_post_reserves.c \
testing_api_cmd_post_transfers.c \
+ testing_api_cmd_post_templates.c \
testing_api_cmd_patch_instance.c \
testing_api_cmd_patch_product.c \
testing_api_cmd_refund_order.c \
diff --git a/src/testing/testing_api_cmd_delete_template.c b/src/testing/testing_api_cmd_delete_template.c
new file mode 100644
index 00000000..4ffe1dd8
--- /dev/null
+++ b/src/testing/testing_api_cmd_delete_template.c
@@ -0,0 +1,180 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_delete_template.c
+ * @brief command to test DELETE /templates/$ID
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "DELETE /templates/$ID" CMD.
+ */
+struct DeleteTemplateState
+{
+
+ /**
+ * Handle for a "DELETE template" request.
+ */
+ struct TALER_MERCHANT_TemplateDeleteHandle *tdh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the template to run DELETE for.
+ */
+ const char *template_id;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a /delete/templates/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+delete_template_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct DeleteTemplateState *dis = cls;
+
+ dis->tdh = NULL;
+ if (dis->http_status != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u (%d) to command %s\n",
+ hr->http_status,
+ (int) hr->ec,
+ TALER_TESTING_interpreter_get_current_label (dis->is));
+ TALER_TESTING_interpreter_fail (dis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for DELETE template.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (dis->is);
+}
+
+
+/**
+ * Run the "DELETE template" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+delete_template_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct DeleteTemplateState *dis = cls;
+
+ dis->is = is;
+ dis->tdh = TALER_MERCHANT_template_delete (is->ctx,
+ dis->merchant_url,
+ dis->template_id,
+ &delete_template_cb,
+ dis);
+ GNUNET_assert (NULL != dis->tdh);
+}
+
+
+/**
+ * Free the state of a "DELETE template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+delete_template_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct DeleteTemplateState *dis = cls;
+
+ if (NULL != dis->tdh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DELETE /templates/$ID operation did not complete\n");
+ TALER_MERCHANT_template_delete_cancel (dis->tdh);
+ }
+ GNUNET_free (dis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_delete_template (const char *label,
+ const char *merchant_url,
+ const char *template_id,
+ unsigned int http_status)
+{
+ struct DeleteTemplateState *dis;
+
+ dis = GNUNET_new (struct DeleteTemplateState);
+ dis->merchant_url = merchant_url;
+ dis->template_id = template_id;
+ dis->http_status = http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = dis,
+ .label = label,
+ .run = &delete_template_run,
+ .cleanup = &delete_template_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_delete_template.c */
diff --git a/src/testing/testing_api_cmd_get_template.c b/src/testing/testing_api_cmd_get_template.c
new file mode 100644
index 00000000..178503c7
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_template.c
@@ -0,0 +1,242 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_get_template.c
+ * @brief command to test GET /templates/$ID
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "GET template" CMD.
+ */
+struct GetTemplateState
+{
+
+ /**
+ * Handle for a "GET template request.
+ */
+ struct TALER_MERCHANT_TemplateGetHandle *igh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the template to run GET for.
+ */
+ const char *template_id;
+
+ /**
+ * Reference for a POST or PATCH /templates CMD (optional).
+ */
+ const char *template_reference;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a /get/templates/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr HTTP response details
+ * @param template_description description of the template
+ * @param image base64-encoded template image
+ * @param template_contract where the contract of the company is
+ */
+static void
+get_template_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ const char *template_description,
+ const char *image,
+ const json_t *template_contract)
+{
+ struct GetTemplateState *gis = cls;
+ const struct TALER_TESTING_Command *template_cmd;
+
+ gis->igh = NULL;
+ if (gis->http_status != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u (%d) to command %s\n",
+ hr->http_status,
+ (int) hr->ec,
+ TALER_TESTING_interpreter_get_current_label (gis->is));
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char **expected_description;
+
+ template_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->template_reference);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_template_description (template_cmd,
+ &expected_description))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (template_description,
+ *expected_description))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Template description does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char **expected_image;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_template_image (template_cmd,
+ &expected_image))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (image,
+ *expected_image))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Template image does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const json_t *expected_template_contract;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_template_contract (template_cmd,
+ &expected_template_contract))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (template_contract,
+ expected_template_contract))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Template contract does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status.\n");
+ }
+ TALER_TESTING_interpreter_next (gis->is);
+}
+
+
+/**
+ * Run the "GET template" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+get_template_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetTemplateState *gis = cls;
+
+ gis->is = is;
+ gis->igh = TALER_MERCHANT_template_get (is->ctx,
+ gis->merchant_url,
+ gis->template_id,
+ &get_template_cb,
+ gis);
+ GNUNET_assert (NULL != gis->igh);
+}
+
+
+/**
+ * Free the state of a "GET template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+get_template_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetTemplateState *gis = cls;
+
+ if (NULL != gis->igh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "GET /templates/$ID operation did not complete\n");
+ TALER_MERCHANT_template_get_cancel (gis->igh);
+ }
+ GNUNET_free (gis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_template (const char *label,
+ const char *merchant_url,
+ const char *template_id,
+ unsigned int http_status,
+ const char *template_reference)
+{
+ struct GetTemplateState *gis;
+
+ gis = GNUNET_new (struct GetTemplateState);
+ gis->merchant_url = merchant_url;
+ gis->template_id = template_id;
+ gis->http_status = http_status;
+ gis->template_reference = template_reference;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gis,
+ .label = label,
+ .run = &get_template_run,
+ .cleanup = &get_template_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_get_template.c */
diff --git a/src/testing/testing_api_cmd_get_templates.c b/src/testing/testing_api_cmd_get_templates.c
new file mode 100644
index 00000000..5c04859d
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_templates.c
@@ -0,0 +1,240 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_get_templates.c
+ * @brief command to test GET /templates
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "GET templates" CMD.
+ */
+struct GetTemplatesState
+{
+
+ /**
+ * Handle for a "GET template" request.
+ */
+ struct TALER_MERCHANT_TemplatesGetHandle *igh;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+ /**
+ * The list of template references.
+ */
+ const char **templates;
+
+ /**
+ * Length of @e templates.
+ */
+ unsigned int templates_length;
+
+};
+
+
+/**
+ * Callback for a GET /templates operation.
+ *
+ * @param cls closure for this function
+ * @param hr HTTP response details
+ * @param templates_length length of the @a templates array
+ * @param templates array of templates the requested instance offers
+ */
+static void
+get_templates_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ unsigned int templates_length,
+ const struct TALER_MERCHANT_TemplateEntry templates[])
+{
+ struct GetTemplatesState *gis = cls;
+
+ gis->igh = NULL;
+ if (gis->http_status != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u (%d) to command %s\n",
+ hr->http_status,
+ (int) hr->ec,
+ TALER_TESTING_interpreter_get_current_label (gis->is));
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_OK:
+ if (templates_length != gis->templates_length)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Length of templates found does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ for (unsigned int i = 0; i < gis->templates_length; ++i)
+ {
+ const struct TALER_TESTING_Command *template_cmd;
+
+ template_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->templates[i]);
+
+ {
+ const char **template_id;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_template_id (template_cmd,
+ &template_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not fetch template id\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ if (0 != strcmp (templates[i].template_id,
+ *template_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Template id does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ }
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* instance does not exist */
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u (%d).\n",
+ hr->http_status,
+ hr->ec);
+ }
+ TALER_TESTING_interpreter_next (gis->is);
+}
+
+
+/**
+ * Run the "GET /templates" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+get_templates_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetTemplatesState *gis = cls;
+
+ gis->is = is;
+ gis->igh = TALER_MERCHANT_templates_get (is->ctx,
+ gis->merchant_url,
+ &get_templates_cb,
+ gis);
+ GNUNET_assert (NULL != gis->igh);
+}
+
+
+/**
+ * Free the state of a "GET template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+get_templates_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetTemplatesState *gis = cls;
+
+ if (NULL != gis->igh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "GET /templates operation did not complete\n");
+ TALER_MERCHANT_templates_get_cancel (gis->igh);
+ }
+ GNUNET_array_grow (gis->templates,
+ gis->templates_length,
+ 0);
+ GNUNET_free (gis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_templates (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ ...)
+{
+ struct GetTemplatesState *gis;
+
+ gis = GNUNET_new (struct GetTemplatesState);
+ gis->merchant_url = merchant_url;
+ gis->http_status = http_status;
+ {
+ const char *clabel;
+ va_list ap;
+
+ va_start (ap, http_status);
+ while (NULL != (clabel = va_arg (ap, const char *)))
+ {
+ GNUNET_array_append (gis->templates,
+ gis->templates_length,
+ clabel);
+ }
+ va_end (ap);
+ }
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gis,
+ .label = label,
+ .run = &get_templates_run,
+ .cleanup = &get_templates_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_get_templates.c */
diff --git a/src/testing/testing_api_cmd_patch_template.c b/src/testing/testing_api_cmd_patch_template.c
new file mode 100644
index 00000000..7f8db916
--- /dev/null
+++ b/src/testing/testing_api_cmd_patch_template.c
@@ -0,0 +1,243 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_patch_template.c
+ * @brief command to test PATCH /template
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "PATCH /template" CMD.
+ */
+struct PatchTemplateState
+{
+
+ /**
+ * Handle for a "GET template" request.
+ */
+ struct TALER_MERCHANT_TemplatePatchHandle *iph;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the template to run GET for.
+ */
+ const char *template_id;
+
+ /**
+ * description of the template
+ */
+ const char *template_description;
+
+ /**
+ * base64-encoded template image
+ */
+ char *image;
+
+ /**
+ * Contract of the company
+ */
+ json_t *template_contract;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a PATCH /templates/$ID operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+patch_template_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct PatchTemplateState *pis = cls;
+
+ pis->iph = NULL;
+ if (pis->http_status != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u (%d) to command %s\n",
+ hr->http_status,
+ (int) hr->ec,
+ TALER_TESTING_interpreter_get_current_label (pis->is));
+ TALER_TESTING_interpreter_fail (pis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for PATCH /products/ID.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (pis->is);
+}
+
+
+/**
+ * Run the "PATCH /templates/$ID" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+patch_template_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PatchTemplateState *pis = cls;
+
+ pis->is = is;
+ pis->iph = TALER_MERCHANT_template_patch (is->ctx,
+ pis->merchant_url,
+ pis->template_id,
+ pis->template_description,
+ pis->image,
+ pis->template_contract,
+ &patch_template_cb,
+ pis);
+ GNUNET_assert (NULL != pis->iph);
+}
+
+
+/**
+ * Offers information from the PATCH /templates CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+patch_template_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PatchTemplateState *pts = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_template_description (&pts->template_description),
+ TALER_TESTING_make_trait_template_image (
+ (const char **) &pts->image),
+ TALER_TESTING_make_trait_template_contract (pts->template_contract),
+ TALER_TESTING_make_trait_template_id (&pts->template_id),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Free the state of a "GET template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+patch_template_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PatchTemplateState *pis = cls;
+
+ if (NULL != pis->iph)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "PATCH /templates/$ID operation did not complete\n");
+ TALER_MERCHANT_template_patch_cancel (pis->iph);
+ }
+ GNUNET_free (pis->image);
+ json_decref (pis->template_contract);
+ GNUNET_free (pis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_patch_template (
+ const char *label,
+ const char *merchant_url,
+ const char *template_id,
+ const char *template_description,
+ const char *image,
+ json_t *template_contract,
+ unsigned int http_status)
+{
+ struct PatchTemplateState *pis;
+
+ pis = GNUNET_new (struct PatchTemplateState);
+ pis->merchant_url = merchant_url;
+ pis->template_id = template_id;
+ pis->http_status = http_status;
+ pis->template_description = template_description;
+ pis->image = GNUNET_strdup (image);
+ pis->template_contract = template_contract; /* ownership taken */
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = pis,
+ .label = label,
+ .run = &patch_template_run,
+ .cleanup = &patch_template_cleanup,
+ .traits = &patch_template_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_patch_template.c */
diff --git a/src/testing/testing_api_cmd_post_templates.c b/src/testing/testing_api_cmd_post_templates.c
new file mode 100644
index 00000000..477fe958
--- /dev/null
+++ b/src/testing/testing_api_cmd_post_templates.c
@@ -0,0 +1,262 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_post_templates.c
+ * @brief command to test POST /templates
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "POST /templates" CMD.
+ */
+struct PostTemplatesState
+{
+
+ /**
+ * Handle for a "GET template" request.
+ */
+ struct TALER_MERCHANT_TemplatesPostHandle *iph;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Base URL of the merchant serving the request.
+ */
+ const char *merchant_url;
+
+ /**
+ * ID of the product to run POST for.
+ */
+ const char *template_id;
+
+ /**
+ * description of the template
+ */
+ const char *template_description;
+
+ /**
+ * base64-encoded product image
+ */
+ char *image;
+
+ /**
+ * Contract of the company
+ */
+ json_t *template_contract;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a POST /templates operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+post_templates_cb (void *cls,
+ const struct TALER_MERCHANT_HttpResponse *hr)
+{
+ struct PostTemplatesState *tis = cls;
+
+ tis->iph = NULL;
+ if (tis->http_status != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u (%d) to command %s\n",
+ hr->http_status,
+ (int) hr->ec,
+ TALER_TESTING_interpreter_get_current_label (tis->is));
+ TALER_TESTING_interpreter_fail (tis->is);
+ return;
+ }
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ break;
+ case MHD_HTTP_CONFLICT:
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unhandled HTTP status %u for POST /templates.\n",
+ hr->http_status);
+ }
+ TALER_TESTING_interpreter_next (tis->is);
+}
+
+
+/**
+ * Run the "POST /templates" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+post_templates_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PostTemplatesState *tis = cls;
+
+ tis->is = is;
+ tis->iph = TALER_MERCHANT_templates_post (is->ctx,
+ tis->merchant_url,
+ tis->template_id,
+ tis->template_description,
+ tis->image,
+ tis->template_contract,
+ &post_templates_cb,
+ tis);
+ GNUNET_assert (NULL != tis->iph);
+}
+
+
+/**
+ * Offers information from the POST /templates CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+post_templates_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PostTemplatesState *pts = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_template_description (&pts->template_description),
+ TALER_TESTING_make_trait_template_image (
+ (const char **) &pts->image),
+ TALER_TESTING_make_trait_template_contract (pts->template_contract),
+ TALER_TESTING_make_trait_template_id (&pts->template_id),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Free the state of a "POST template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+post_templates_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PostTemplatesState *tis = cls;
+
+ if (NULL != tis->iph)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "POST /templates operation did not complete\n");
+ TALER_MERCHANT_templates_post_cancel (tis->iph);
+ }
+ GNUNET_free (tis->image);
+ json_decref (tis->template_contract);
+ GNUNET_free (tis);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_templates2 (
+ const char *label,
+ const char *merchant_url,
+ const char *template_id,
+ const char *template_description,
+ const char *image,
+ json_t *template_contract,
+ unsigned int http_status)
+{
+ struct PostTemplatesState *tis;
+
+ tis = GNUNET_new (struct PostTemplatesState);
+ tis->merchant_url = merchant_url;
+ tis->template_id = template_id;
+ tis->http_status = http_status;
+ tis->template_description = template_description;
+ tis->image = GNUNET_strdup (image);
+ tis->template_contract = template_contract;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = tis,
+ .label = label,
+ .run = &post_templates_run,
+ .cleanup = &post_templates_cleanup,
+ .traits = &post_templates_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_templates (const char *label,
+ const char *merchant_url,
+ const char *template_id,
+ const char *template_description,
+ unsigned int http_status)
+{
+ return TALER_TESTING_cmd_merchant_post_templates2 (
+ label,
+ merchant_url,
+ template_id,
+ template_description,
+ "",
+ json_pack ("merchant 1", "5e", "minimum 10"),
+ http_status);
+}
+
+
+/* end of testing_api_cmd_post_templates.c */