Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
2cb1544c
Commit
2cb1544c
authored
Mar 21, 2012
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on test case for SQL Alchemy integration
parent
b91d5d78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
3 deletions
+82
-3
sqlalchemy_resource.py
corepost/test/sqlalchemy_resource.py
+82
-3
No files found.
corepost/test/sqlalchemy_resource.py
View file @
2cb1544c
...
...
@@ -8,8 +8,20 @@ from corepost.web import RESTResource, route, Http
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
,
ForeignKey
from
sqlalchemy.orm
import
relationship
,
backref
from
sqlalchemy.orm
import
relationship
,
backref
,
Session
# support different sessions for read/writes for master/read slave configuration
class
WriteSession
(
Session
):
"""SQL Alchemy session for writes (to master)"""
def
__init__
(
self
):
Session
.
__init__
(
self
)
class
ReadSession
(
Session
):
"""SQL Alchemy session for reads (from read slaves)"""
def
__init__
(
self
):
Session
.
__init__
(
self
)
# SQL Alchemy entities
Base
=
declarative_base
()
class
Customer
(
Base
):
...
...
@@ -36,9 +48,76 @@ class CustomerAddress(Base):
def
__init__
(
self
,
addressLine1
,
addressLine2
,
city
,
stateCode
,
countryCode
):
(
self
.
addressLine1
,
self
.
addressLine2
,
self
.
city
,
self
.
stateCode
,
self
.
countryCode
)
=
(
addressLine1
,
addressLine2
,
city
,
stateCode
,
countryCode
)
class
CustomerDAO
:
"""SQLAlchemy DAO that uses blocking I/O. Needs to always be run in defer.deferToThread()"""
def
findById
(
self
,
customerId
):
pass
def
save
(
self
,
customer
):
pass
def
merge
(
self
,
customer
):
pass
def
delete
(
self
,
customer
):
pass
# REST services
class
CustomerREST
:
"""Customer REST service"""
path
=
"/customer"
@
route
(
"/"
,
Http
.
GET
)
def
getAll
(
self
,
request
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
GET
)
def
get
(
self
,
request
,
customerId
,
**
kwargs
):
pass
@
route
(
"/"
,
Http
.
POST
)
def
post
(
self
,
request
,
customerId
,
firstName
,
middleName
=
None
,
lastName
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
PUT
)
def
put
(
self
,
request
,
customerId
,
firstName
=
None
,
middleName
=
None
,
lastName
=
None
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
DELETE
)
def
delete
(
self
,
request
,
customerId
,
**
kwargs
):
pass
class
CustomerAddressREST
:
"""Customer Address REST service"""
path
=
"/customer/<customerId>/address"
@
route
(
"/"
,
Http
.
GET
)
def
getAll
(
self
,
request
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
GET
)
def
get
(
self
,
request
,
customerId
,
addressId
,
**
kwargs
):
pass
@
route
(
"/"
,
Http
.
POST
)
def
post
(
self
,
request
,
customerId
,
addressId
,
addressLine1
,
addressLine2
=
None
,
city
,
stateCode
,
countryCode
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
PUT
)
def
put
(
self
,
request
,
customerId
,
self
,
request
,
customerId
,
addressId
,
addressLine1
=
None
,
addressLine2
=
None
,
city
=
None
,
stateCode
=
None
,
countryCode
=
None
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
DELETE
)
def
delete
(
self
,
request
,
customerId
,
addressId
,
**
kwargs
):
pass
def
run_sqlalchemy_app
():
app
=
RESTResource
((
CustomerREST
Service
(),
CustomerAddressRESTService
()))
app
=
RESTResource
((
CustomerREST
(),
CustomerAddressREST
()))
app
.
run
(
8086
)
pass
if
__name__
==
"__main__"
:
run_rest_app
()
\ No newline at end of file
run_sqlalchemy_app
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment