Commit e17a7d11 authored by Jamesie Pic's avatar Jamesie Pic
Browse files

Test upgrade

- use tox for reproductible test suite
- separate qa check in another job
- use django-dbdiff to remove technical debt
- upgrade django-responsediff, indent fixture json
parent 1e30571f
sudo: false
language: python
env:
- DJANGO="django>1.8,<1.9" DJANGO_SETTINGS_MODULE=representatives.tests.settings
matrix:
- TOXENV=py27-dj18
- TOXENV=qa
python:
- "2.7"
before_install:
- pip install codecov
install:
- pip install $DJANGO pep8 flake8 pytest-django pytest-cov codecov django-responsediff
- pip install -e .[api]
- pip install tox codecov
script:
- pep8 representatives/ --exclude migrations --ignore E128
- flake8 representatives/ --exclude migrations --ignore E128
- django-admin migrate
- cat representatives/contrib/francedata/tests/representatives_input.json | francedata_import_representatives
- cat representatives/contrib/parltrack/tests/representatives_fixture.json | parltrack_import_representatives
- py.test
- tox
after_success:
- codecov
import pytest
import os
import copy
from django.core.serializers.json import Deserializer
from representatives.models import Representative
from representatives.contrib.francedata import import_representatives
from representatives.tests.utils import ImportTestMixin
@pytest.mark.django_db
def test_francedata_import_representatives():
inputjson = os.path.join(os.path.dirname(__file__),
'representatives_input.json')
expected = os.path.join(os.path.dirname(__file__),
'representatives_expected.json')
from django import test
# Disable django auto fields
exclude = ('id', '_state', 'created', 'updated', 'fingerprint')
with open(inputjson, 'r') as f:
import_representatives.main(f)
from representatives.contrib.francedata import import_representatives
missing = []
with open(expected, 'r') as f:
for obj in Deserializer(f.read()):
compare = copy.copy(obj.object.__dict__)
for field in exclude:
if field in compare:
compare.pop(field)
class FrancedataImportTest(ImportTestMixin, test.TestCase):
dbdiff_expected = os.path.join(
'representatives',
'contrib',
'francedata',
'tests',
'representatives_expected.json',
)
try:
type(obj.object).objects.get(**compare)
except:
missing.append(compare)
def dbdiff_test(self):
fixture = os.path.join(
os.path.dirname(__file__),
'representatives_fixture.json'
)
assert len(missing) is 0
assert Representative.objects.count() == 2
with open(fixture, 'r') as f:
import_representatives.main(f)
import pytest
import os
import copy
from django.core.serializers.json import Deserializer
from representatives.models import Representative
from representatives.contrib.parltrack import import_representatives
from representatives.tests.utils import ImportTestMixin
@pytest.mark.django_db
def test_parltrack_import_representatives():
fixture = os.path.join(os.path.dirname(__file__),
'representatives_fixture.json')
expected = os.path.join(os.path.dirname(__file__),
'representatives_expected.json')
from django import test
# Disable django auto fields
exclude = ('id', '_state', 'created', 'updated', 'fingerprint')
with open(fixture, 'r') as f:
import_representatives.main(f)
from representatives.contrib.parltrack import import_representatives
missing = []
with open(expected, 'r') as f:
for obj in Deserializer(f.read()):
compare = copy.copy(obj.object.__dict__)
for field in exclude:
if field in compare:
compare.pop(field)
class ParltrackImportTest(ImportTestMixin, test.TestCase):
dbdiff_expected = os.path.join(
'representatives',
'contrib',
'parltrack',
'tests',
'representatives_expected.json',
)
try:
type(obj.object).objects.get(**compare)
except:
missing.append(compare)
def dbdiff_test(self):
fixture = os.path.join(
os.path.dirname(__file__),
'representatives_fixture.json'
)
assert len(missing) is 0
assert Representative.objects.count() == 2
with open(fixture, 'r') as f:
import_representatives.main(f)
[
{
"id": 1,
"name": "European Parliament",
"fingerprint": "bc0c3668435accfa5da4479c80478fe68d15ddb1"
},
{
"id": 2,
"name": "Österreichische Volkspartei",
"fingerprint": "74e9c77e0664716d098cb1194927b86f2aa55f7e"
},
{
"id": 3,
"name": "Arbetarepartiet- Socialdemokraterna",
"fingerprint": "a8fa2ff595aedee63954c3b5ad6e1dcd5dfac910"
}
]
\ No newline at end of file
{
"constituencies": "http://testserver/api/constituencies/",
"groups": "http://testserver/api/groups/",
"mandates": "http://testserver/api/mandates/",
"representatives": "http://testserver/api/representatives/"
}
\ No newline at end of file
[
{
"id": 6,
"name": "Austria",
"abbreviation": "AT",
"kind": "country",
"fingerprint": "7b37fb29f750421d82ee36539c2cb5bca9cef938"
},
{
"id": 8,
"name": "Committee on Economic and Monetary Affairs",
"abbreviation": "ECON",
"kind": "committee",
"fingerprint": "2da973401cd76bb56b36f3a9162cda13d2f2d8f3"
},
{
"id": 1,
"name": "Committee on Employment and Social Affairs",
"abbreviation": "EMPL",
"kind": "committee",
"fingerprint": "7f0e6d2c3342dde2c6077e127a418a19e0e891bb"
},
{
"id": 9,
"name": "Committee on Industry, Research and Energy",
"abbreviation": "ITRE",
"kind": "committee",
"fingerprint": "17ff1a9fe036e400612c9153c1647a8258c34d63"
},
{
"id": 7,
"name": "Conference of Delegation Chairs",
"abbreviation": "",
"kind": "organization",
"fingerprint": "eb99949bb40fd2e906d738eef276a912c5412f67"
},
{
"id": 12,
"name": "Delegation for relations with Australia and New Zealand",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "1e5d79317501c2fdf7f36846ad1d5491a244a103"
},
{
"id": 11,
"name": "Delegation for relations with Bosnia and Herzegovina, and Kosovo",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "3d2d9370cc501b1208a4692baf69deeab1e65d0a"
},
{
"id": 2,
"name": "Delegation for relations with the countries of Southeast Asia and the Association of Southeast Asian Nations (ASEAN)",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "23bb5f3e808b2ea6a02ddbe01705714ecfe7a82a"
},
{
"id": 3,
"name": "Delegation for relations with the Member States of ASEAN, South-east Asia and the Republic of Korea",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "3d0bc2c9506b90bb22e02e3866c1d14c9be1867e"
},
{
"id": 10,
"name": "Delegation to the EU-Serbia Stabilisation and Association Parliamentary Committee",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "a24b4e184cf25f0e300c07a1402b65243f5ba93d"
},
{
"id": 5,
"name": "Group of the European People's Party (Christian-Democratic Group)",
"abbreviation": "EPP",
"kind": "group",
"fingerprint": "669373eca233e4101a0af25debda58fdfd59741f"
},
{
"id": 4,
"name": "Group of the European People's Party (Christian Democrats) and European Democrats",
"abbreviation": "PPE-DE",
"kind": "group",
"fingerprint": "cab4a9a406aa114716967e6fd6e698dfd2421794"
},
{
"id": 13,
"name": "Group of the Progressive Alliance of Socialists and Democrats in the European Parliament",
"abbreviation": "SD",
"kind": "group",
"fingerprint": "729890eba3ce20f90808b32110871d1fe41b53b6"
},
{
"id": 14,
"name": "Sweden",
"abbreviation": "SE",
"kind": "country",
"fingerprint": "ea4cacc64af470d01e5b4da150b8b9d3a9dc4bfe"
}
]
\ No newline at end of file
{
"query_count": 1,
"status_code": 200
}
\ No newline at end of file
[
{
"id": 10,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "17ff1a9fe036e400612c9153c1647a8258c34d63",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Substitute",
"begin_date": "2014-07-08",
"end_date": "9999-12-31",
"fingerprint": "9d57bd7941ddda428728446908f8dd7aa642c764"
},
{
"id": 9,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "2da973401cd76bb56b36f3a9162cda13d2f2d8f3",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2014-07-01",
"end_date": "9999-12-31",
"fingerprint": "5323fd311cf0cb24122be532666fabb7ef23fa0c"
},
{
"id": 17,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "ea4cacc64af470d01e5b4da150b8b9d3a9dc4bfe",
"constituency": "a8fa2ff595aedee63954c3b5ad6e1dcd5dfac910",
"role": "",
"begin_date": "2014-07-01",
"end_date": "9999-12-31",
"fingerprint": "6058eddb2a4542a23de70a2528993eba09b5817a"
},
{
"id": 15,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "729890eba3ce20f90808b32110871d1fe41b53b6",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2014-07-01",
"end_date": "9999-12-31",
"fingerprint": "f5c73825add38bb2c5f8de70d88b9effa6d6527f"
},
{
"id": 13,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "3d2d9370cc501b1208a4692baf69deeab1e65d0a",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Substitute",
"begin_date": "2015-05-18",
"end_date": "9999-12-31",
"fingerprint": "b65a685d8e4144e36aff12b64bf6d835af1b95a5"
},
{
"id": 12,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "a24b4e184cf25f0e300c07a1402b65243f5ba93d",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2014-07-14",
"end_date": "9999-12-31",
"fingerprint": "20a93b100a172b29f9ec6c6f94a8faeb1754a075"
},
{
"id": 18,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "ea4cacc64af470d01e5b4da150b8b9d3a9dc4bfe",
"constituency": "a8fa2ff595aedee63954c3b5ad6e1dcd5dfac910",
"role": "",
"begin_date": "2009-07-14",
"end_date": "2014-06-30",
"fingerprint": "4d9c58327c6b94bdf8a01e5c4d1fbcf751abaf8f"
},
{
"id": 2,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "23bb5f3e808b2ea6a02ddbe01705714ecfe7a82a",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2013-10-09",
"end_date": "2014-06-30",
"fingerprint": "18613b505dc43a9a3055bf7aed2b2651246838f8"
},
{
"id": 16,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "729890eba3ce20f90808b32110871d1fe41b53b6",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2009-07-14",
"end_date": "2014-06-30",
"fingerprint": "5765a17282ede4b110bedd2af0b1e5cc87673e6e"
},
{
"id": 14,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "1e5d79317501c2fdf7f36846ad1d5491a244a103",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Substitute",
"begin_date": "2009-09-17",
"end_date": "2013-01-10",
"fingerprint": "681dac891286446feb02863db19826f079cfed12"
},
{
"id": 11,
"representative": "314d0f4c25af31bfa2a6b286838367994b902615",
"group": "2da973401cd76bb56b36f3a9162cda13d2f2d8f3",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Substitute",
"begin_date": "2009-07-16",
"end_date": "2012-01-18",
"fingerprint": "5953eb229dd3c0993c1af3654fa7dfc052614002"
},
{
"id": 8,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "eb99949bb40fd2e906d738eef276a912c5412f67",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "2006-03-21",
"end_date": "2009-07-13",
"fingerprint": "0926a8c1dbc827362c3eabfdca87a5b595706120"
},
{
"id": 6,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "7b37fb29f750421d82ee36539c2cb5bca9cef938",
"constituency": "74e9c77e0664716d098cb1194927b86f2aa55f7e",
"role": "",
"begin_date": "1999-07-20",
"end_date": "2004-07-19",
"fingerprint": "d761586241fb47f9fae7035365f5253cd8a363fb"
},
{
"id": 4,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "cab4a9a406aa114716967e6fd6e698dfd2421794",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "1999-07-20",
"end_date": "2004-07-19",
"fingerprint": "1d054cac567dd5bc523ddf2063dd05971d7b9c88"
},
{
"id": 5,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "669373eca233e4101a0af25debda58fdfd59741f",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "1996-11-11",
"end_date": "1999-07-19",
"fingerprint": "0cfeaa28bfa4036f385bd7d81f29be83120fc985"
},
{
"id": 1,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "7f0e6d2c3342dde2c6077e127a418a19e0e891bb",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Substitute",
"begin_date": "1997-01-16",
"end_date": "1999-07-19",
"fingerprint": "9d2cdb45658e7b535e4b39de233b8e2f747bc1d1"
},
{
"id": 7,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "7b37fb29f750421d82ee36539c2cb5bca9cef938",
"constituency": "74e9c77e0664716d098cb1194927b86f2aa55f7e",
"role": "",
"begin_date": "1996-11-11",
"end_date": "1999-07-19",
"fingerprint": "5e7d170fc24b161457a09baebcc388edcbddc954"
},
{
"id": 3,
"representative": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"group": "3d0bc2c9506b90bb22e02e3866c1d14c9be1867e",
"constituency": "bc0c3668435accfa5da4479c80478fe68d15ddb1",
"role": "Member",
"begin_date": "1996-11-14",
"end_date": "1997-01-15",
"fingerprint": "fd6db1f22987be42ba290e1f8fbfda6cc109dd7e"
}
]
\ No newline at end of file
{
"query_count": 1,
"status_code": 200
}
\ No newline at end of file
{
"query_count": 0,
"status_code": 200
}
\ No newline at end of file
{
"id": 1,
"slug": "hubert-pirker",
"remote_id": "2307",
"first_name": "Hubert",
"last_name": "PIRKER",
"full_name": "Hubert PIRKER",
"gender": 2,
"birth_place": "Gries",
"birth_date": "1948-10-03",
"photo": "http://www.europarl.europa.eu/mepphoto/2307.jpg",
"active": false,
"cv": "Transport and security spokesman, ÖVP Delegation, European Parliament;\nsecurity spokesman, ÖVP Delegation, European Parliament (2006-2009); security spokesman (coordinator), EPP Group (1999-2004); Deputy Head of ÖVP Delegation, European Parliament (1996-2004);",
"contacts": {
"emails": [],
"phones": [],
"websites": [],
"address": []
},
"fingerprint": "2a3c90346d40e9c540050534d832ceb3e0d25a49",
"url": "http://testserver/api/representatives/1/",
"mandates": [
{
"id": 2,
"group": {
"id": 2,
"name": "Delegation for relations with the countries of Southeast Asia and the Association of Southeast Asian Nations (ASEAN)",
"abbreviation": "",
"kind": "delegation",
"fingerprint": "23bb5f3e808b2ea6a02ddbe01705714ecfe7a82a"
},
"constituency": {
"id": 1,
"name": "European Parliament",
"fingerprint": "bc0c3668435accfa5da4479c80478fe68d15ddb1"
},
"role": "Member",
"begin_date": "2013-10-09",
"end_date": "2014-06-30",
"fingerprint": "18613b505dc43a9a3055bf7aed2b2651246838f8"
},
{
"id": 8,
"group": {
"id": 7,
"name": "Conference of Delegation Chairs",
"abbreviation": "",
"kind": "organization",
"fingerprint": "eb99949bb40fd2e906d738eef276a912c5412f67"
},
"constituency": {
"id": 1,
"name": "European Parliament",
"fingerprint": "bc0c3668435accfa5da4479c80478fe68d15ddb1"
},
"role": "Member",
"begin_date": "2006-03-21",
"end_date": "2009-07-13",
"fingerprint": "0926a8c1dbc827362c3eabfdca87a5b595706120"
},
{
"id": 4,
"group": {
"id": 4,
"name": "Group of the European People's Party (Christian Democrats) and European Democrats",
"abbreviation": "PPE-DE",
"kind": "group",
"fingerprint": "cab4a9a406aa114716967e6fd6e698dfd2421794"
},
"constituency": {
"id": 1,
"name": "European Parliament",
"fingerprint": "bc0c3668435accfa5da4479c80478fe68d15ddb1"
},
"role": "Member",
"begin_date": "1999-07-20",
"end_date": "2004-07-19",
"fingerprint": "1d054cac567dd5bc523ddf2063dd05971d7b9c88"
},
{
"id": 6,
"group": {
"id": 6,
"name": "Austria",
"abbreviation": "AT",
"kind": "country",
"fingerprint": "7b37fb29f750421d82ee36539c2cb5bca9cef938"
},
"constituency": {
"id": 2,
"name": "Österreichische Volkspartei",
"fingerprint": "74e9c77e0664716d098cb1194927b86f2aa55f7e"
},
"role": "",
"begin_date": "1999-07-20",
"end_date": "2004-07-19",
"fingerprint": "d761586241fb47f9fae7035365f5253cd8a363fb"
},
{
"id": 5,
"group": {
"id": 5,