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
d11a036c
Commit
d11a036c
authored
Nov 12, 2014
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial tests for custom queryset methods
parent
f2c2d4d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
10 deletions
+38
-10
wiki/tests/base.py
+21
-10
wiki/tests/test_basic.py
+17
-0
No files found.
wiki/tests/base.py
View file @
d11a036c
...
@@ -4,7 +4,9 @@ from django.test.client import Client
...
@@ -4,7 +4,9 @@ from django.test.client import Client
from
wiki.models
import
URLPath
from
wiki.models
import
URLPath
class
WebTestBase
(
TestCase
):
class
WebTestBase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestCase
,
self
)
.
setUp
()
super
(
TestCase
,
self
)
.
setUp
()
try
:
try
:
...
@@ -12,28 +14,36 @@ class WebTestBase(TestCase):
...
@@ -12,28 +14,36 @@ class WebTestBase(TestCase):
User
=
get_user_model
()
User
=
get_user_model
()
except
ImportError
:
except
ImportError
:
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
User
.
objects
.
create_superuser
(
'admin'
,
'nobody@example.com'
,
'secret'
)
self
.
superuser1
=
User
.
objects
.
create_superuser
(
'admin'
,
'nobody@example.com'
,
'secret'
)
self
.
c
=
c
=
Client
()
self
.
c
=
c
=
Client
()
c
.
login
(
username
=
'admin'
,
password
=
'secret'
)
c
.
login
(
username
=
'admin'
,
password
=
'secret'
)
class
ArticleTestBase
(
WebTestBase
):
class
ArticleTestBase
(
WebTestBase
):
"""Base class for web client tests, that sets up initial root article."""
"""Base class for web client tests, that sets up initial root article."""
def
setUp
(
self
):
def
setUp
(
self
):
super
(
ArticleTestBase
,
self
)
.
setUp
()
super
(
ArticleTestBase
,
self
)
.
setUp
()
response
=
self
.
c
.
post
(
reverse
(
'wiki:root_create'
),
{
'content'
:
'root article content'
,
'title'
:
'Root Article'
},
follow
=
True
)
response
=
self
.
c
.
post
(
self
.
assertEqual
(
response
.
status_code
,
200
)
# sanity check
reverse
(
'wiki:root_create'
),
{
'content'
:
'root article content'
,
'title'
:
'Root Article'
},
follow
=
True
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# sanity check
self
.
root_article
=
URLPath
.
root
()
.
article
self
.
root_article
=
URLPath
.
root
()
.
article
self
.
example_data
=
{
self
.
example_data
=
{
'content'
:
'The modified text'
,
'content'
:
'The modified text'
,
'current_revision'
:
'1'
,
'current_revision'
:
'1'
,
'preview'
:
'1'
,
'preview'
:
'1'
,
#
'save': '1', # probably not too important
#
'save': '1', # probably not too important
'summary'
:
'why edited'
,
'summary'
:
'why edited'
,
'title'
:
'wiki test'
}
'title'
:
'wiki test'
}
def
get_by_path
(
self
,
path
):
def
get_by_path
(
self
,
path
):
"""Get the article response for the path.
"""Get the article response for the path.
Example: self.get_by_path("Level1/Slug2/").title
Example: self.get_by_path("Level1/Slug2/").title
"""
"""
return
self
.
c
.
get
(
reverse
(
'wiki:get'
,
kwargs
=
{
'path'
:
path
}))
return
self
.
c
.
get
(
reverse
(
'wiki:get'
,
kwargs
=
{
'path'
:
path
}))
\ No newline at end of file
wiki/tests/test_basic.py
View file @
d11a036c
...
@@ -8,6 +8,23 @@ import pprint
...
@@ -8,6 +8,23 @@ import pprint
from
.base
import
ArticleTestBase
,
WebTestBase
from
.base
import
ArticleTestBase
,
WebTestBase
from
wiki
import
models
class
ModelTests
(
ArticleTestBase
):
"""Tests basic model and queryset functionalities"""
def
test_custom_querysets
(
self
):
"""
Tests that the custom queryset methods work, this is important
because the pattern of building them is different from Django
1.5 to 1.6 to 1.7 so there will be 3 patterns in play at the
same time.
"""
self
.
assertEqual
(
models
.
Article
.
objects
.
can_read
(
self
.
superuser1
)
.
count
(),
1
)
self
.
assertEqual
(
models
.
Article
.
objects
.
can_write
(
self
.
superuser1
)
.
count
(),
1
)
self
.
assertEqual
(
models
.
Article
.
objects
.
active
()
.
count
(),
1
)
class
RootArticleViewTests
(
WebTestBase
):
class
RootArticleViewTests
(
WebTestBase
):
...
...
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