gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: [lib][testing] finish charity get


From: gnunet
Subject: [taler-donau] branch master updated: [lib][testing] finish charity get
Date: Tue, 27 Feb 2024 15:33:43 +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 454a3fc  [lib][testing] finish charity get
454a3fc is described below

commit 454a3fc3011b9674f1d1817d8eac9b2b3b534ad3
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
AuthorDate: Tue Feb 27 15:34:12 2024 +0100

    [lib][testing] finish charity get
---
 src/include/donau_service.h               |  2 +-
 src/include/donau_testing_lib.h           | 19 ++++++++-
 src/lib/donau_api_charity_get.c           | 58 ++++++---------------------
 src/testing/test_donau_api.c              |  6 ++-
 src/testing/testing_api_cmd_charity_get.c | 65 ++++++++-----------------------
 src/testing/testing_api_traits.c          | 25 ++++++++++++
 6 files changed, 76 insertions(+), 99 deletions(-)

diff --git a/src/include/donau_service.h b/src/include/donau_service.h
index f3811af..ad1c2ac 100644
--- a/src/include/donau_service.h
+++ b/src/include/donau_service.h
@@ -969,7 +969,7 @@ struct DONAU_GetCharityResponse
       /**
        * Charity status information.
        */
-      struct DONAU_Charity *charity;
+      struct DONAU_Charity charity;
 
 
     } ok;
diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
index 5dce88e..da00bd6 100644
--- a/src/include/donau_testing_lib.h
+++ b/src/include/donau_testing_lib.h
@@ -55,13 +55,17 @@ TALER_TESTING_cmd_get_donau (
  * Create a GET "charity" command with a @a timeout.
  *
  * @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.
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charity_get (const char *label,
-                                struct GNUNET_TIME_Relative timeout,
+                                                               const uint64_t 
charity_id,
+                                                               const struct 
DONAU_BearerToken bearer,
+                                                               const struct 
GNUNET_TIME_Relative timeout,
                                 unsigned int expected_response_code);
 
   /**
@@ -83,6 +87,17 @@ DONAU_TESTING_main (char *const *argv,
                     TALER_TESTING_Main main_cb,
                     void *main_cb_cls);
 
+/* ****************** convenience functions ************** */
+
+/**
+ * Get donau URL from interpreter. Convenience function.
+ *
+ * @param is interpreter state.
+ * @return the donau URL, or NULL on error
+ */
+const char *
+TALER_TESTING_get_donau_url (
+  struct TALER_TESTING_Interpreter *is);
 
 /* ****** Specific traits supported by this component ******* */
 
@@ -105,4 +120,4 @@ DONAU_TESTING_main (char *const *argv,
 DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT)
 DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_DECL_INDEXED_TRAIT)
 
