diff --git a/src/_secureaccesstokenauthorizer/model.py b/src/_secureaccesstokenauthorizer/model.py index fb259f1e4e4377a43a70c740ff87909ebb3d977d..867b7cbc21768908de493898749229499f17db4c 100644 --- a/src/_secureaccesstokenauthorizer/model.py +++ b/src/_secureaccesstokenauthorizer/model.py @@ -53,7 +53,7 @@ CONFIG_DB_NAME = u"privatestorageio-satauthz-v1.sqlite3" def open_and_initialize(path, required_schema_version, connect=None): """ - Open a SQLite3 database for use as a payment reference store. + Open a SQLite3 database for use as a voucher store. Create the database and populate it with a schema, if it does not already exist. @@ -110,7 +110,7 @@ def open_and_initialize(path, required_schema_version, connect=None): cursor.execute( """ - CREATE TABLE IF NOT EXISTS [payment-references] ( + CREATE TABLE IF NOT EXISTS [vouchers] ( [number] text, PRIMARY KEY([number]) @@ -136,12 +136,12 @@ def memory_connect(path, *a, **kw): @attr.s(frozen=True) -class PaymentReferenceStore(object): +class VoucherStore(object): """ - This class implements persistence for payment references. + This class implements persistence for vouchers. :ivar allmydata.node._Config node_config: The Tahoe-LAFS node configuration object for - the node that owns the persisted payment preferences. + the node that owns the persisted vouchers. """ database_path = attr.ib(type=FilePath) _connection = attr.ib() @@ -166,7 +166,7 @@ class PaymentReferenceStore(object): SELECT ([number]) FROM - [payment-references] + [vouchers] WHERE [number] = ? """, @@ -175,13 +175,13 @@ class PaymentReferenceStore(object): refs = cursor.fetchall() if len(refs) == 0: raise KeyError(prn) - return PaymentReference(refs[0][0]) + return Voucher(refs[0][0]) @with_cursor def add(self, cursor, prn): cursor.execute( """ - INSERT OR IGNORE INTO [payment-references] VALUES (?) + INSERT OR IGNORE INTO [vouchers] VALUES (?) """, (prn,) ) @@ -190,20 +190,20 @@ class PaymentReferenceStore(object): def list(self, cursor): cursor.execute( """ - SELECT ([number]) FROM [payment-references] + SELECT ([number]) FROM [vouchers] """, ) refs = cursor.fetchall() return list( - PaymentReference(number) + Voucher(number) for (number,) in refs ) @attr.s -class PaymentReference(object): +class Voucher(object): number = attr.ib() @classmethod diff --git a/src/_secureaccesstokenauthorizer/resource.py b/src/_secureaccesstokenauthorizer/resource.py index 3f40a45fb000e749a298e4064559a18300734708..d75666843cf0ae376177eccdbdf05339fd88c088 100644 --- a/src/_secureaccesstokenauthorizer/resource.py +++ b/src/_secureaccesstokenauthorizer/resource.py @@ -15,7 +15,7 @@ """ This module implements views (in the MVC sense) for the web interface for the client side of the storage plugin. This interface allows users to redeem -payment codes for fresh tokens. +vouchers for fresh tokens. In the future it should also allow users to read statistics about token usage. """ @@ -38,7 +38,7 @@ from ._base64 import ( ) from .model import ( - PaymentReferenceStore, + VoucherStore, ) from .controller import ( PaymentController, @@ -57,14 +57,14 @@ def from_configuration(node_config, store=None): This is also used to read and write files in the private storage area of the node's persistent state location. - :param PaymentReferenceStore store: The store to use. If ``None`` a - sensible one is constructed. + :param VoucherStore store: The store to use. If ``None`` a sensible one + is constructed. :return IResource: The root of the resource hierarchy presented by the client side of the plugin. """ if store is None: - store = PaymentReferenceStore.from_node_config(node_config) + store = VoucherStore.from_node_config(node_config) controller = PaymentController(store) root = Resource() root.putChild( @@ -124,10 +124,10 @@ class _VoucherCollection(Resource): if not is_syntactic_prn(prn): return bad_request() try: - payment_reference = self._store.get(prn) + voucher = self._store.get(prn) except KeyError: return NoResource() - return PaymentReferenceView(payment_reference) + return VoucherView(voucher) def is_syntactic_prn(prn): @@ -153,22 +153,22 @@ def is_syntactic_prn(prn): return True -class PaymentReferenceView(Resource): +class VoucherView(Resource): """ - This class implements a view for a ``PaymentReference`` instance. + This class implements a view for a ``Voucher`` instance. """ - def __init__(self, reference): + def __init__(self, voucher): """ - :param PaymentReference reference: The model object for which to provide a + :param Voucher reference: The model object for which to provide a view. """ - self._reference = reference + self._voucher = voucher Resource.__init__(self) def render_GET(self, request): request.responseHeaders.setRawHeaders(u"content-type", [u"application/json"]) - return self._reference.to_json() + return self._voucher.to_json() def bad_request(): diff --git a/src/_secureaccesstokenauthorizer/tests/test_client_resource.py b/src/_secureaccesstokenauthorizer/tests/test_client_resource.py index 1232479d894bd0d99db371b5e73883dbfca8bd8f..89af191bcfca56f01b5719b9cebf18adab191f74 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_client_resource.py +++ b/src/_secureaccesstokenauthorizer/tests/test_client_resource.py @@ -92,7 +92,7 @@ from treq.testing import ( ) from ..model import ( - PaymentReferenceStore, + VoucherStore, memory_connect, ) from ..resource import ( @@ -198,7 +198,7 @@ def root_from_config(config): """ return from_configuration( config, - PaymentReferenceStore.from_node_config( + VoucherStore.from_node_config( config, memory_connect, ), diff --git a/src/_secureaccesstokenauthorizer/tests/test_model.py b/src/_secureaccesstokenauthorizer/tests/test_model.py index cd427788cf49008caacf453b41d3fe8c638036d7..f8af40d578e1f8c257898539e0915b34e460a5b3 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_model.py +++ b/src/_secureaccesstokenauthorizer/tests/test_model.py @@ -55,8 +55,8 @@ from twisted.python.filepath import ( from ..model import ( SchemaError, StoreOpenError, - PaymentReferenceStore, - PaymentReference, + VoucherStore, + Voucher, open_and_initialize, memory_connect, ) @@ -67,9 +67,9 @@ from .strategies import ( ) -class PaymentReferenceStoreTests(TestCase): +class VoucherStoreTests(TestCase): """ - Tests for ``PaymentReferenceStore``. + Tests for ``VoucherStore``. """ def test_create_mismatched_schema(self): """ @@ -90,12 +90,12 @@ class PaymentReferenceStoreTests(TestCase): @given(tahoe_configs(), vouchers()) def test_get_missing(self, get_config, prn): """ - ``PaymentReferenceStore.get`` raises ``KeyError`` when called with a + ``VoucherStore.get`` raises ``KeyError`` when called with a voucher not previously added to the store. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"node"), b"tub.port") - store = PaymentReferenceStore.from_node_config( + store = VoucherStore.from_node_config( config, memory_connect, ) @@ -107,20 +107,19 @@ class PaymentReferenceStoreTests(TestCase): @given(tahoe_configs(), vouchers()) def test_add(self, get_config, prn): """ - ``PaymentReferenceStore.get`` returns a ``PaymentReference`` representing - a payment reference previously added to the store with - ``PaymentReferenceStore.add``. + ``VoucherStore.get`` returns a ``Voucher`` representing a voucher + previously added to the store with ``VoucherStore.add``. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"node"), b"tub.port") - store = PaymentReferenceStore.from_node_config( + store = VoucherStore.from_node_config( config, memory_connect, ) store.add(prn) - payment_reference = store.get(prn) + voucher = store.get(prn) self.assertThat( - payment_reference, + voucher, MatchesStructure( number=Equals(prn), ), @@ -129,20 +128,20 @@ class PaymentReferenceStoreTests(TestCase): @given(tahoe_configs(), vouchers()) def test_add_idempotent(self, get_config, prn): """ - More than one call to ``PaymentReferenceStore.add`` with the same argument - results in the same state as a single call. + More than one call to ``VoucherStore.add`` with the same argument results + in the same state as a single call. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"node"), b"tub.port") - store = PaymentReferenceStore.from_node_config( + store = VoucherStore.from_node_config( config, memory_connect, ) store.add(prn) store.add(prn) - payment_reference = store.get(prn) + voucher = store.get(prn) self.assertThat( - payment_reference, + voucher, MatchesStructure( number=Equals(prn), ), @@ -152,13 +151,13 @@ class PaymentReferenceStoreTests(TestCase): @given(tahoe_configs(), lists(vouchers())) def test_list(self, get_config, prns): """ - ``PaymentReferenceStore.list`` returns a ``list`` containing a - ``PaymentReference`` object for each voucher previously added. + ``VoucherStore.list`` returns a ``list`` containing a ``Voucher`` object + for each voucher previously added. """ tempdir = self.useFixture(TempDir()) nodedir = tempdir.join(b"node") config = get_config(nodedir, b"tub.port") - store = PaymentReferenceStore.from_node_config( + store = VoucherStore.from_node_config( config, memory_connect, ) @@ -179,8 +178,7 @@ class PaymentReferenceStoreTests(TestCase): def test_uncreateable_store_directory(self, get_config): """ If the underlying directory in the node configuration cannot be created - then ``PaymentReferenceStore.from_node_config`` raises - ``StoreOpenError``. + then ``VoucherStore.from_node_config`` raises ``StoreOpenError``. """ tempdir = self.useFixture(TempDir()) nodedir = tempdir.join(b"node") @@ -192,7 +190,7 @@ class PaymentReferenceStoreTests(TestCase): config = get_config(nodedir, b"tub.port") self.assertThat( - lambda: PaymentReferenceStore.from_node_config( + lambda: VoucherStore.from_node_config( config, memory_connect, ), @@ -219,7 +217,7 @@ class PaymentReferenceStoreTests(TestCase): def test_unopenable_store(self, get_config): """ If the underlying database file cannot be opened then - ``PaymentReferenceStore.from_node_config`` raises ``StoreOpenError``. + ``VoucherStore.from_node_config`` raises ``StoreOpenError``. """ tempdir = self.useFixture(TempDir()) nodedir = tempdir.join(b"node") @@ -227,30 +225,30 @@ class PaymentReferenceStoreTests(TestCase): config = get_config(nodedir, b"tub.port") # Create the underlying database file. - store = PaymentReferenceStore.from_node_config(config) + store = VoucherStore.from_node_config(config) # Prevent further access to it. store.database_path.chmod(0o000) self.assertThat( - lambda: PaymentReferenceStore.from_node_config( + lambda: VoucherStore.from_node_config( config, ), raises(StoreOpenError), ) -class PaymentReferenceTests(TestCase): +class VoucherTests(TestCase): """ - Tests for ``PaymentReference``. + Tests for ``Voucher``. """ @given(vouchers()) def test_json_roundtrip(self, prn): """ - ``PaymentReference.to_json . PaymentReference.from_json → id`` + ``Voucher.to_json . Voucher.from_json → id`` """ - ref = PaymentReference(prn) + ref = Voucher(prn) self.assertThat( - PaymentReference.from_json(ref.to_json()), + Voucher.from_json(ref.to_json()), Equals(ref), )