gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-donau] branch master updated: [testing] charity delete works & wo


From: gnunet
Subject: [taler-donau] branch master updated: [testing] charity delete works & work on charity post
Date: Tue, 05 Mar 2024 23:17:35 +0100

This is an automated email from the git hooks/post-receive script.

lukas-matyja pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new 767755a  [testing] charity delete works & work on charity post
     new a97ac26  Merge remote-tracking branch 'refs/remotes/origin/master'
767755a is described below

commit 767755a57b1b58653ebd6522fe4f380e49019471
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
AuthorDate: Tue Mar 5 23:17:13 2024 +0100

    [testing] charity delete works & work on charity post
---
 src/include/donau_service.h                  |   3 +-
 src/include/donau_testing_lib.h              |  29 +++-
 src/testing/Makefile.am                      |   4 +-
 src/testing/test_donau_api.c                 |  22 +++
 src/testing/testing_api_cmd_charity_delete.c | 168 +++++++++++++++++++++++
 src/testing/testing_api_cmd_charity_post.c   | 197 +++++++++++++++++++++++++++
 6 files changed, 418 insertions(+), 5 deletions(-)

diff --git a/src/include/donau_service.h b/src/include/donau_service.h
index 055bc92..c94b04f 100644
--- a/src/include/donau_service.h
+++ b/src/include/donau_service.h
@@ -1055,8 +1055,7 @@ struct DONAU_CharityRequest
   /**
    * public key of the charity
    */
-  struct DONAU_DonauPublicKeyP charity_pub;
-
+  struct DONAU_CharityPublicKeyP charity_pub;
 
   /**
    * current year
diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
index 7a4a18b..fe55c63 100644
--- a/src/include/donau_testing_lib.h
+++ b/src/include/donau_testing_lib.h
@@ -52,12 +52,11 @@ TALER_TESTING_cmd_get_donau (
   bool load_private_key);
 
 /**
- * Create a GET "charity" command with a @a timeout.
+ * Create a GET "charity" command.
  *
  * @param label the command label.
  * @param charity_id
  * @param bearer authorization token
- * @param timeout how long to long-poll for the charity to exist.
  * @param expected_response_code expected HTTP response code.
  * @return the command.
  */
@@ -67,6 +66,32 @@ TALER_TESTING_cmd_charity_get (const char *label,
                                                                const struct 
DONAU_BearerToken bearer,
                                 unsigned int expected_response_code);
 
+/**
+ * Create a POST "charity" command.
+ *
+ * @param label the command label.
+ * @param charity_id
+ * @param bearer authorization token
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_charity_post (const char *label,
+                                char charity_pub[256 / 8],
+                                char *name,
+                                char *url,
+                                char *max_per_year,
+                                char *receipts_to_date,
+                                uint64_t current_year, 
+                                                                               
const struct DONAU_BearerToken bearer,
+                                unsigned int expected_response_code);
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_charity_delete (const char *label,
+                                  const uint64_t charity_id,
+                                  const struct DONAU_BearerToken bearer,
+                                  unsigned int expected_response_code);
+
 /**
  * Create a GET "charities" command.
  *
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 415d4e2..5623c1c 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -21,8 +21,10 @@ libdonautesting_la_LDFLAGS = \
   -no-undefined
 libdonautesting_la_SOURCES = \
   testing_api_cmd_get_donau.c \
-  testing_api_cmd_charity_get.c \
   testing_api_cmd_charities_get.c \
+  testing_api_cmd_charity_get.c \
+  testing_api_cmd_charity_post.c \
+  testing_api_cmd_charity_delete.c \
   testing_api_traits.c \
   testing_api_loop.c
 
diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c
index 15f97d5..8d93527 100644
--- a/src/testing/test_donau_api.c
+++ b/src/testing/test_donau_api.c
@@ -66,6 +66,14 @@ run (void *cls,
 {
        struct DONAU_BearerToken bearer;
        bearer.token = NULL;
+//     struct DONAU_CharityRequest charity_req = {
+//       .charity_pub = 
{{"EBETNXT9ZF606FRF3WD5N6G2XVD5QHDP2PTQD4GSX4VEN2YYG2C0"}},
+//       .name = "example",
+//       .charity_url = "example.com",
+//       .max_per_year = {"EUR:10"},
+//       .receipts_to_date = {"EUR:0"},
+//       .current_year = 2024
+//     };
   {
     struct TALER_TESTING_Command commands[] = {
       TALER_TESTING_cmd_system_start ("start-donau",
@@ -76,12 +84,26 @@ run (void *cls,
 //                                      cred.cfg,
 //                                      true,
 //                                      true),
+//       TALER_TESTING_cmd_charity_post ("post-charity",
+//                                                                       
"EBETNXT9ZF606FRF3WD5N6G2XVD5QHDP2PTQD4GSX4VEN2YYG2C0",
+//                                                                       
"example",
+//                                                                       
"example.com",
+//                                                                       
"EUR:10", // max_per_year
+//                                                                       
"EUR:0", // receipts_to_date
+//                                                                       2024, 
// current year
+//                                                                       
bearer,
+//                                                                       
MHD_HTTP_NO_CONTENT),
       TALER_TESTING_cmd_charity_get ("get-charity-by-id",
                                                                  4,
                                                                          
bearer,
                                       MHD_HTTP_OK),
          TALER_TESTING_cmd_charities_get ("get-charities",
                                                                          
MHD_HTTP_OK),
+         TALER_TESTING_cmd_charity_delete("delete-charity",
+                                                                         4,
+                                                                         
bearer,
+                                                                         
MHD_HTTP_NO_CONTENT),
+
          //TODO: test POST charity, DELETE charity
       /* End the suite. */
       TALER_TESTING_cmd_end ()
