From db5750c4ecad1cc050bdc7ee7bd66a00eced3a79 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Mon, 13 Apr 2020 09:39:34 -0400
Subject: [PATCH] Remove some duplication in token insertion implementations

---
 src/_zkapauthorizer/model.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/_zkapauthorizer/model.py b/src/_zkapauthorizer/model.py
index 3e6ac81..8615b43 100644
--- a/src/_zkapauthorizer/model.py
+++ b/src/_zkapauthorizer/model.py
@@ -308,13 +308,9 @@ class VoucherStore(object):
             in refs
         )
 
-    @with_cursor
-    def insert_unblinded_tokens(self, cursor, unblinded_tokens):
+    def _insert_unblinded_tokens(self, cursor, unblinded_tokens):
         """
-        Store some unblinded tokens, for example as part of a backup-restore
-        process.
-
-        :param list[unicode] unblinded_tokens: The unblinded tokens to store.
+        Helper function to really insert unblinded tokens into the database.
         """
         cursor.executemany(
             """
@@ -327,6 +323,16 @@ class VoucherStore(object):
             ),
         )
 
+    @with_cursor
+    def insert_unblinded_tokens(self, cursor, unblinded_tokens):
+        """
+        Store some unblinded tokens, for example as part of a backup-restore
+        process.
+
+        :param list[unicode] unblinded_tokens: The unblinded tokens to store.
+        """
+        self._insert_unblinded_tokens(cursor, unblinded_tokens)
+
     @with_cursor
     def insert_unblinded_tokens_for_voucher(self, cursor, voucher, public_key, unblinded_tokens):
         """
@@ -362,12 +368,10 @@ class VoucherStore(object):
         )
         if cursor.rowcount == 0:
             raise ValueError("Cannot insert tokens for unknown voucher; add voucher first")
-        cursor.executemany(
-            """
-            INSERT INTO [unblinded-tokens] VALUES (?)
-            """,
+        self._insert_unblinded_tokens(
+            cursor,
             list(
-                (t.unblinded_token,)
+                t.unblinded_token
                 for t
                 in unblinded_tokens
             ),
-- 
GitLab