Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
campaign
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
60bc7c30
Commit
60bc7c30
authored
Jan 05, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
59% covergae on organization/admin
parent
bb148de0
Pipeline
#716
passed with stage
in 1 minute and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
1 deletion
+88
-1
picampaign/campaign/test_admin.py
picampaign/campaign/test_admin.py
+0
-1
picampaign/organization/tests.py
picampaign/organization/tests.py
+88
-0
No files found.
picampaign/campaign/test_admin.py
View file @
60bc7c30
from
django.contrib.admin.sites
import
AdminSite
from
django.contrib.admin.options
import
ModelAdmin
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
...
...
picampaign/organization/tests.py
View file @
60bc7c30
from
django.contrib.admin.sites
import
AdminSite
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
rest_framework.test
import
APIClient
from
picampaign.organization.models
import
Organization
,
GroupType
,
Group
,
FeedbackCategory
from
picampaign.organization.admin
import
OrganizationAdmin
,
GroupTypeAdmin
from
picampaign.campaign.models
import
Campaign
# Create your tests here.
...
...
@@ -75,3 +78,88 @@ class CategoryViewSet(TestCase):
response
=
client
.
get
(
'/campaigns/%(cid)s/categories/'
%
{
'cid'
:
self
.
campaign
.
id
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'[{"id":1,"name":"Feedback"}]'
)
class
MockRequest
(
object
):
pass
class
OrganizationAdminTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
super_user
=
User
.
objects
.
create_superuser
(
username
=
'john'
,
email
=
'johndoe@example.com'
,
password
=
'password'
,
)
self
.
user
=
User
.
objects
.
create_user
(
username
=
'jane'
,
email
=
'janedoe@example.com'
,
password
=
'password'
)
self
.
site
=
AdminSite
()
def
test_get_queryset
(
self
):
ma
=
OrganizationAdmin
(
Organization
,
self
.
site
)
request
=
MockRequest
()
request
.
user
=
self
.
super_user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Organization
.
objects
.
all
()))
request
.
user
=
self
.
user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
[])
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Organization
.
objects
.
all
()))
class
GroupTypeAdminTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
grouptype
=
GroupType
.
objects
.
create
(
name
=
'Group'
,
organization
=
self
.
organization
)
self
.
super_user
=
User
.
objects
.
create_superuser
(
username
=
'john'
,
email
=
'johndoe@example.com'
,
password
=
'password'
,
)
self
.
user
=
User
.
objects
.
create_user
(
username
=
'jane'
,
email
=
'janedoe@example.com'
,
password
=
'password'
)
self
.
site
=
AdminSite
()
def
test_get_queryset
(
self
):
ma
=
GroupTypeAdmin
(
GroupType
,
self
.
site
)
request
=
MockRequest
()
request
.
user
=
self
.
super_user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
GroupType
.
objects
.
all
()))
request
.
user
=
self
.
user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
[])
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
GroupType
.
objects
.
all
()))
def
test_formfield_forforeignkey
(
self
):
ma
=
GroupTypeAdmin
(
GroupType
,
self
.
site
)
request
=
MockRequest
()
request
.
user
=
self
.
user
form
=
ma
.
get_form
(
request
)()
self
.
assertHTMLEqual
(
str
(
form
[
'organization'
]),
'<div class="related-widget-wrapper">'
'<select id="id_organization" name="organization" required>'
'<option value="" selected="selected">---------</option>'
'</select>'
'</div>'
)
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
form
=
ma
.
get_form
(
request
)()
self
.
assertHTMLEqual
(
str
(
form
[
'organization'
]),
'<div class="related-widget-wrapper">'
'<select id="id_organization" name="organization" required>'
'<option value="" selected="selected">---------</option>'
'<option value="%(id)d">%(org)s</option>'
'</select>'
'</div>'
%
{
'id'
:
self
.
organization
.
id
,
'org'
:
self
.
organization
})
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