Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
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
OpenEdx
django-wiki
Commits
844bbd4a
Commit
844bbd4a
authored
Oct 01, 2014
by
Luke Plant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pulled out some useful base classes for test cases
parent
13502c67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
45 deletions
+52
-45
wiki/tests/base.py
+43
-0
wiki/tests/test_basic.py
+9
-45
No files found.
wiki/tests/base.py
0 → 100644
View file @
844bbd4a
from
django.core.urlresolvers
import
reverse
from
django.test
import
TestCase
from
django.test.client
import
Client
class
WebTestBase
(
TestCase
):
def
setUp
(
self
):
super
(
TestCase
,
self
)
.
setUp
()
try
:
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
except
ImportError
:
from
django.contrib.auth.models
import
User
User
.
objects
.
create_superuser
(
'admin'
,
'nobody@example.com'
,
'secret'
)
self
.
c
=
c
=
Client
()
c
.
login
(
username
=
'admin'
,
password
=
'secret'
)
class
ArticleTestBase
(
WebTestBase
):
"""Base class for web client tests, that sets up initial root article."""
def
setUp
(
self
):
super
(
ArticleTestBase
,
self
)
.
setUp
()
response
=
self
.
c
.
post
(
reverse
(
'wiki:root_create'
),
{
'content'
:
'root article content'
,
'title'
:
'Root Article'
},
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# sanity check
self
.
example_data
=
{
'content'
:
'The modified text'
,
'current_revision'
:
'1'
,
'preview'
:
'1'
,
#'save': '1', # probably not too important
'summary'
:
'why edited'
,
'title'
:
'wiki test'
}
def
tearDown
(
self
):
super
(
ArticleTestBase
,
self
)
.
tearDown
()
# clear Article cache before the next test
from
wiki.models
import
Article
Article
.
objects
.
all
()
.
delete
()
def
get_by_path
(
self
,
path
):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
"""
return
self
.
c
.
get
(
reverse
(
'wiki:get'
,
kwargs
=
{
'path'
:
path
}))
wiki/tests/test_basic.py
View file @
844bbd4a
from
__future__
import
print_function
from
__future__
import
print_function
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.test
import
TestCase
from
django.test.client
import
Client
import
pprint
import
pprint
class
InitialWebClientTest
(
TestCase
):
from
.base
import
ArticleTestBase
,
WebTestBase
"""Tests by the dummy web client, with manual creating the root article."""
def
setUp
(
self
):
class
RootArticleViewTests
(
WebTestBase
):
try
:
"""Tests for creating/viewing the root article."""
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
except
ImportError
:
from
django.contrib.auth.models
import
User
User
.
objects
.
create_superuser
(
'admin'
,
'nobody@example.com'
,
'secret'
)
self
.
c
=
c
=
Client
()
c
.
login
(
username
=
'admin'
,
password
=
'secret'
)
def
test_root_article
(
self
):
def
test_root_article
(
self
):
"""Test redirecting to /create-root/, creating the root article and a simple markup."""
"""Test redirecting to /create-root/, creating the root article and a simple markup."""
...
@@ -33,37 +23,11 @@ class InitialWebClientTest(TestCase):
...
@@ -33,37 +23,11 @@ class InitialWebClientTest(TestCase):
self
.
assertContains
(
response
,
'test heading h1</h1>'
)
self
.
assertContains
(
response
,
'test heading h1</h1>'
)
class
WebClientTest
(
TestCase
):
class
ArticleViewTests
(
ArticleTestBase
):
"""Tests by the dummy web client."""
"""
def
setUp
(
self
):
Tests for article views, assuming a root article already created.
try
:
"""
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
except
ImportError
:
from
django.contrib.auth.models
import
User
User
.
objects
.
create_superuser
(
'admin'
,
'nobody@example.com'
,
'secret'
)
self
.
c
=
c
=
Client
()
c
.
login
(
username
=
'admin'
,
password
=
'secret'
)
response
=
self
.
c
.
post
(
reverse
(
'wiki:root_create'
),
{
'content'
:
'root article content'
,
'title'
:
'Root Article'
})
self
.
example_data
=
{
'content'
:
'The modified text'
,
'current_revision'
:
'1'
,
'preview'
:
'1'
,
#'save': '1', # probably not too important
'summary'
:
'why edited'
,
'title'
:
'wiki test'
}
def
tearDown
(
self
):
# clear Article cache before the next test
from
wiki.models
import
Article
Article
.
objects
.
all
()
.
delete
()
def
get_by_path
(
self
,
path
):
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
"""
return
self
.
c
.
get
(
reverse
(
'wiki:get'
,
kwargs
=
{
'path'
:
path
}))
def
dump_db_status
(
self
,
message
=
''
):
def
dump_db_status
(
self
,
message
=
''
):
"""Debug printing of the complete important database content."""
"""Debug printing of the complete important database content."""
print
(
'*** db status *** {}'
.
format
(
message
))
print
(
'*** db status *** {}'
.
format
(
message
))
...
...
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