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
91953a8b
Commit
91953a8b
authored
Jan 04, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing the importer
parent
d931aa24
Pipeline
#707
failed with stage
in 57 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3418 additions
and
17 deletions
+3418
-17
picampaign/importer/data_tests.json
picampaign/importer/data_tests.json
+3327
-0
picampaign/importer/models.py
picampaign/importer/models.py
+13
-17
picampaign/importer/tests.py
picampaign/importer/tests.py
+78
-0
No files found.
picampaign/importer/data_tests.json
0 → 100644
View file @
91953a8b
This diff is collapsed.
Click to expand it.
picampaign/importer/models.py
View file @
91953a8b
...
...
@@ -29,9 +29,9 @@ class Importer(models.Model):
'name'
:
self
.
name
}
def
kind
(
self
):
if
self
.
url
is
''
and
self
.
fil
e
is
None
:
if
self
.
url
is
None
and
self
.
file
.
nam
e
is
None
:
return
None
if
self
.
url
is
''
:
if
self
.
url
is
None
:
return
'file'
else
:
return
'url'
...
...
@@ -63,19 +63,16 @@ class Importer(models.Model):
if
not
(
end_date
==
''
or
end_date
.
startswith
(
'9999'
)):
# This mandate has ended
continue
# We want to only use the groups nown by the organisation
try
:
groupType
=
GroupType
.
objects
.
get
(
organization
=
self
.
organization
,
name
=
mandate
[
'group'
][
'kind'
])
except
:
continue
if
'abbreviation'
in
mandate
[
'group'
]:
group
,
added
=
Group
.
objects
.
get_or_create
(
name
=
mandate
[
'group'
][
'abbreviation'
],
type
=
groupType
)
else
:
group
,
added
=
Group
.
objects
.
get_or_create
(
name
=
mandate
[
'group'
][
'name'
],
type
=
groupType
)
groups
.
append
(
group
)
# We want to only use the groups own by the organisation
for
groupType
in
GroupType
.
objects
.
filter
(
organization
=
self
.
organization
,
name
=
mandate
[
'group'
][
'kind'
]):
if
'abbreviation'
in
mandate
[
'group'
]:
group
,
added
=
Group
.
objects
.
get_or_create
(
name
=
mandate
[
'group'
][
'abbreviation'
],
type
=
groupType
)
else
:
group
,
added
=
Group
.
objects
.
get_or_create
(
name
=
mandate
[
'group'
][
'name'
],
type
=
groupType
)
groups
.
append
(
group
)
if
groups
==
[]:
# The contact have no groups active, he is not to be bothered.
continue
...
...
@@ -122,7 +119,7 @@ class Importer(models.Model):
# Updating the last imported item
self
.
last_imported
=
inserted
self
.
save
()
def
handle
(
self
):
"""
This function is used to import the data described by the Importer.
...
...
@@ -155,5 +152,4 @@ class Importer(models.Model):
# Now, let's get the correct call
if
self
.
category
==
'repr'
:
self
.
representative
(
import_data
)
return
picampaign/importer/tests.py
0 → 100644
View file @
91953a8b
from
unittest
import
mock
from
django.test
import
TestCase
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
picampaign.importer.models
import
Importer
from
picampaign.contact.models
import
Contact
,
Phone
from
picampaign.campaign.models
import
Campaign
,
CampaignContact
from
picampaign.organization.models
import
Group
,
GroupType
,
Organization
class
ImporterTest
(
TestCase
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
name
=
'Majestic 12'
,
sip_key
=
'majestic-12'
)
self
.
campaign
=
Campaign
.
objects
.
create
(
title
=
'Test campaign'
,
start_date
=
'2000-01-01'
,
end_date
=
'2100-12-31'
,
organization
=
self
.
organization
)
GroupType
.
objects
.
create
(
organization
=
self
.
organization
,
name
=
'group'
)
GroupType
.
objects
.
create
(
organization
=
self
.
organization
,
name
=
'chamber'
)
GroupType
.
objects
.
create
(
organization
=
self
.
organization
,
name
=
'committee'
)
def
test_str
(
self
):
importer
=
Importer
.
objects
.
create
(
name
=
'test importer'
,
category
=
'repr'
,
campaign
=
self
.
campaign
,
organization
=
self
.
organization
)
self
.
assertEqual
(
str
(
importer
),
u
'%(name)s: %(format)s %(type)s importer'
%
{
'format'
:
importer
.
category
,
'type'
:
importer
.
kind
(),
'name'
:
importer
.
name
})
def
test_kind
(
self
):
importer
=
Importer
.
objects
.
create
(
name
=
'test importer'
,
category
=
'repr'
,
campaign
=
self
.
campaign
,
organization
=
self
.
organization
,
)
self
.
assertEqual
(
importer
.
kind
(),
None
)
importer
.
file
=
'a'
self
.
assertEqual
(
importer
.
kind
(),
'file'
)
importer
.
url
=
'http://www.example.com/'
self
.
assertEqual
(
importer
.
kind
(),
'url'
)
def
test_representative
(
self
):
json_file
=
None
with
open
(
'picampaign/importer/data_tests.json'
,
u
'rb'
)
as
f
:
json_file
=
SimpleUploadedFile
(
'data_tests.json'
,
f
.
read
())
importer
=
Importer
.
objects
.
create
(
name
=
'test importer'
,
category
=
'repr'
,
campaign
=
self
.
campaign
,
organization
=
self
.
organization
,
file
=
json_file
)
self
.
assertEqual
(
importer
.
kind
(),
'file'
)
importer
.
handle
()
importer
.
refresh_from_db
()
# The file import 3 of the 10 meps
self
.
assertEqual
(
importer
.
last_count
,
10
)
self
.
assertEqual
(
importer
.
last_imported
,
3
)
self
.
assertEqual
(
len
(
Group
.
objects
.
all
()),
13
)
self
.
assertEqual
(
len
(
Contact
.
objects
.
all
()),
3
)
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