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
d931aa24
Commit
d931aa24
authored
Jan 04, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Still improving coverage
parent
4710efaf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
387 additions
and
15 deletions
+387
-15
picampaign/campaign/serializers.py
picampaign/campaign/serializers.py
+0
-1
picampaign/campaign/test_admin.py
picampaign/campaign/test_admin.py
+184
-0
picampaign/campaign/test_serializers.py
picampaign/campaign/test_serializers.py
+63
-0
picampaign/campaign/test_views.py
picampaign/campaign/test_views.py
+59
-0
picampaign/campaign/views.py
picampaign/campaign/views.py
+0
-3
picampaign/contact/views.py
picampaign/contact/views.py
+0
-3
picampaign/feedback/serializers.py
picampaign/feedback/serializers.py
+1
-1
picampaign/feedback/tests.py
picampaign/feedback/tests.py
+73
-1
picampaign/feedback/views.py
picampaign/feedback/views.py
+7
-6
No files found.
picampaign/campaign/serializers.py
View file @
d931aa24
...
...
@@ -57,4 +57,3 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):
if
phone
[
'phone'
].
startswith
(
filter
):
data
[
'phone'
]
=
phone
[
'phone'
]
return
data
return
data
picampaign/campaign/test_admin.py
0 → 100644
View file @
d931aa24
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
from
picampaign.campaign.models
import
Campaign
,
Contact
,
CampaignContact
,
Argumentary
from
picampaign.campaign.admin
import
CampaignAdmin
,
CampaignContactAdmin
,
ArgumentaryAdmin
from
picampaign.organization.models
import
Organization
class
MockRequest
(
object
):
pass
class
ArugmentaryAdminTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
campaign
=
Campaign
.
objects
.
create
(
title
=
'Campaign Title'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
self
.
organization
)
self
.
argumentary
=
Argumentary
.
objects
.
create
(
lang
=
'en'
,
text
=
'A pertinent argument'
,
campaign
=
self
.
campaign
)
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
=
ArgumentaryAdmin
(
Argumentary
,
self
.
site
)
request
=
MockRequest
()
# SuperUser should have it all
request
.
user
=
self
.
super_user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Argumentary
.
objects
.
all
()))
# User with no orgs should have nothing
request
.
user
=
self
.
user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
[])
# User with orgs should have contacts from associated campaign
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Argumentary
.
objects
.
all
()))
def
test_formfield_for_foreignkey
(
self
):
ma
=
ArgumentaryAdmin
(
Argumentary
,
self
.
site
)
request
=
MockRequest
()
# Organization fields should be filtered
request
.
user
=
self
.
user
form
=
ma
.
get_form
(
request
)()
self
.
assertHTMLEqual
(
str
(
form
[
'campaign'
]),
'<div class="related-widget-wrapper">'
'<select id="id_campaign" name="campaign">'
'<option value="" selected="selected">---------</option>'
'</select>'
'</div>'
)
# If we add an org, we shoudl have it
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
form
=
ma
.
get_form
(
request
)()
self
.
assertHTMLEqual
(
str
(
form
[
'campaign'
]),
'<div class="related-widget-wrapper">'
'<select id="id_campaign" name="campaign">'
'<option value="" selected="selected">---------</option>'
'<option value="%d">%s</option>'
'</select>'
'</div>'
%
(
self
.
campaign
.
id
,
str
(
self
.
campaign
)))
class
CampaignContactAdminTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
campaign
=
Campaign
.
objects
.
create
(
title
=
'Campaign Title'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
self
.
organization
)
self
.
contact
=
Contact
.
objects
.
create
(
first_name
=
'Victor'
,
last_name
=
'Hugo'
,
birthdate
=
'1802-02-26'
)
self
.
campaigncontact
=
CampaignContact
.
objects
.
create
(
campaign
=
self
.
campaign
,
contact
=
self
.
contact
)
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
=
CampaignContactAdmin
(
CampaignContact
,
self
.
site
)
request
=
MockRequest
()
# SuperUser should have it all
request
.
user
=
self
.
super_user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
CampaignContact
.
objects
.
all
()))
# User with no orgs should have nothing
request
.
user
=
self
.
user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
[])
# User with orgs should have contacts from associated campaign
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
CampaignContact
.
objects
.
all
()))
class
CampaignAdminTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
campaign
=
Campaign
.
objects
.
create
(
title
=
'Campaign Title'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
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
=
CampaignAdmin
(
Campaign
,
self
.
site
)
request
=
MockRequest
()
# SuperUser should have access to everything
request
.
user
=
self
.
super_user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Campaign
.
objects
.
all
()))
# NormalUser outside of organization should have access to nothing
request
.
user
=
self
.
user
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
[])
# NormalUser which is part of orgs should have access to them
request
.
user
.
organizations
=
Organization
.
objects
.
all
()
self
.
assertEqual
(
list
(
ma
.
get_queryset
(
request
)),
list
(
Campaign
.
objects
.
all
()))
def
test_formfield_for_foreignkey
(
self
):
ma
=
CampaignAdmin
(
Campaign
,
self
.
site
)
request
=
MockRequest
()
# Organization fields should be filtered
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">'
'<option value="" selected="selected">---------</option>'
'</select>'
'</div>'
)
# If we add an org, we shoudl have it
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">'
'<option value="" selected="selected">---------</option>'
'<option value="%d">%s</option>'
'</select>'
'</div>'
%
(
self
.
organization
.
id
,
str
(
self
.
organization
)))
picampaign/campaign/test_serializers.py
0 → 100644
View file @
d931aa24
from
collections
import
OrderedDict
from
django.test
import
TestCase
from
picampaign.contact.models
import
Phone
,
Contact
from
picampaign.campaign.models
import
Argumentary
,
Campaign
,
Organization
,
CampaignContact
from
picampaign.campaign.serializers
import
ArgumentarySerializer
,
CampaignContactSerializer
class
ArgumentarySerializerTest
(
TestCase
):
def
test_serializers
(
self
):
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
campaign
=
Campaign
.
objects
.
create
(
title
=
'A campaign'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
organization
)
Argumentary
.
objects
.
create
(
lang
=
'en'
,
text
=
'A pertinent argument'
,
campaign
=
campaign
)
self
.
assertEqual
(
ArgumentarySerializer
(
Argumentary
.
objects
.
all
(),
many
=
True
).
data
,
[
OrderedDict
([(
'lang'
,
'en'
),
(
'text'
,
'A pertinent argument'
)])])
class
CampaignContactSerializerTest
(
TestCase
):
def
test_to_representation
(
self
):
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
campaign
=
Campaign
.
objects
.
create
(
title
=
'A campaign'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
organization
)
contact
=
Contact
.
objects
.
create
(
first_name
=
'Victor'
,
last_name
=
'Hugo'
,
birthdate
=
'1887-02-26'
,
)
Phone
.
objects
.
create
(
phone
=
'0123456789'
,
valid
=
True
,
contact
=
contact
)
Phone
.
objects
.
create
(
phone
=
'9876543210'
,
valid
=
True
,
contact
=
contact
)
campaigncontact
=
CampaignContact
(
campaign
=
campaign
,
contact
=
contact
)
serializer
=
CampaignContactSerializer
(
campaigncontact
)
self
.
assertEqual
(
serializer
.
to_representation
(
campaigncontact
)[
'phone'
],
contact
.
phones
.
first
().
phone
)
# Let's add a phone filter
campaign
.
phone_filter
=
'98'
self
.
assertEqual
(
serializer
.
to_representation
(
campaigncontact
)[
'phone'
],
contact
.
phones
.
last
().
phone
)
picampaign/campaign/test_views.py
0 → 100644
View file @
d931aa24
from
rest_framework.test
import
APIClient
from
django.test
import
TestCase
from
picampaign.campaign.models
import
Argumentary
,
Organization
,
Campaign
,
CampaignContact
from
picampaign.contact.models
import
Contact
,
Phone
class
ViewSetTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
campaign
=
Campaign
.
objects
.
create
(
title
=
'Campaign Title'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
self
.
organization
)
self
.
argumentary
=
Argumentary
.
objects
.
create
(
lang
=
'en'
,
text
=
'A pertinent argument'
,
campaign
=
self
.
campaign
)
self
.
contact
=
Contact
.
objects
.
create
(
first_name
=
'Victor'
,
last_name
=
'Hugo'
,
birthdate
=
'1802-02-26'
)
self
.
campaigncontact
=
CampaignContact
.
objects
.
create
(
campaign
=
self
.
campaign
,
contact
=
self
.
contact
)
self
.
phone
=
Phone
.
objects
.
create
(
phone
=
'0123456789'
,
valid
=
True
,
contact
=
self
.
contact
)
def
test_campaign_viewset
(
self
):
client
=
APIClient
()
response
=
client
.
get
(
'/campaigns/'
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'[{"id":1,"title":"Campaign Title","description":null,"start_date":"2000-01-01","end_date":"2100-12-31"}]'
)
def
test_campaign_contact_viewset
(
self
):
client
=
APIClient
()
response
=
client
.
get
(
'/campaigns/%(cid)d/contacts/'
%
{
'cid'
:
self
.
campaign
.
id
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'[{"id":1,"weight":0,"contact_id":1,"full_name":"Victor Hugo","first_name":"Victor","last_name":"Hugo","phone":"0123456789","groups":[],"photo":""}]'
)
def
test_campaign_argumentary_viewset
(
self
):
client
=
APIClient
()
response
=
client
.
get
(
'/campaigns/%(cid)d/arguments/'
%
{
'cid'
:
self
.
campaign
.
id
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'[{"lang":"en","text":"A pertinent argument"}]'
)
response
=
client
.
get
(
'/campaigns/%(cid)d/arguments/%(lang)s/'
%
{
'cid'
:
self
.
campaign
.
id
,
'lang'
:
self
.
argumentary
.
lang
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'{"lang":"en","text":"A pertinent argument"}'
)
picampaign/campaign/views.py
View file @
d931aa24
...
...
@@ -5,7 +5,6 @@ from picampaign.campaign.serializers import (CampaignSerializer,
CampaignContactSerializer
,
ArgumentarySerializer
)
class
CampaignViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint for campaign view
...
...
@@ -13,7 +12,6 @@ class CampaignViewSet(viewsets.ReadOnlyModelViewSet):
queryset
=
Campaign
.
objects
.
all
()
serializer_class
=
CampaignSerializer
class
CampaignContactViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view contacts related to a campaign
...
...
@@ -26,7 +24,6 @@ class CampaignContactViewSet(viewsets.ReadOnlyModelViewSet):
serializer
=
self
.
serializer_class
(
contacts
.
all
(),
many
=
True
)
return
Response
(
serializer
.
data
)
class
ArgumentaryViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
API endpoint to view contacts related to a campaign
...
...
picampaign/contact/views.py
deleted
100644 → 0
View file @
4710efaf
from
django.shortcuts
import
render
# Create your views here.
picampaign/feedback/serializers.py
View file @
d931aa24
...
...
@@ -6,4 +6,4 @@ class FeedbackSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Feedback
fields
=
(
'comment'
,
'callee'
)
fields
=
(
'c
ategory'
,
'c
omment'
,
'callee'
)
picampaign/feedback/tests.py
View file @
d931aa24
from
django.test
import
TestCase
from
rest_framework.test
import
APITestCase
# Create your tests here.
from
picampaign.contact.models
import
Contact
from
picampaign.campaign.models
import
CampaignContact
,
Campaign
from
picampaign.organization.models
import
FeedbackCategory
,
Organization
from
picampaign.feedback.models
import
Feedback
class
FeedbackModelTest
(
TestCase
):
def
test_str
(
self
):
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
contact
=
Contact
.
objects
.
create
(
first_name
=
'Victor'
,
last_name
=
'Hugo'
,
birthdate
=
'1889-02-26'
)
campaign
=
Campaign
.
objects
.
create
(
title
=
'Test campaign'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
organization
)
campaigncontact
=
CampaignContact
.
objects
.
create
(
campaign
=
campaign
,
contact
=
contact
)
feedbackcategory
=
FeedbackCategory
.
objects
.
create
(
name
=
'Normal'
,
organization
=
organization
)
feedback
=
Feedback
.
objects
.
create
(
callee
=
campaigncontact
,
category
=
feedbackcategory
,
comment
=
'Feedback'
)
self
.
assertEqual
(
str
(
feedback
),
'feedback for %(callee)s on %(campaign)s'
%
{
'callee'
:
campaigncontact
.
contact
,
'campaign'
:
campaign
})
class
FeedbackViewTest
(
APITestCase
):
def
test_create
(
self
):
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
category
=
FeedbackCategory
.
objects
.
create
(
name
=
'Normal'
,
organization
=
organization
)
campaign
=
Campaign
.
objects
.
create
(
title
=
'Test campaign'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
organization
)
contact
=
Contact
.
objects
.
create
(
first_name
=
'Victor'
,
last_name
=
'Hugo'
,
birthdate
=
'1889-02-26'
)
campaigncontact
=
CampaignContact
.
objects
.
create
(
campaign
=
campaign
,
contact
=
contact
)
data
=
{
'callee'
:
contact
.
id
,
'category'
:
category
.
id
,
'comment'
:
'Feedback'
}
response
=
self
.
client
.
post
(
'/campaigns/%(cid)d/feedbacks/'
%
{
'cid'
:
campaign
.
id
},
data
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
Feedback
.
objects
.
count
(),
1
)
self
.
assertEqual
(
Feedback
.
objects
.
get
().
comment
,
'Feedback'
)
data
=
{
'callee'
:
contact
.
id
,
'category'
:
1234567
,
'comment'
:
'Feedback'
}
with
self
.
assertRaises
(
Exception
):
self
.
client
.
post
(
'/campaigns/%(cid)d/feedbacks/'
%
{
'cid'
:
campaign
.
id
},
data
,
format
=
'json'
)
picampaign/feedback/views.py
View file @
d931aa24
...
...
@@ -12,10 +12,11 @@ class FeedbackViewSet(viewsets.ViewSet):
serializer_class
=
FeedbackSerializer
def
create
(
self
,
request
,
campaign_pk
=
None
):
serializer
=
FeedbackSerializer
(
request
.
DATA
)
callee
=
CampaignContact
.
objects
.
get
(
id
=
request
.
DATA
[
'callee'
])
category
=
FeedbackCategory
.
objects
.
get
(
id
=
request
.
DATA
[
'category'
])
serializer
.
data
[
'callee'
]
=
callee
serializer
.
data
[
'category'
]
=
category
feedback
=
Feedback
.
objects
.
create
(
**
serializer
.
data
)
serializer
=
FeedbackSerializer
(
data
=
request
.
data
)
try
:
serializer
.
is_valid
()
except
Exception
as
e
:
print
(
"Bloup"
)
raise
e
feedback
=
Feedback
.
objects
.
create
(
**
serializer
.
validated_data
)
return
Response
(
feedback
.
id
)
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