Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
9ed34be7
Commit
9ed34be7
authored
Mar 10, 2011
by
tom christie tom@tomchristie.com
Browse files
Options
Browse Files
Download
Plain Diff
markos pygments tests
parents
c25f8f84
f7f00154
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
examples/pygments_api/tests.py
+4
-2
examples/pygments_api/views.py
+8
-5
No files found.
examples/pygments_api/tests.py
View file @
9ed34be7
from
django.test
import
TestCase
from
djangorestframework.compat
import
RequestFactory
from
pygments_api
import
views
import
os
,
tempfile
,
shutil
import
os
,
tempfile
,
shutil
,
time
,
json
class
TestPygmentsExample
(
TestCase
):
...
...
@@ -35,7 +35,8 @@ class TestPygmentsExample(TestCase):
request
=
self
.
factory
.
get
(
'/pygments'
)
view
=
views
.
PygmentsRoot
.
as_view
()
response
=
view
(
request
)
self
.
assertEquals
(
locations
,
response
.
content
)
response_locations
=
json
.
loads
(
response
.
content
)
self
.
assertEquals
(
locations
,
response_locations
)
\ No newline at end of file
examples/pygments_api/views.py
View file @
9ed34be7
...
...
@@ -21,13 +21,15 @@ import operator
HIGHLIGHTED_CODE_DIR
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'pygments'
)
MAX_FILES
=
20
def
list_dir_sorted_by_ctime
(
dir
):
"""Return a list of files sorted by creation time"""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
return
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
def
remove_oldest_files
(
dir
,
max_files
):
"""Remove the oldest files in a directory 'dir', leaving at most 'max_files' remaining.
We use this to limit the number of resources in the sandbox."""
filepaths
=
[
os
.
path
.
join
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
ctime_sorted_paths
=
[
item
[
0
]
for
item
in
sorted
([(
path
,
os
.
path
.
getctime
(
path
))
for
path
in
filepaths
],
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)]
[
os
.
remove
(
path
)
for
path
in
ctime_sorted_paths
[
max_files
:]]
[
os
.
remove
(
path
)
for
path
in
list_dir_sorted_by_ctime
(
dir
)[
max_files
:]]
class
HTMLEmitter
(
BaseEmitter
):
...
...
@@ -43,7 +45,8 @@ class PygmentsRoot(Resource):
def
get
(
self
,
request
,
auth
):
"""Return a list of all currently existing snippets."""
unique_ids
=
sorted
(
os
.
listdir
(
HIGHLIGHTED_CODE_DIR
))
unique_ids
=
[
os
.
path
.
split
(
f
)[
1
]
for
f
in
list_dir_sorted_by_ctime
(
HIGHLIGHTED_CODE_DIR
)]
unique_ids
.
reverse
()
return
[
reverse
(
'pygments-instance'
,
args
=
[
unique_id
])
for
unique_id
in
unique_ids
]
def
post
(
self
,
request
,
auth
,
content
):
...
...
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