-#endif
\ No newline at end of file
+#endif
diff --git a/src/lib/donau_api_charity_get.c b/src/lib/donau_api_charity_get.c
index 2ccc7ab..f131832 100644
--- a/src/lib/donau_api_charity_get.c
+++ b/src/lib/donau_api_charity_get.c
@@ -73,10 +73,9 @@ struct DONAU_CharityGetHandle
 static enum GNUNET_GenericReturnValue
 handle_charity_get_ok (const json_t *resp_obj,
                        struct DONAU_CharityGetHandle *cgh,
-                                          struct DONAU_Charity *charity,
                                           struct DONAU_GetCharityResponse 
*gcresp)
 {
-  // const json_t *charity_hist_array;
+  struct DONAU_Charity *charity = &gcresp->details.ok.charity;
   const char *name;
   if (JSON_OBJECT != json_typeof (resp_obj))
   {
@@ -85,16 +84,16 @@ handle_charity_get_ok (const json_t *resp_obj,
   }
 
   struct GNUNET_JSON_Specification spec[] = {
-//    GNUNET_JSON_spec_fixed_auto ("charity_pub",
-//                                 &charity->charity_pub),
-//     GNUNET_JSON_spec_string ("name", &name),
-//    TALER_JSON_spec_amount_any ("max_per_year",
-//                                &charity->max_per_year),
-//    TALER_JSON_spec_amount_any ("receipts_to_date",
-//                                &charity->
-//                                receipts_to_date),
-//    GNUNET_JSON_spec_uint64 ("current_year",
-//                             &charity->current_year),
+    GNUNET_JSON_spec_fixed_auto ("charity_pub",
+                                 &charity->charity_pub),
+       GNUNET_JSON_spec_string ("name", &name),
+    TALER_JSON_spec_amount_any ("max_per_year",
+                                &charity->max_per_year),
+    TALER_JSON_spec_amount_any ("receipts_to_date",
+                                &charity->
+                                receipts_to_date),
+    GNUNET_JSON_spec_uint64 ("current_year",
+                             &charity->current_year),
     GNUNET_JSON_spec_end ()
   };
   if (GNUNET_OK !=
@@ -106,39 +105,7 @@ handle_charity_get_ok (const json_t *resp_obj,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  //charity->name = GNUNET_strdup (name);
-
-  /* parse the charity history data */
-  // charity_resp.details.ok.charity->num_hist
-  //   = json_array_size (charity_hist_array);
-  // if (0 != charity_resp.details.ok.charity->num_hist)
-  // {
-  //   json_t *charity_history_obj;
-  //   unsigned int index;
-
-  //   charity_resp.details.ok.charity->donation_history
-  //     = GNUNET_new_array (charity_resp.details.ok.charity->num_hist,
-  //                         struct DONAU_CharityHistoryYear);
-  //   json_array_foreach (charity_hist_array, index, charity_history_obj) {
-  //     struct DONAU_CharityHistoryYear *donation_history = 
&charity_resp.details.ok.charity->donation_history[index];
-  //     struct GNUNET_JSON_Specification history_spec[] = {
-  //       TALER_JSON_spec_amount_any ("final_amount",
-  //                                   &donation_history->final_amount),
-  //       GNUNET_JSON_spec_uint32 ("year",
-  //                               &donation_history->year),
-  //       GNUNET_JSON_spec_end ()
-  //     };
-
-  //     if (GNUNET_OK !=
-  //         GNUNET_JSON_parse (charity_history_obj,
-  //                           history_spec,
-  //                           NULL, NULL))
-  //     {
-  //       GNUNET_break_op (0);
-  //       return GNUNET_SYSERR;
-  //     }
-  //   }
-  // }
+  charity->name = GNUNET_strdup (name);
 
   cgh->cb (cgh->cb_cls,
            gcresp);
@@ -179,7 +146,6 @@ handle_charity_get_finished (void *cls,
     if (GNUNET_OK !=
         handle_charity_get_ok (j,
                                cgh,
-                                                          
&gcresp.details.ok.charity,
                                                           &gcresp))
     {
       gcresp.hr.http_status = 0;
diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c
index 028fa0d..1965d37 100644
--- a/src/testing/test_donau_api.c
+++ b/src/testing/test_donau_api.c
@@ -64,6 +64,8 @@ static void
 run (void *cls,
      struct TALER_TESTING_Interpreter *is)
 {
+       struct DONAU_BearerToken bearer;
+       bearer.token = NULL;
   {
     struct TALER_TESTING_Command commands[] = {
       TALER_TESTING_cmd_system_start ("start-donau",
@@ -74,7 +76,9 @@ run (void *cls,
 //                                      cred.cfg,
 //                                      true,
 //                                      true),
-      TALER_TESTING_cmd_charity_get ("get-charity-1",
+      TALER_TESTING_cmd_charity_get ("get-charity-by-id",
+                                                                 4,
+                                                                         
bearer,
                                                                  
GNUNET_TIME_relative_get_zero_ (),
                                       MHD_HTTP_OK),
          //TODO: test POST charity, GET charities, DELETE charity
diff --git a/src/testing/testing_api_cmd_charity_get.c 
b/src/testing/testing_api_cmd_charity_get.c
index fede656..7e18f3c 100644
--- a/src/testing/testing_api_cmd_charity_get.c
+++ b/src/testing/testing_api_cmd_charity_get.c
@@ -29,35 +29,6 @@
 #include "donau_testing_lib.h"
 
 
-/**
- * State for a "poll" CMD.
- */
-struct PollState
-{
-
-  /**
-   * How long do we give the exchange to respond?
-   */
-  struct GNUNET_TIME_Relative timeout;
-
-  /**
-   * Label to the command which created the reserve to check,
-   * needed to resort the reserve key.
-   */
-  const char *poll_reference;
-
-  /**
-   * Timeout to wait for at most.
-   */
-  //struct GNUNET_SCHEDULER_Task *tt;
-
-  /**
-   * The interpreter we are using.
-   */
-  struct TALER_TESTING_Interpreter *is;
-};
-
-
 /**
  * State for a "status" CMD.
  */
@@ -72,13 +43,7 @@ struct StatusState
   /**
    * Poller waiting for us.
    */
-  struct PollState *ps;
-
-  /**
-   * Label to the command which created the reserve to check,
-   * needed to resort the reserve key.
-   */
-  // const char *reserve_reference;
+//  struct PollState *ps;
 
   /**
    * Handle to the "charity status" operation.
@@ -86,14 +51,14 @@ struct StatusState
   struct DONAU_CharityGetHandle *cgh;
 
   /**
-   * Expected reserve balance.
+   * The bearer token for authorization.
    */
-  // const char *expected_balance;
+  struct DONAU_BearerToken bearer;
 
   /**
-   * Public key of the reserve being analyzed.
+   * The ID of the requested charity.
    */
-  // const struct TALER_ReservePublicKeyP *reserve_pubp;
+  uint64_t charity_id;
 
   /**
    * Expected HTTP response code.
@@ -156,17 +121,14 @@ status_run (void *cls,
             struct TALER_TESTING_Interpreter *is)
 {
   struct StatusState *ss = cls;
-  const char *donau_url = "http://localhost:8080/";;
 
   ss->is = is;
 
-  struct DONAU_BearerToken bearer;
-  bearer.token = NULL;
   ss->cgh = DONAU_charity_get (
     TALER_TESTING_interpreter_get_context (is),
-    donau_url,
-    4,
-    bearer,
+       "http://localhost:8080/";, //TODO: TALER_TESTING_get_donau_url (is),
+    ss->charity_id,
+    ss->bearer,
     ss->timeout,
     &charity_status_cb,
     ss);
@@ -192,8 +154,9 @@ status_cleanup (void *cls,
 
   if (NULL != ss->cgh)
   {
-    // TALER_TESTING_command_incomplete (ss->is,
-    //                                   cmd->label);
+       // log incomplete command
+       TALER_TESTING_command_incomplete (ss->is,
+                                                                          
cmd->label);
     DONAU_charity_get_cancel (ss->cgh);
     ss->cgh = NULL;
   }
@@ -203,7 +166,9 @@ status_cleanup (void *cls,
 
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charity_get (const char *label,
-                                struct GNUNET_TIME_Relative timeout,
+                                                               const uint64_t 
charity_id,
+                                                               const struct 
DONAU_BearerToken bearer,
+                                                               const struct 
GNUNET_TIME_Relative timeout,
                                 unsigned int expected_response_code)
 {
   struct StatusState *ss;
@@ -211,6 +176,8 @@ TALER_TESTING_cmd_charity_get (const char *label,
   ss = GNUNET_new (struct StatusState);
   ss->expected_response_code = expected_response_code;
   ss->timeout = timeout;
+  ss->bearer = bearer;
+  ss->charity_id = charity_id;
   {
     struct TALER_TESTING_Command cmd = {
       .cls = ss,
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index febea3a..bc6a598 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -30,5 +30,30 @@ DONAU_TESTING_SIMPLE_TRAITS 
(TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
 
 DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_IMPL_INDEXED_TRAIT)
 
+const char *
+TALER_TESTING_get_donau_url (struct TALER_TESTING_Interpreter *is)
+{
+  const char *donau_url;
+  const struct TALER_TESTING_Command *donau_cmd;
+
+  donau_cmd
+    = TALER_TESTING_interpreter_get_command (is,
+                                             "donau");
+  if (NULL == donau_cmd)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return NULL;
+  }
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_donau_url (donau_cmd,
+                                            &donau_url))
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return NULL;
+  }
+  return donau_url;
+}
 
 /* end of testing_api_traits.c */

-- 
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]