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
3c3d5260
Commit
3c3d5260
authored
Aug 31, 2011
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
argument tests
parent
3424e38d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
8 deletions
+115
-8
README.md
README.md
+21
-0
arguments.py
corepost/test/arguments.py
+17
-0
arguments.feature
corepost/test/feature/arguments.feature
+32
-0
steps.py
corepost/test/steps.py
+2
-1
setup.py
setup.py
+43
-7
No files found.
README.md
View file @
3c3d5260
...
@@ -12,6 +12,8 @@ Single REST module example
...
@@ -12,6 +12,8 @@ Single REST module example
The simplest possible REST application:
The simplest possible REST application:
::
from corepost.web import CorePost
from corepost.web import CorePost
from corepost.enums import Http
from corepost.enums import Http
...
@@ -41,6 +43,8 @@ The key CorePost object is just an extension of the regular twisted.web Resource
...
@@ -41,6 +43,8 @@ The key CorePost object is just an extension of the regular twisted.web Resource
Therefore, it can easily be used to assemble a multi-module REST applications with
Therefore, it can easily be used to assemble a multi-module REST applications with
different CorePost resources serving from different context paths:
different CorePost resources serving from different context paths:
::
from corepost.web import CorePost
from corepost.web import CorePost
from corepost.enums import Http
from corepost.enums import Http
from twisted.web.resource import Resource
from twisted.web.resource import Resource
...
@@ -97,6 +101,23 @@ The example above creates 3 modules ("/","module1","/module2") and exposes the f
...
@@ -97,6 +101,23 @@ The example above creates 3 modules ("/","module1","/module2") and exposes the f
http://127.0.0.1:8080/module2/
http://127.0.0.1:8080/module2/
http://127.0.0.1:8080/module2/sub
http://127.0.0.1:8080/module2/sub
Path argument extraction
------------------------
CorePort can easily extract path arguments from an URL and convert them to the desired type.
The supported types are:
*
*int*
, e.g. '
<int:some
_int_arg
>
'
*
*float*
, e.g. '
<int:some
_float_arg
>
'
*
*string*
, e.g. '
<string
_arg
>
'
Example:
::
@app.route("/int/<int:intarg>/float/<float:floatarg>/string/<stringarg>",Http.GET)
def test(request,intarg,floatarg,stringarg,**kwargs):
pass
@defer.inlineCallbacks support
@defer.inlineCallbacks support
------------------------------
------------------------------
...
...
corepost/test/arguments.py
0 → 100644
View file @
3c3d5260
'''
Argument extraction tests
@author: jacekf
'''
from
corepost.web
import
CorePost
from
corepost.enums
import
Http
app
=
CorePost
()
@
app
.
route
(
"/int/<int:intarg>/float/<float:floatarg>/string/<stringarg>"
,
Http
.
GET
)
def
test
(
request
,
intarg
,
floatarg
,
stringarg
,
**
kwargs
):
args
=
(
intarg
,
floatarg
,
stringarg
)
return
"
%
s"
%
map
(
lambda
x
:
(
type
(
x
),
x
),
args
)
def
run_app_arguments
():
app
.
run
(
8082
)
\ No newline at end of file
corepost/test/feature/arguments.feature
0 → 100644
View file @
3c3d5260
Using step definitions from
:
'../steps'
@arguments
Feature
:
Arguments
CorePost should be able to correctly extract arguments
from paths, query arguments and form arguments
@path_arguments
Scenario Outline
:
Path argument extraction
Given 'arguments' is running
When as user 'None
:
None' I GET 'http
:
//127.0.0.1
:
8082<url>'
Then
I expect HTTP code
<code>
And
I expect content contains '<content>'
Examples
:
|
url
|
code
|
content
|
|
/int/1/float/1.1/string/TEST
|
200
|
[(<type
'int'>,
1),
(<type
'float'>,
1.1),
(<type
'str'>,
'TEST')]
|
|
/int/1/float/1/string/TEST
|
200
|
[(<type
'int'>,
1),
(<type
'float'>,
1.0),
(<type
'str'>,
'TEST')]
|
|
/int/1/float/1/string/23
|
200
|
[(<type
'int'>,
1),
(<type
'float'>,
1.0),
(<type
'str'>,
'23')]
|
@path_arguments
Scenario Outline
:
Path argument extraction - error handling
Given 'arguments' is running
When as user 'None
:
None' I GET 'http
:
//127.0.0.1
:
8082<url>'
Then
I expect HTTP code
<code>
And
I expect content contains '<content>'
Examples
:
|
url
|
code
|
content
|
|
/int/WRONG/float/1.1/string/TEST
|
404
|
URL
'/int/WRONG/float/1.1/string/TEST'
not
found
|
|
/int/1/float/WRONG/string/TEST
|
404
|
URL
'/int/1/float/WRONG/string/TEST'
not
found
|
|
\ No newline at end of file
corepost/test/steps.py
View file @
3c3d5260
...
@@ -9,8 +9,9 @@ from freshen import Before, After, Given, When, Then, scc, glc, assert_equals, a
...
@@ -9,8 +9,9 @@ from freshen import Before, After, Given, When, Then, scc, glc, assert_equals, a
from
urllib
import
urlencode
from
urllib
import
urlencode
from
corepost.test.home_resource
import
run_app_home
from
corepost.test.home_resource
import
run_app_home
from
corepost.test.multi_resource
import
run_app_multi
from
corepost.test.multi_resource
import
run_app_multi
from
corepost.test.arguments
import
run_app_arguments
apps
=
{
'home_resource'
:
run_app_home
,
'multi_resource'
:
run_app_multi
}
apps
=
{
'home_resource'
:
run_app_home
,
'multi_resource'
:
run_app_multi
,
'arguments'
:
run_app_arguments
}
def
as_dict
(
parameters
):
def
as_dict
(
parameters
):
dict_val
=
{}
dict_val
=
{}
...
...
setup.py
View file @
3c3d5260
'''
"""
Created on 2011-08-25
Twisted REST micro-framework
================================
@author: jacekf
Based on *Flask* API, with integrated multiprocessing support for full usage of all CPUs.
'''
Provides a more Flask/Sinatra-style API on top of the core *twisted.web* APIs.
The simplest possible twisted.web CorePost REST application:
::
from corepost.web import CorePost
from corepost.enums import Http
app = CorePost()
@app.route("/",Http.GET)
def root(request,**kwargs):
return request.path
@app.route("/test",Http.GET)
def test(request,**kwargs):
return request.path
@app.route("/test/<int:numericid>",Http.GET)
def test_get_resources(request,numericid,**kwargs):
return "
%
s"
%
numericid
if __name__ == '__main__':
app.run()
Links
`````
* `website <http://github.com/jacek99/corepost>`_
* `Twisted <http://twistedmatrix.com>`_
"""
import
os
import
os
from
setuptools
import
setup
from
setuptools
import
setup
import
markdown
# Utility function to read the README file.
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
# string in below ...
def
read
(
fname
):
def
read
(
fname
):
return
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
fname
))
.
read
()
md
=
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
fname
))
.
read
()
return
md
#return "<html>%s<html>" % markdown.markdown(md)
setup
(
setup
(
name
=
"CorePost"
,
name
=
"CorePost"
,
version
=
"0.0.3"
,
version
=
"0.0.3"
,
...
@@ -24,7 +60,7 @@ setup(
...
@@ -24,7 +60,7 @@ setup(
keywords
=
"twisted rest flask sinatra get post put delete web"
,
keywords
=
"twisted rest flask sinatra get post put delete web"
,
url
=
"https://github.com/jacek99/corepost"
,
url
=
"https://github.com/jacek99/corepost"
,
packages
=
[
'corepost'
,
],
packages
=
[
'corepost'
,
],
long_description
=
read
(
'README.md'
)
,
long_description
=
__doc__
,
classifiers
=
[
classifiers
=
[
"Development Status :: 3 - Alpha"
,
"Development Status :: 3 - Alpha"
,
"Environment :: Web Environment"
,
"Environment :: Web Environment"
,
...
...
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