Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flaskdav
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
flaskdav
Commits
353189e1
Commit
353189e1
authored
Jan 20, 2016
by
iv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test file, first tests, clean some code.
parent
1a08344c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
6 deletions
+100
-6
flaskdav.py
flaskdav.py
+10
-6
tests.py
tests.py
+90
-0
No files found.
flaskdav.py
View file @
353189e1
...
...
@@ -362,12 +362,16 @@ class WebDAV(MethodView):
return
make_response
(
''
,
g
.
status
,
g
.
headers
)
webdav_view
=
WebDAV
.
as_view
(
'dav'
)
app
.
add_url_rule
(
'/webdav/'
,
defaults
=
{
'pathname'
:
''
},
view_func
=
webdav_view
)
app
.
add_url_rule
(
URI_BEGINNING_PATH
[
'webdav'
]
+
'<path:pathname>'
,
view_func
=
webdav_view
)
app
.
add_url_rule
(
'/webdav/'
,
defaults
=
{
'pathname'
:
''
},
view_func
=
webdav_view
)
app
.
add_url_rule
(
URI_BEGINNING_PATH
[
'webdav'
]
+
'<path:pathname>'
,
view_func
=
webdav_view
)
@
app
.
route
(
URI_BEGINNING_PATH
[
'authorization'
],
methods
=
[
'GET'
,
'POST'
])
...
...
tests.py
0 → 100644
View file @
353189e1
import
unittest
import
flaskdav
import
utils
import
tempfile
import
shutil
class
FlaskdavTestCase
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
self
):
'''
create temporary dir and files, and flaskdav test instance
'''
self
.
app
=
flaskdav
.
app
self
.
app
.
fs_path
=
tempfile
.
mkdtemp
()
f
=
open
(
self
.
app
.
fs_path
+
'/file.txt'
,
'w'
)
f
.
write
(
'pouet'
)
f
.
close
()
f
=
open
(
self
.
app
.
fs_path
+
'/file.js'
,
'w'
)
f
.
close
()
f
=
open
(
self
.
app
.
fs_path
+
'/file.png'
,
'w'
)
f
.
close
()
self
.
app
.
fs_handler
=
utils
.
FilesystemHandler
(
self
.
app
.
fs_path
,
'/webdav/'
)
self
.
server
=
self
.
app
.
test_client
()
'''
GET method
'''
# status code
def
test_get_root_return_code_200
(
self
):
response
=
self
.
server
.
get
(
'/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_get_webdav_root_return_code_200
(
self
):
response
=
self
.
server
.
get
(
'/webdav/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# MIME type
def
test_plaintext_content_type
(
self
):
response
=
self
.
server
.
get
(
'/webdav/file.txt'
)
self
.
assertEqual
(
response
.
mimetype
,
'text/plain'
)
def
test_plaintext_content_type
(
self
):
response
=
self
.
server
.
get
(
'/webdav/file.js'
)
self
.
assertEqual
(
response
.
mimetype
,
'application/x-javascript'
)
def
test_png_content_type
(
self
):
response
=
self
.
app
.
test_client
().
get
(
'/webdav/file.png'
)
self
.
assertEqual
(
response
.
mimetype
,
'image/png'
)
# response body
def
test_response_body
(
self
):
f
=
open
(
self
.
app
.
fs_path
+
'/file.txt'
,
'w'
)
f
.
write
(
'pouet'
)
f
.
close
()
response
=
self
.
server
.
get
(
'/webdav/file.txt'
)
self
.
assertEqual
(
response
.
data
,
'pouet'
)
'''
PUT method
'''
# status code
def
test_put_root_return_code_405
(
self
):
response
=
self
.
server
.
put
(
'/'
)
self
.
assertEqual
(
response
.
status_code
,
405
)
def
test_put_webdav_return_code_201
(
self
):
response
=
self
.
server
.
put
(
'/webdav/put.txt'
,
''
)
self
.
assertEqual
(
response
.
status_code
,
201
)
# file content modification
def
test_put_webdav_content_changed
(
self
):
response
=
self
.
server
.
put
(
'/webdav/put.txt'
,
data
=
'couscous'
)
f
=
open
(
self
.
app
.
fs_path
+
'/put.txt'
,
'r'
)
content
=
f
.
read
()
f
.
close
()
self
.
assertEqual
(
content
,
'couscous'
)
@
classmethod
def
tearDownClass
(
self
):
'''
cleaning temporary dir
'''
shutil
.
rmtree
(
self
.
app
.
fs_path
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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