Skip to content

Commit b255b6d

Browse files
committed
Make tests run in half the time
1 parent 0a2dcd4 commit b255b6d

File tree

5 files changed

+148
-125
lines changed

5 files changed

+148
-125
lines changed

docs/api.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
API
55
===
66

7-
.. module:: flask.ext.dynamo.manager
7+
.. module:: flask_dynamo.manager
88

99
This part of the documentation documents all the public classes, functions, and
1010
API details in flask-dynamo. This documentation is auto generated, and is
@@ -17,17 +17,26 @@ Configuration
1717
.. autoclass:: Dynamo
1818

1919
.. automethod:: init_app
20-
.. automethod:: init_settings
21-
.. automethod:: check_settings
2220
.. autoattribute:: connection
23-
.. autoattribute:: tables
21+
.. autoinstanceattribute:: DynamoLazyTables
22+
.. automethod:: get_table
23+
.. automethod:: create_all
24+
.. automethod:: destroy_all
25+
26+
.. autoclass:: DynamoLazyTables
27+
28+
.. automethod:: keys
29+
.. automethod:: len
30+
.. automethod:: items
31+
.. automethod:: wait_exists
32+
.. automethod:: wait_not_exists
2433
.. automethod:: create_all
2534
.. automethod:: destroy_all
2635

2736

2837
Errors
2938
------
3039

31-
.. module:: flask.ext.dynamo.errors
40+
.. module:: flask_dynamo.errors
3241

3342
.. autoclass:: ConfigurationError

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from os.path import abspath
1717
from sys import path
1818

19-
from flask.ext.dynamo import __version__ as version
19+
from flask_dynamo import __version__ as version
2020

2121

2222
# If extensions (or modules to document with autodoc) are in another directory,

docs/quickstart.rst

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. _quickstart:
2-
.. module:: flask.ext.dynamo
2+
.. module:: flask_dynamo
33

44

55
Quickstart
@@ -69,7 +69,7 @@ Below is an example::
6969
# app.py
7070

7171
from flask import Flask
72-
from flask.ext.dynamo import Dynamo
72+
from flask_dynamo import Dynamo
7373

7474
app = Flask(__name__)
7575
app.config['DYNAMO_TABLES'] = [
@@ -104,7 +104,7 @@ All you need to do is pass your app to the ``Dynamo`` constructor::
104104
# app.py
105105

106106
from flask import Flask
107-
from flask.ext.dynamo import Dynamo
107+
from flask_dynamo import Dynamo
108108

109109
app = Flask(__name__)
110110
app.config['DYNAMO_TABLES'] = [
@@ -123,8 +123,38 @@ All you need to do is pass your app to the ``Dynamo`` constructor::
123123

124124
dynamo = Dynamo(app)
125125

126+
If you use the app factory pattern then use::
127+
128+
# app.py
129+
130+
from flask import Flask
131+
from flask_dynamo import Dynamo
132+
133+
def create_app():
134+
app = Flask(__name__)
135+
app.config['DYNAMO_TABLES'] = [
136+
{
137+
TableName='users',
138+
KeySchema=[dict(AttributeName='username', KeyType='HASH')],
139+
AttributeDefinitions=[dict(AttributeName='username', AttributeType='S')],
140+
ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
141+
}, {
142+
TableName='groups',
143+
KeySchema=[dict(AttributeName='name', KeyType='HASH')],
144+
AttributeDefinitions=[dict(AttributeName='name', AttributeType='S')],
145+
ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
146+
}
147+
]
148+
dynamo = Dynamo()
149+
dynamo.init_app(app)
150+
return app
151+
152+
app = create_app()
153+
154+
126155
From this point on, you can interact with DynamoDB through the global ``dynamo``
127-
object.
156+
object, or through ``Flask.current_app.extensions['dynamodb']`` if you are
157+
using the Flask app factory pattern.
128158

129159

130160
Create Your Tables
@@ -145,44 +175,30 @@ This works great in bootstrap scripts.
145175
Working with Tables
146176
-------------------
147177

148-
Now that you've got everything setup, you can easily access your tables in one
149-
of two ways: you can either access the table directly from the ``dynamo``
150-
global, or you can access the table in a dictionary-like format through
151-
``dynamo.tables``.
178+
Now that you've got everything setup, you can easily access your tables
179+
in a dictionary-like format through ``dynamo.tables``.
152180

153181
Below is an example view which creates a new user account::
154182

155183
# app.py
156184

157185
@app.route('/create_user')
158186
def create_user():
159-
dynamo.users.put_item(data={
160-
'username': 'rdegges',
161-
'first_name': 'Randall',
162-
'last_name': 'Degges',
163-
'email': '[email protected]',
164-
})
165-
166-
# or ...
167-
168187
dynamo.tables['users'].put_item(data={
169188
'username': 'rdegges',
170189
'first_name': 'Randall',
171190
'last_name': 'Degges',
172191
'email': '[email protected]',
173192
})
174193

175-
Either of the above will work the same.
176-
177194
On a related note, you can also use the ``dynamo.tables`` dictionary to iterate
178195
through all of your tables (*this is sometimes useful*). Here's how you could
179196
iterate over your existing DynamoDB tables::
180197

181198
# app.py
182199

183-
with app.app_context():
184-
for table_name, table in dynamo.tables.iteritems():
185-
print table_name, table
200+
for table_name, table in dynamo.tables.items():
201+
print(table_name, table)
186202

187203

188204
Deleting Tables
@@ -195,8 +211,7 @@ The below code snippet will destroy all of your predefined DynamoDB tables::
195211

196212
# app.py
197213

198-
with app.app_context():
199-
dynamo.destroy_all()
214+
dynamo.destroy_all()
200215

201216
.. note::
202217
Please be *extremely* careful when running this -- it has the potential to

0 commit comments

Comments
 (0)