Commit 714aab07 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Fix rep votes tests with natural keys as well

parent a2782dd8
[ [
{ {
"fields" : { "fields": {
"abbreviation": "AN", "abbreviation": "AN",
"country": 1095, "country": [
"FR"
],
"name": "Assembl\u00e9e nationale" "name": "Assembl\u00e9e nationale"
}, },
"model": "representatives.chamber", "model": "representatives.chamber"
"pk": 2
}, },
{ {
"fields": { "fields": {
"abbreviation": "SEN", "abbreviation": "SEN",
"country": 1095, "country": [
"FR"
],
"name": "S\u00e9nat" "name": "S\u00e9nat"
}, },
"model": "representatives.chamber", "model": "representatives.chamber"
"pk": 3
}, },
{ {
"fields": { "fields": {
"text": "", "text": "",
"updated": "2016-07-07T20:23:24.303Z", "updated": "2016-10-05T09:33:06.310Z",
"title": "Education : libre choix des maires concernant les rythmes scolaires dans le premier degr\u00e9", "title": "Education : libre choix des maires concernant les rythmes scolaires dans le premier degr\u00e9",
"reference": "14/liberte_maires_rythmes_scolaires_premier_degre", "reference": "14/liberte_maires_rythmes_scolaires_premier_degre",
"created": "2016-07-07T20:23:24.302Z" "created": "2016-10-05T09:33:06.310Z"
}, },
"model": "representatives_votes.dossier", "model": "representatives_votes.dossier"
"pk": 1
}, },
{ {
"fields": { "fields": {
"text": "", "text": "",
"updated": "2016-07-07T20:23:24.365Z", "updated": "2016-10-05T09:33:06.325Z",
"title": "Collectivit\u00e9s territoriales : action publique territoriale et m\u00e9tropoles", "title": "Collectivit\u00e9s territoriales : action publique territoriale et m\u00e9tropoles",
"reference": "14/action_publique_territoriale_metropoles", "reference": "14/action_publique_territoriale_metropoles",
"created": "2016-07-07T20:23:24.332Z" "created": "2016-10-05T09:33:06.318Z"
}, },
"model": "representatives_votes.dossier", "model": "representatives_votes.dossier"
"pk": 2
}, },
{ {
"fields": { "fields": {
"text": "", "text": "",
"updated": "2016-07-07T20:23:24.410Z", "updated": "2016-10-05T09:33:06.338Z",
"title": "Protection de l'enfant", "title": "Protection de l'enfant",
"reference": "ppl13-799", "reference": "ppl13-799",
"created": "2016-07-07T20:23:24.410Z" "created": "2016-10-05T09:33:06.338Z"
}, },
"model": "representatives_votes.dossier", "model": "representatives_votes.dossier"
"pk": 3
}, },
{ {
"fields": { "fields": {
"updated": "2016-07-07T20:23:24.307Z", "updated": "2016-10-05T09:33:06.314Z",
"title": "", "title": "",
"dossier": 1, "dossier": [
"created": "2016-07-07T20:23:24.307Z", "14/liberte_maires_rythmes_scolaires_premier_degre"
],
"created": "2016-10-05T09:33:06.314Z",
"kind": "procedure-file", "kind": "procedure-file",
"chamber": 2, "chamber": [
"AN"
],
"link": "http://www.assemblee-nationale.fr/14/dossiers/liberte_maires_rythmes_scolaires_premier_degre.asp" "link": "http://www.assemblee-nationale.fr/14/dossiers/liberte_maires_rythmes_scolaires_premier_degre.asp"
}, },
"model": "representatives_votes.document", "model": "representatives_votes.document",
...@@ -65,12 +68,16 @@ ...@@ -65,12 +68,16 @@
}, },
{ {
"fields": { "fields": {
"updated": "2016-07-07T20:23:24.335Z", "updated": "2016-10-05T09:33:06.320Z",
"title": "", "title": "",
"dossier": 2, "dossier": [
"created": "2016-07-07T20:23:24.335Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:33:06.320Z",
"kind": "procedure-file", "kind": "procedure-file",
"chamber": 3, "chamber": [
"SEN"
],
"link": "http://www.senat.fr/dossier-legislatif/pjl12-495.html" "link": "http://www.senat.fr/dossier-legislatif/pjl12-495.html"
}, },
"model": "representatives_votes.document", "model": "representatives_votes.document",
...@@ -78,12 +85,16 @@ ...@@ -78,12 +85,16 @@
}, },
{ {
"fields": { "fields": {
"updated": "2016-07-07T20:23:24.371Z", "updated": "2016-10-05T09:33:06.332Z",
"title": "", "title": "",
"dossier": 2, "dossier": [
"created": "2016-07-07T20:23:24.371Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:33:06.331Z",
"kind": "procedure-file", "kind": "procedure-file",
"chamber": 2, "chamber": [
"AN"
],
"link": "http://www.assemblee-nationale.fr/14/dossiers/action_publique_territoriale_metropoles.asp" "link": "http://www.assemblee-nationale.fr/14/dossiers/action_publique_territoriale_metropoles.asp"
}, },
"model": "representatives_votes.document", "model": "representatives_votes.document",
...@@ -91,12 +102,16 @@ ...@@ -91,12 +102,16 @@
}, },
{ {
"fields": { "fields": {
"updated": "2016-07-07T20:23:24.415Z", "updated": "2016-10-05T09:33:06.342Z",
"title": "", "title": "",
"dossier": 3, "dossier": [
"created": "2016-07-07T20:23:24.415Z", "ppl13-799"
],
"created": "2016-10-05T09:33:06.342Z",
"kind": "procedure-file", "kind": "procedure-file",
"chamber": 3, "chamber": [
"SEN"
],
"link": "http://www.senat.fr/dossier-legislatif/ppl13-799.html" "link": "http://www.senat.fr/dossier-legislatif/ppl13-799.html"
}, },
"model": "representatives_votes.document", "model": "representatives_votes.document",
......
[ [
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.550Z", "updated": "2016-10-05T09:41:46.342Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740",
"title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9.", "title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9.",
"dossier": 1, "dossier": [
"created": "2016-02-14T13:44:37.550Z", "14/liberte_maires_rythmes_scolaires_premier_degre"
],
"created": "2016-10-05T09:41:46.342Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-04T23:00:00Z", "datetime": "2013-12-04T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 1
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.578Z", "updated": "2016-10-05T09:41:46.349Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740-2", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740-2",
"title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9. (1)", "title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9. (1)",
"dossier": 1, "dossier": [
"created": "2016-02-14T13:44:37.578Z", "14/liberte_maires_rythmes_scolaires_premier_degre"
],
"created": "2016-10-05T09:41:46.349Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-05T23:00:00Z", "datetime": "2013-12-05T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 2
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.587Z", "updated": "2016-10-05T09:41:46.363Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/748", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/748",
"title": "L'amendement n\u00b0 381 de m. dolez \u00e0 l'article 2 du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.", "title": "L'amendement n\u00b0 381 de m. dolez \u00e0 l'article 2 du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.",
"dossier": 2, "dossier": [
"created": "2016-02-14T13:44:37.587Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:41:46.363Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-10T23:00:00Z", "datetime": "2013-12-10T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 3
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.596Z", "updated": "2016-10-05T09:41:46.375Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/747", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/747",
"title": "L'amendement n\u00b0 379 de m. dolez \u00e0 l'article 1er a du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.", "title": "L'amendement n\u00b0 379 de m. dolez \u00e0 l'article 1er a du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.",
"dossier": 2, "dossier": [
"created": "2016-02-14T13:44:37.596Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:41:46.375Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-10T23:00:00Z", "datetime": "2013-12-10T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 4
} }
] ]
import copy
import os import os
import pytest
from django.core.serializers.json import Deserializer
from django.core.management import call_command from django.core.management import call_command
from representatives.models import Representative from representatives.models import Representative
from representatives.tests.base import TestBase
from representatives_votes.contrib.francedata import import_dossiers from representatives_votes.contrib.francedata import import_dossiers
from representatives_votes.contrib.francedata import import_scrutins from representatives_votes.contrib.francedata import import_scrutins
from representatives_votes.contrib.francedata import import_votes from representatives_votes.contrib.francedata import import_votes
...@@ -16,55 +14,39 @@ def _get_testdata(filename): ...@@ -16,55 +14,39 @@ def _get_testdata(filename):
return os.path.join(os.path.dirname(__file__), filename) return os.path.join(os.path.dirname(__file__), filename)
def _test_import(fixtures, scenario, callback): class FranceDataVotesTest(TestBase):
for model in (Representative, Dossier, Proposal, Vote): def _test_import(self, fixtures, scenario, callback):
model.objects.all().delete() for model in (Representative, Dossier, Proposal, Vote):
model.objects.all().delete()
for fix in fixtures: for fix in fixtures:
call_command('loaddata', fix) call_command('loaddata', fix)
inputfile = _get_testdata('%s_input.json' % scenario) inputfile = _get_testdata('%s_input.json' % scenario)
expected = _get_testdata('%s_expected.json' % scenario) expected = _get_testdata('%s_expected.json' % scenario)
# Disable django auto fields with open(inputfile, 'r') as f:
exclude = ('id', '_state', 'created', 'updated', 'fingerprint') callback(f)
with open(inputfile, 'r') as f: self.assertObjectsFromFixture(expected)
callback(f)
with open(expected, 'r') as f: def test_francedata_import_dossiers(self):
for obj in Deserializer(f.read()): fixtures = []
compare = copy.copy(obj.object.__dict__)
for f in exclude: self._test_import(fixtures, 'dossiers', import_dossiers.main)
if f in compare:
compare.pop(f)
type(obj.object).objects.get(**compare) def test_francedata_import_scrutins(self):
fixtures = [
_get_testdata('dossiers_expected.json')
]
self._test_import(fixtures, 'scrutins', import_scrutins.main)
@pytest.mark.django_db def test_francedata_import_votes(self):
def test_francedata_import_dossiers(): fixtures = [
fixtures = [] _get_testdata('dossiers_expected.json'),
_get_testdata('scrutins_expected.json'),
_get_testdata('rep_fixture.json')
]
_test_import(fixtures, 'dossiers', import_dossiers.main) self._test_import(fixtures, 'votes', import_votes.main)
@pytest.mark.django_db
def test_francedata_import_scrutins():
fixtures = [
_get_testdata('dossiers_expected.json')
]
_test_import(fixtures, 'scrutins', import_scrutins.main)
@pytest.mark.django_db
def test_francedata_import_votes():
fixtures = [
_get_testdata('dossiers_expected.json'),
_get_testdata('scrutins_expected.json'),
_get_testdata('rep_fixture.json')
]
_test_import(fixtures, 'votes', import_votes.main)
[ [
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.550Z", "updated": "2016-10-05T09:43:34.405Z",
"total_for": 1, "total_for": 1,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740",
"title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9.", "title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9.",
"dossier": 1, "dossier": [
"created": "2016-02-14T13:44:37.550Z", "14/liberte_maires_rythmes_scolaires_premier_degre"
],
"created": "2016-10-05T09:41:46.342Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-04T23:00:00Z", "datetime": "2013-12-04T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 1
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.578Z", "updated": "2016-10-05T09:43:34.427Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740-2", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/740-2",
"title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9. (1)", "title": "La motion de rejet pr\u00e9alable, pr\u00e9sent\u00e9e par m. le roux, de la proposition de loi permettant le libre choix des maires concernant les rythmes scolaires dans l'enseignement du premier degr\u00e9. (1)",
"dossier": 1, "dossier": [
"created": "2016-02-14T13:44:37.578Z", "14/liberte_maires_rythmes_scolaires_premier_degre"
],
"created": "2016-10-05T09:41:46.349Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-05T23:00:00Z", "datetime": "2013-12-05T23:00:00Z",
"total_against": 1, "total_against": 1,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 2
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.587Z", "updated": "2016-10-05T09:43:34.434Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/748", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/748",
"title": "L'amendement n\u00b0 381 de m. dolez \u00e0 l'article 2 du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.", "title": "L'amendement n\u00b0 381 de m. dolez \u00e0 l'article 2 du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.",
"dossier": 2, "dossier": [
"created": "2016-02-14T13:44:37.587Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:41:46.363Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-10T23:00:00Z", "datetime": "2013-12-10T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 1 "total_abstain": 1
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 3
}, },
{ {
"fields": { "fields": {
"updated": "2016-02-14T13:44:37.596Z", "updated": "2016-10-05T09:41:46.375Z",
"total_for": 0, "total_for": 0,
"description": "", "description": "",
"reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/747", "reference": "http://www.assemblee-nationale.fr/scrutins/detail/(legislature)/14/(num)/747",
"title": "L'amendement n\u00b0 379 de m. dolez \u00e0 l'article 1er a du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.", "title": "L'amendement n\u00b0 379 de m. dolez \u00e0 l'article 1er a du projet de loi de modernisation de l'action publique territoriale et d'affirmation des m\u00e9tropoles.",
"dossier": 2, "dossier": [
"created": "2016-02-14T13:44:37.596Z", "14/action_publique_territoriale_metropoles"
],
"created": "2016-10-05T09:41:46.375Z",
"kind": "dossier", "kind": "dossier",
"datetime": "2013-12-10T23:00:00Z", "datetime": "2013-12-10T23:00:00Z",
"total_against": 0, "total_against": 0,
"total_abstain": 0 "total_abstain": 0
}, },
"model": "representatives_votes.proposal", "model": "representatives_votes.proposal"
"pk": 4
}, },
{ {
"fields": { "fields": {