diff --git a/src/testing/testing_api_cmd_charity_delete.c 
b/src/testing/testing_api_cmd_charity_delete.c
new file mode 100644
index 0000000..4d59b0b
--- /dev/null
+++ b/src/testing/testing_api_cmd_charity_delete.c
@@ -0,0 +1,168 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2024 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/testing_api_cmd_charity_delete.c
+ * @brief Implement the DELETE /charities test command.
+ * @author Lukas Matyja
+ */
+#include <taler/platform.h>
+#include <taler/taler_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_testing_lib.h>
+#include "donau_testing_lib.h"
+
+
+/**
+ * State for a "status" CMD.
+ */
+struct StatusState
+{
+  /**
+   * Handle to the "charity status" operation.
+   */
+  struct DONAU_CharityDeleteHandle *cgh;
+
+  /**
+   * The bearer token for authorization.
+   */
+  struct DONAU_BearerToken bearer;
+
+  /**
+   * The ID of the requested charity.
+   */
+  uint64_t charity_id;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int expected_response_code;
+
+  /**
+   * Interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param dcr HTTP response details
+ */
+static void
+charity_status_cb (void *cls,
+                   const struct DONAU_DeleteCharityResponse *dcr)
+{
+  struct StatusState *ss = cls;
+
+
+  ss->cgh = NULL;
+  if (ss->expected_response_code != dcr->hr.http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected HTTP response code: %d in %s:%u\n",
+                dcr->hr.http_status,
+                __FILE__,
+                __LINE__);
+    json_dumpf (dcr->hr.reply,
+                stderr,
+                0);
+    TALER_TESTING_interpreter_fail (ss->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (ss->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+status_run (void *cls,
+            const struct TALER_TESTING_Command *cmd,
+            struct TALER_TESTING_Interpreter *is)
+{
+  struct StatusState *ss = cls;
+
+  ss->is = is;
+
+  ss->cgh = DONAU_charity_delete (
+    TALER_TESTING_interpreter_get_context (is),
+       "http://localhost:8080/";, //TODO: TALER_TESTING_get_donau_url (is),
+    ss->charity_id,
+    ss->bearer,
+    &charity_status_cb,
+    ss);
+}
+
+/**
+ * Cleanup the state from a "reserve status" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+status_cleanup (void *cls,
+                const struct TALER_TESTING_Command *cmd)
+{
+  struct StatusState *ss = cls;
+
+  if (NULL != ss->cgh)
+  {
+       // log incomplete command
+       TALER_TESTING_command_incomplete (ss->is,
+                                                                          
cmd->label);
+    DONAU_charity_delete_cancel (ss->cgh);
+    ss->cgh = NULL;
+  }
+  GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_charity_delete (const char *label,
+                                                               const uint64_t 
charity_id,
+                                                               const struct 
DONAU_BearerToken bearer,
+                                unsigned int expected_response_code)
+{
+  struct StatusState *ss;
+
+  ss = GNUNET_new (struct StatusState);
+  ss->expected_response_code = expected_response_code;
+  ss->bearer = bearer;
+  ss->charity_id = charity_id;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ss,
+      .label = label,
+      .run = &status_run,
+      .cleanup = &status_cleanup
+    };
+
+    return cmd;
+  }
+}
diff --git a/src/testing/testing_api_cmd_charity_post.c 
b/src/testing/testing_api_cmd_charity_post.c
new file mode 100644
index 0000000..2518785
--- /dev/null
+++ b/src/testing/testing_api_cmd_charity_post.c
@@ -0,0 +1,197 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2024 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/testing_api_cmd_charity_post.c
+ * @brief Implement the POST /charities test command.
+ * @author Lukas Matyja
+ */
+#include <taler/platform.h>
+#include <taler/taler_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_testing_lib.h>
+#include "donau_testing_lib.h"
+
+
+/**
+ * State for a "status" CMD.
+ */
+struct StatusState
+{
+  /**
+   * Handle to the "charity status" operation.
+   */
+  struct DONAU_CharityPostHandle *cph;
+
+  /**
+   * The charity POST request.
+   */
+  struct DONAU_CharityRequest *charity_req;
+
+  /**
+   * The bearer token for authorization.
+   */
+  struct DONAU_BearerToken bearer;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int expected_response_code;
+
+  /**
+   * Interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param gcr HTTP response details
+ */
+static void
+charity_status_cb (void *cls,
+                   const struct DONAU_PostCharityResponse *gcr)
+{
+  struct StatusState *ss = cls;
+
+
+  ss->cph = NULL;
+  if (ss->expected_response_code != gcr->hr.http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected HTTP response code: %d in %s:%u\n",
+                gcr->hr.http_status,
+                __FILE__,
+                __LINE__);
+    json_dumpf (gcr->hr.reply,
+                stderr,
+                0);
+    TALER_TESTING_interpreter_fail (ss->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (ss->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+status_run (void *cls,
+            const struct TALER_TESTING_Command *cmd,
+            struct TALER_TESTING_Interpreter *is)
+{
+  struct StatusState *ss = cls;
+
+  ss->is = is;
+
+  ss->cph = DONAU_charity_post (
+    TALER_TESTING_interpreter_get_context (is),
+       "http://localhost:8080/";, //TODO: TALER_TESTING_get_donau_url (is),
+       ss->charity_req,
+    ss->bearer,
+    &charity_status_cb,
+    ss);
+}
+
+/**
+ * Cleanup the state from a "reserve status" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+status_cleanup (void *cls,
+                const struct TALER_TESTING_Command *cmd)
+{
+  struct StatusState *ss = cls;
+
+  if (NULL != ss->cph)
+  {
+       // log incomplete command
+       TALER_TESTING_command_incomplete (ss->is,
+                                                                          
cmd->label);
+    DONAU_charity_post_cancel (ss->cph);
+    ss->cph = NULL;
+  }
+  GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_charity_post (const char *label,
+        char charity_pub[256 / 8],
+        char *name,
+        char *url,
+        char *max_per_year,
+        char *receipts_to_date,
+        uint64_t current_year,
+               const struct DONAU_BearerToken bearer,
+        unsigned int expected_response_code)
+{
+  struct StatusState *ss;
+  ss = GNUNET_new (struct StatusState);
+  //memcpy(ss->charity_req->charity_pub.eddsa_pub.q_y, charity_pub, 
(256/8)*sizeof(char));
+  //ss->charity_req->name = GNUNET_strdup (name);
+  //ss->charity_req->charity_url = GNUNET_strdup (url);
+  // parse string max_per_year to amount
+//  if (GNUNET_OK !=
+//      TALER_string_to_amount (max_per_year,
+//                              &ss->charity_req->max_per_year))
+//  {
+//    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+//                "Failed to parse amount `%s' at %s\n",
+//                             max_per_year,
+//                label);
+//    GNUNET_assert (0);
+//  }
+  // parse string receipts_to_date to amount
+//  if (GNUNET_OK !=
+//      TALER_string_to_amount (receipts_to_date,
+//                              &ss->charity_req->receipts_to_date))
+//  {
+//    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+//                "Failed to parse amount `%s' at %s\n",
+//                             receipts_to_date,
+//                label);
+//    GNUNET_assert (0);
+//  }
+//  ss->charity_req->current_year = current_year;
+  ss->expected_response_code = expected_response_code;
+  ss->bearer = bearer;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ss,
+      .label = label,
+      .run = &status_run,
+      .cleanup = &status_cleanup
+    };
+
+    return cmd;
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]