1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# See the file COPYING for details.
"""
Unit tests
"""
import json, os
from django.core.management import call_command
from django.test import TestCase
from django.contrib.auth.models import User
import models
from ishtar_common.models import OrganizationType, Organization, Town
class ImportOperationTest(TestCase):
fixtures = ['../ishtar_common/fixtures/initial_data.json',
'../archaeological_files/fixtures/initial_data.json',
'../archaeological_operations/fixtures/initial_data-fr.json']
def setUp(self):
user = User.objects.create_user('username')
def testImportDbfOperation(self):
"""
Test operation import
"""
call_command('import_operations', os.sep.join([os.getcwd(), '..',
'archaeological_operations', 'tests', 'sample.dbf']))
def testImportCsvOperation(self):
"""
Test operation import
"""
call_command('import_operations', os.sep.join([os.getcwd(), '..',
'archaeological_operations', 'tests', 'sample.csv']))
def testParseParcels(self):
# the database needs to be initialised before importing
from archaeological_operations.import_from_csv import parse_parcels
default_town = Town.objects.create(numero_insee="12345",
name="default_town")
test_values = (
("1996 : XT:53,54,56,57,59,60,61,62",
{1996:[
("XT", "53"),
("XT", "54"),
("XT", "56"),
("XT", "57"),
("XT", "59"),
("XT", "60"),
("XT", "61"),
("XT", "62"),
]}),
("AD:23",
{None:[
("AD", "23")
]}),
("1961 :B1:227;", {}
),("1982 CV:35;CV:36", {}
),("E:24;E:25", {}
),("B : 375, 376, 386, 387, 645, 646 / C : 412 à 415, 432 à 435, 622 / F : 120, 149, 150, 284, 287, 321 à 323", {}
),("AD : 95, 96, 86, 87, 81, 252, AE : 58, AD : 115 à 132", {}
),("XD:1 à 13, 24 à 28, 33 à 39, 50 à 52, 80, 83, 84 à 86, 259 à 261, 182, 225 ; XH:5 ; P:1640, 1888, 1889, 1890 ; R:1311, 1312, 1314, 1342, 1343, 1559 à 1569", {}
),("BZ:2 à 5, 365 ; CD:88 à 104, 106, 108, 326", {}
),("AV 118 à 125, 127, 132 à 137, 153, 398p, 399, 402; BI 27, 30, 32, 33, 188, 255, 256 à 258, 260, 284p, 294; BL 297", {}
),("A : 904 à 906, 911 ; E:40, 41", {}
),("1991 : BE:8, 12", {}
),("AB 37 et 308", {}
),("1979 : EM:1", {}
),("B:448;B:449;B:450;B:451;B:452;B:455;B:456;B:457;B:458;B:459;B:1486;", {}
),("AC : 72 à 81, 91 à 100, 197 / ZC:180 à 189", {}
),("A : 1195, 1203 à 1208, 1338 ; ZC : 11 à 13, 16, 18, 22, 23, 25 à 31, 45, 82, 103, 107, 109 ; ZA : 2 à 8, 10, 11, 34 à 36, 49 à 41, 57, 58, Z:21", {}
),("1983 D2 n° 458 et 459", {}
),("ZS : 21p, 66", {}
),("VV:166, 167, domaine public", {}
),("Domaine public", {}
),("Tranche 1 : AV:4 à 6, 18, 80, 104 / partiellement : 5 et 18", {}
),(" AS:13 à 15, 17 à 19, 21 à 32, 34 à 45, 47 à 53, 69, 70, 82, 84 / CK:1, 24, 25, 29, 30, 37 à 43", {}
),(" ZE, 16, 17, 83, 10, 18, 82, 9, 73, 76, 77, 79, 80, 84, 78 et 81", {}
),(" ZN:37, 15, 35, 28, 29 / ZM:9, 73", {}
),("A:26a, 26b, 27 / AB:95 / AK:4, 12, 20", {}
),(" Tranche n°1 : YP:243, 12, 14 à 16, 18 à 26, DP / Tranche n°2 : YP:17, 307, 27, 308, 44 à 46, 683, BM:1, 250, 488 à 492", {}
),(" 1987 : ZD: ?", {}
),(" H : 106, 156, 158", {}
))
for value, result in test_values:
parcels = parse_parcels("12345", value, None)
"""
self.assertTrue(parcels != [])
parcels_copy = parcels[:]
for year in result.keys():
for parcel in parcels_copy:
if parcel.year != year:
continue
self.assertTrue((parcel.section, parcel.parcel_number)
in result[year])
parcel.pop(parcel.index(parcel))
# all parcels have been imported
self.assertEqual(parcels, [])
"""
|