hdo-storting-importer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +16 -0
- data/.gitmodules +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/LICENSE +20 -0
- data/README.md +14 -0
- data/Rakefile +11 -0
- data/bin/hdo-converter +7 -0
- data/features/import.feature +85 -0
- data/features/step_definitions/import_steps.rb +0 -0
- data/features/support/env.rb +7 -0
- data/hdo-storting-importer.gemspec +17 -0
- data/lib/hdo/storting_importer/api_data_source.rb +62 -0
- data/lib/hdo/storting_importer/category.rb +55 -0
- data/lib/hdo/storting_importer/cli.rb +141 -0
- data/lib/hdo/storting_importer/committee.rb +35 -0
- data/lib/hdo/storting_importer/converter.rb +45 -0
- data/lib/hdo/storting_importer/core_ext/enumerable.rb +12 -0
- data/lib/hdo/storting_importer/data_source.rb +22 -0
- data/lib/hdo/storting_importer/disk_data_source.rb +61 -0
- data/lib/hdo/storting_importer/district.rb +36 -0
- data/lib/hdo/storting_importer/issue.rb +90 -0
- data/lib/hdo/storting_importer/ivar_equality.rb +22 -0
- data/lib/hdo/storting_importer/parsing_data_source.rb +59 -0
- data/lib/hdo/storting_importer/party.rb +31 -0
- data/lib/hdo/storting_importer/promise.rb +49 -0
- data/lib/hdo/storting_importer/promise_converter.rb +48 -0
- data/lib/hdo/storting_importer/representative.rb +106 -0
- data/lib/hdo/storting_importer/script_importer.rb +20 -0
- data/lib/hdo/storting_importer/util.rb +26 -0
- data/lib/hdo/storting_importer/version.rb +5 -0
- data/lib/hdo/storting_importer/vote.rb +171 -0
- data/lib/hdo/storting_importer.rb +41 -0
- data/spec/fixtures/input/categories.xml +1351 -0
- data/spec/fixtures/input/committees.xml +92 -0
- data/spec/fixtures/input/districts.xml +101 -0
- data/spec/fixtures/input/issues.xml +2852 -0
- data/spec/fixtures/input/parties.xml +42 -0
- data/spec/fixtures/input/promises-a.csv +341 -0
- data/spec/fixtures/input/propositions_2175.xml +64 -0
- data/spec/fixtures/input/propositions_2176.xml +64 -0
- data/spec/fixtures/input/representatives.xml +3218 -0
- data/spec/fixtures/input/representatives_today.xml +4872 -0
- data/spec/fixtures/input/vote_results_2175.xml +4400 -0
- data/spec/fixtures/input/vote_results_2176.xml +4400 -0
- data/spec/fixtures/input/votes.xml +85 -0
- data/spec/fixtures/output/categories.xml +803 -0
- data/spec/fixtures/output/committees.xml +71 -0
- data/spec/fixtures/output/districts.xml +79 -0
- data/spec/fixtures/output/issues.xml +836 -0
- data/spec/fixtures/output/parties.xml +31 -0
- data/spec/fixtures/output/promises-a.xml +3224 -0
- data/spec/fixtures/output/representatives.xml +2567 -0
- data/spec/fixtures/output/votes.xml +4899 -0
- data/spec/hdo/storting_importer/category_spec.rb +76 -0
- data/spec/hdo/storting_importer/committee_spec.rb +46 -0
- data/spec/hdo/storting_importer/converter_spec.rb +72 -0
- data/spec/hdo/storting_importer/district_spec.rb +54 -0
- data/spec/hdo/storting_importer/issue_spec.rb +115 -0
- data/spec/hdo/storting_importer/party_spec.rb +52 -0
- data/spec/hdo/storting_importer/promise_spec.rb +38 -0
- data/spec/hdo/storting_importer/representative_spec.rb +81 -0
- data/spec/hdo/storting_importer/vote_spec.rb +155 -0
- data/spec/spec_helper.rb +39 -0
- metadata +145 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe Category do
|
7
|
+
|
8
|
+
it 'builds categories from Storting XML list' do
|
9
|
+
xml = <<-XML
|
10
|
+
<?xml version="1.0" encoding="utf-8"?>
|
11
|
+
<emne_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
12
|
+
<versjon>1.0</versjon>
|
13
|
+
<emne_liste>
|
14
|
+
<emne>
|
15
|
+
<versjon>1.0</versjon>
|
16
|
+
<er_hovedemne>true</er_hovedemne>
|
17
|
+
<id>5</id>
|
18
|
+
<navn>ARBEIDSLIV</navn>
|
19
|
+
<underemne_liste>
|
20
|
+
<emne>
|
21
|
+
<versjon>1.0</versjon>
|
22
|
+
<er_hovedemne>false</er_hovedemne>
|
23
|
+
<id>205</id>
|
24
|
+
<navn>ARBEIDSMILJØ</navn>
|
25
|
+
<underemne_liste />
|
26
|
+
</emne>
|
27
|
+
</underemne_liste>
|
28
|
+
</emne>
|
29
|
+
</emne_liste>
|
30
|
+
</emne_oversikt>
|
31
|
+
XML
|
32
|
+
|
33
|
+
categories = Category.from_storting_doc(parse(xml))
|
34
|
+
categories.size.should == 1
|
35
|
+
|
36
|
+
cat = categories.first
|
37
|
+
cat.name.should == "ARBEIDSLIV"
|
38
|
+
cat.external_id.should == "5"
|
39
|
+
|
40
|
+
cat.children.size.should == 1
|
41
|
+
cat.children.first.name.should == "ARBEIDSMILJØ"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can serialize as HDO XML" do
|
45
|
+
category = Category.new("5", "ARBEIDSLIV")
|
46
|
+
category.children << Category.new("205", "ARBEIDSMILJØ")
|
47
|
+
category.children << Category.new("94", "ARBEIDSVILKÅR")
|
48
|
+
|
49
|
+
category.to_hdo_xml.should == <<-XML
|
50
|
+
<category>
|
51
|
+
<externalId>5</externalId>
|
52
|
+
<name>ARBEIDSLIV</name>
|
53
|
+
<subcategories>
|
54
|
+
<category>
|
55
|
+
<externalId>205</externalId>
|
56
|
+
<name>ARBEIDSMILJØ</name>
|
57
|
+
</category>
|
58
|
+
<category>
|
59
|
+
<externalId>94</externalId>
|
60
|
+
<name>ARBEIDSVILKÅR</name>
|
61
|
+
</category>
|
62
|
+
</subcategories>
|
63
|
+
</category>
|
64
|
+
XML
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can deserialize HDO XML' do
|
68
|
+
orig = Category.new("5", "ARBEIDSLIV")
|
69
|
+
orig.children << Category.new("3", "LØNN")
|
70
|
+
|
71
|
+
Category.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe Committee do
|
7
|
+
|
8
|
+
it 'builds committees from Storting XML list' do
|
9
|
+
xml = <<-XML
|
10
|
+
<?xml version="1.0" encoding="utf-8"?>
|
11
|
+
<komiteer_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
12
|
+
<versjon>1.0</versjon>
|
13
|
+
<komiteer_liste>
|
14
|
+
<komite>
|
15
|
+
<versjon>1.0</versjon>
|
16
|
+
<id>ARBSOS</id>
|
17
|
+
<navn>Arbeids- og sosialkomiteen</navn>
|
18
|
+
</komite>
|
19
|
+
</komiteer_liste>
|
20
|
+
</komiteer_oversikt>
|
21
|
+
XML
|
22
|
+
|
23
|
+
committees = Committee.from_storting_doc(parse(xml))
|
24
|
+
committees.size.should == 1
|
25
|
+
committees.first.name.should == 'Arbeids- og sosialkomiteen'
|
26
|
+
committees.first.external_id.should == "ARBSOS"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can serialize as HDO XML' do
|
30
|
+
Committee.new("ARBSOS", 'Arbeids- og sosialkomiteen').to_hdo_xml.should == <<-XML
|
31
|
+
<committee>
|
32
|
+
<externalId>ARBSOS</externalId>
|
33
|
+
<name>Arbeids- og sosialkomiteen</name>
|
34
|
+
</committee>
|
35
|
+
XML
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can deserialize HDO XML' do
|
39
|
+
com = Committee.new("ARBSOS", 'Arbeids- og sosialkomiteen')
|
40
|
+
Committee.from_hdo_node(parse(com.to_hdo_xml)).should == com
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hdo
|
4
|
+
module StortingImporter
|
5
|
+
module Converters
|
6
|
+
|
7
|
+
describe Converter do
|
8
|
+
let(:data_source) { DataSource.new }
|
9
|
+
let(:parsing_data_source) { ParsingDataSource.new(data_source) }
|
10
|
+
let(:converter) { Converter.new(parsing_data_source) }
|
11
|
+
|
12
|
+
def input_for(name)
|
13
|
+
doc = Nokogiri::XML.parse input_fixture(name)
|
14
|
+
doc.remove_namespaces!
|
15
|
+
|
16
|
+
doc
|
17
|
+
end
|
18
|
+
|
19
|
+
def output_for(name)
|
20
|
+
output_fixture(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
[
|
24
|
+
:parties,
|
25
|
+
:committees,
|
26
|
+
:districts,
|
27
|
+
:categories,
|
28
|
+
:issues,
|
29
|
+
].each { |name|
|
30
|
+
it "converts #{name}" do
|
31
|
+
data_source.should_receive(name).and_return(input_for(name))
|
32
|
+
|
33
|
+
actual_output = converter.xml_for(name)
|
34
|
+
actual_output.should == output_for(name)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
|
38
|
+
it "converts representatives" do
|
39
|
+
data_source.should_receive(:representatives).and_return(input_for(:representatives))
|
40
|
+
data_source.should_receive(:representatives_today).and_return(input_for(:representatives_today))
|
41
|
+
|
42
|
+
actual = converter.xml_for(:representatives)
|
43
|
+
expected = output_for(:representatives)
|
44
|
+
|
45
|
+
actual.should == expected
|
46
|
+
end
|
47
|
+
|
48
|
+
it "converts votes" do
|
49
|
+
parsing_data_source.should_receive(:issues).and_return [mock(:external_id => 2175)]
|
50
|
+
|
51
|
+
data_source.should_receive(:votes_for).and_return(input_for(:votes))
|
52
|
+
|
53
|
+
data_source.should_receive(:propositions_for).with('2175').and_return(input_for(:propositions_2175))
|
54
|
+
data_source.should_receive(:vote_results_for).with('2175').and_return(input_for(:vote_results_2175))
|
55
|
+
|
56
|
+
data_source.should_receive(:propositions_for).with('2176').and_return(input_for(:propositions_2176))
|
57
|
+
data_source.should_receive(:vote_results_for).with('2176').and_return(input_for(:vote_results_2176))
|
58
|
+
|
59
|
+
actual = converter.xml_for(:votes)
|
60
|
+
expected = output_for(:votes)
|
61
|
+
|
62
|
+
actual.should == expected
|
63
|
+
end
|
64
|
+
|
65
|
+
it "converts promises" do
|
66
|
+
PromiseConverter.new(input_path('promises-a.csv')).xml.should == output_path('promises-a.xml').read
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe District do
|
7
|
+
|
8
|
+
it 'builds committees from Storting XML list' do
|
9
|
+
xml = <<-XML
|
10
|
+
<?xml version="1.0" encoding="utf-8"?>
|
11
|
+
<fylker_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
12
|
+
<versjon>1.0</versjon>
|
13
|
+
<fylker_liste>
|
14
|
+
<fylke>
|
15
|
+
<versjon>1.0</versjon>
|
16
|
+
<id>Ak</id>
|
17
|
+
<navn>Akershus</navn>
|
18
|
+
</fylke>
|
19
|
+
<fylke>
|
20
|
+
<versjon>1.0</versjon>
|
21
|
+
<id>Bu</id>
|
22
|
+
<navn>Buskerud</navn>
|
23
|
+
</fylke>
|
24
|
+
</fylker_liste>
|
25
|
+
</fylker_oversikt>
|
26
|
+
XML
|
27
|
+
|
28
|
+
districts = District.from_storting_doc(parse(xml))
|
29
|
+
districts.size.should == 2
|
30
|
+
|
31
|
+
district = districts.first
|
32
|
+
|
33
|
+
district.name.should == 'Akershus'
|
34
|
+
district.external_id.should == 'Ak'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can serialize as HDO XML' do
|
38
|
+
District.new("Ak", "Akershus").to_hdo_xml.should == <<-XML
|
39
|
+
<district>
|
40
|
+
<externalId>Ak</externalId>
|
41
|
+
<name>Akershus</name>
|
42
|
+
</district>
|
43
|
+
XML
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can deserialize HDO XML' do
|
47
|
+
orig = District.new("Ak", "Akershus")
|
48
|
+
District.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe Issue do
|
7
|
+
|
8
|
+
def create_issue
|
9
|
+
Issue.new(
|
10
|
+
"53520",
|
11
|
+
"Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
|
12
|
+
"Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
|
13
|
+
"alminneligsak",
|
14
|
+
"mottatt",
|
15
|
+
"2012-04-20T00:00:00",
|
16
|
+
"Prop. 90 S (2011-2012)",
|
17
|
+
"proposisjon",
|
18
|
+
"Transport- og kommunikasjonskomiteen",
|
19
|
+
['UTENRIKSSAKER', 'TRAKTATER', 'NORDISK SAMARBEID']
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'builds issues from Storting XML list' do
|
24
|
+
xml = <<-XML
|
25
|
+
<?xml version="1.0" encoding="utf-8"?>
|
26
|
+
<saker_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
27
|
+
<versjon>1.0</versjon>
|
28
|
+
<saker_liste>
|
29
|
+
<sak>
|
30
|
+
<versjon>1.0</versjon>
|
31
|
+
<behandlet_sesjon_id i:nil="true" />
|
32
|
+
<dokumentgruppe>proposisjon</dokumentgruppe>
|
33
|
+
<emne_liste>
|
34
|
+
<emne>
|
35
|
+
<versjon>1.0</versjon>
|
36
|
+
<er_hovedemne>true</er_hovedemne>
|
37
|
+
<id>163</id>
|
38
|
+
<navn>UTENRIKSSAKER</navn>
|
39
|
+
<underemne_liste />
|
40
|
+
</emne>
|
41
|
+
<emne>
|
42
|
+
<versjon>1.0</versjon>
|
43
|
+
<er_hovedemne>false</er_hovedemne>
|
44
|
+
<id>166</id>
|
45
|
+
<navn>TRAKTATER</navn>
|
46
|
+
<underemne_liste />
|
47
|
+
</emne>
|
48
|
+
<emne>
|
49
|
+
<versjon>1.0</versjon>
|
50
|
+
<er_hovedemne>false</er_hovedemne>
|
51
|
+
<id>171</id>
|
52
|
+
<navn>NORDISK SAMARBEID</navn>
|
53
|
+
<underemne_liste />
|
54
|
+
</emne>
|
55
|
+
</emne_liste>
|
56
|
+
<henvisning>Prop. 90 S (2011-2012)</henvisning>
|
57
|
+
<id>53520</id>
|
58
|
+
<innstilling_id>-1</innstilling_id>
|
59
|
+
<komite i:nil="true" />
|
60
|
+
<korttittel>Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</korttittel>
|
61
|
+
<sak_fremmet_id>53520</sak_fremmet_id>
|
62
|
+
<saksordfoerer_liste />
|
63
|
+
<sist_oppdatert_dato>2012-04-20T00:00:00</sist_oppdatert_dato>
|
64
|
+
<status>mottatt</status>
|
65
|
+
<tittel>Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</tittel>
|
66
|
+
<type>alminneligsak</type>
|
67
|
+
</sak>
|
68
|
+
</saker_liste>
|
69
|
+
</saker_oversikt>
|
70
|
+
XML
|
71
|
+
|
72
|
+
issues = Issue.from_storting_doc(parse(xml))
|
73
|
+
issues.size.should == 1
|
74
|
+
|
75
|
+
issue = issues.first
|
76
|
+
issue.document_group.should == 'proposisjon'
|
77
|
+
issue.categories.should == ['UTENRIKSSAKER', 'TRAKTATER', 'NORDISK SAMARBEID']
|
78
|
+
issue.reference.should == 'Prop. 90 S (2011-2012)'
|
79
|
+
issue.external_id.should == '53520'
|
80
|
+
issue.summary.should == 'Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)'
|
81
|
+
issue.last_update.should == '2012-04-20T00:00:00'
|
82
|
+
issue.status.should == 'mottatt'
|
83
|
+
issue.description.should == 'Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)'
|
84
|
+
issue.type.should == 'alminneligsak'
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can serialize as HDO XML' do
|
88
|
+
create_issue.to_hdo_xml.should == <<-XML
|
89
|
+
<issue>
|
90
|
+
<externalId>53520</externalId>
|
91
|
+
<summary>Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</summary>
|
92
|
+
<description>Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)</description>
|
93
|
+
<type>alminneligsak</type>
|
94
|
+
<status>mottatt</status>
|
95
|
+
<lastUpdate>2012-04-20T00:00:00</lastUpdate>
|
96
|
+
<reference>Prop. 90 S (2011-2012)</reference>
|
97
|
+
<documentGroup>proposisjon</documentGroup>
|
98
|
+
<committee>Transport- og kommunikasjonskomiteen</committee>
|
99
|
+
<categories>
|
100
|
+
<category>UTENRIKSSAKER</category>
|
101
|
+
<category>TRAKTATER</category>
|
102
|
+
<category>NORDISK SAMARBEID</category>
|
103
|
+
</categories>
|
104
|
+
</issue>
|
105
|
+
XML
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'can deserialize HDO XML' do
|
109
|
+
orig = create_issue
|
110
|
+
Issue.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe Party do
|
7
|
+
|
8
|
+
it 'builds parties from Storting XML list' do
|
9
|
+
xml = <<-XML
|
10
|
+
<?xml version="1.0" encoding="utf-8"?>
|
11
|
+
<partier_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
12
|
+
<versjon>1.0</versjon>
|
13
|
+
<partier_liste>
|
14
|
+
<parti>
|
15
|
+
<versjon>1.0</versjon>
|
16
|
+
<id>A</id>
|
17
|
+
<navn>Arbeiderpartiet</navn>
|
18
|
+
</parti>
|
19
|
+
<parti>
|
20
|
+
<versjon>1.0</versjon>
|
21
|
+
<id>FrP</id>
|
22
|
+
<navn>Fremskrittspartiet</navn>
|
23
|
+
</parti>
|
24
|
+
</partier_liste>
|
25
|
+
</partier_oversikt>
|
26
|
+
XML
|
27
|
+
|
28
|
+
parties = Party.from_storting_doc(parse(xml))
|
29
|
+
parties.size.should == 2
|
30
|
+
|
31
|
+
parties.map(&:external_id).should == ['A', 'FrP']
|
32
|
+
parties.map(&:name).should == ['Arbeiderpartiet', 'Fremskrittspartiet']
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can serialize as HDO XML' do
|
36
|
+
Party.new("A", "Arbeiderpartiet").to_hdo_xml.should == <<-XML
|
37
|
+
<party>
|
38
|
+
<externalId>A</externalId>
|
39
|
+
<name>Arbeiderpartiet</name>
|
40
|
+
</party>
|
41
|
+
XML
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can deserialize HDO XML' do
|
45
|
+
orig = Party.new('Sp', 'Senterpartiet')
|
46
|
+
Party.from_hdo_node(parse(orig.to_hdo_xml)).should == orig
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Hdo
|
5
|
+
module StortingImporter
|
6
|
+
describe Promise do
|
7
|
+
|
8
|
+
it 'builds promises from CSV' do
|
9
|
+
csv = <<-CSV
|
10
|
+
Parti;Løftetekst;Generell;Emner;Kilde;Side
|
11
|
+
A;Ha et inntektspolitisk samarbeid og en økonomisk politikk som sikrer arbeid til alle. ;Ja;LØNN , SYSSELSETTING;PP;10
|
12
|
+
A;Følge handlingsregelen for en forsvarlig bruk av oljepenger.;Ja;FINANSER;PP;10
|
13
|
+
A;Bruke penger slik at det bidrar til å utjevne svingninger i økonomien.;Ja;FINANSER;PP;10
|
14
|
+
A;Sette ned et utvalg som skal gjennomgå årsakene til finanskrisen.;Nei;FINANSER;PP;10
|
15
|
+
A;Gjennomføre de tiltak som er nødvendig for å sikre et stabilt og fungerende finansmarked.;Ja;FINANSER;PP;10
|
16
|
+
A;Stille etiske krav til forvaltning av statlig kapital. ;Ja;FINANSER;PP;10
|
17
|
+
A;Holde de samlede skattene og avgiftene på samme nivå som i dag.;Nei;SKATTER;PP;10
|
18
|
+
A;Ha en grundig evaluering av skattereformen av 2006, med særlig blikk på fordelingsvirkningene. ;Ja;SKATTER;PP;10
|
19
|
+
A;Opprettholde formueskatten, men gjøre den mer rettferdig.;Ja;SKATTER;PP;10
|
20
|
+
CSV
|
21
|
+
|
22
|
+
|
23
|
+
promises = Promise.from_csv(csv)
|
24
|
+
|
25
|
+
promises.size.should == 9
|
26
|
+
|
27
|
+
prom = promises.first
|
28
|
+
prom.party.should == 'A'
|
29
|
+
prom.body.should == 'Ha et inntektspolitisk samarbeid og en økonomisk politikk som sikrer arbeid til alle.'
|
30
|
+
prom.general.should be_true
|
31
|
+
prom.categories.should == %w[LØNN SYSSELSETTING]
|
32
|
+
prom.source.should == "PP"
|
33
|
+
prom.page.should == '10'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Hdo
|
4
|
+
module StortingImporter
|
5
|
+
describe Representative do
|
6
|
+
|
7
|
+
def create_representative
|
8
|
+
Representative.new('ADA', 'André Oktay', 'Dahl', 'M', '1975-07-07T00:00:00', '0001-01-01T00:00:00', 'Akershus', 'Høyre', ['Justiskomiteen'], '2011-2012')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "builds representatives from the Storting XML list" do
|
12
|
+
xml = <<-XML
|
13
|
+
<?xml version="1.0" encoding="utf-8"?>
|
14
|
+
<representanter_oversikt xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://data.stortinget.no">
|
15
|
+
<versjon>1.0</versjon>
|
16
|
+
<representanter_liste>
|
17
|
+
<representant>
|
18
|
+
<versjon>1.0</versjon>
|
19
|
+
<doedsdato>0001-01-01T00:00:00</doedsdato>
|
20
|
+
<etternavn>Dahl</etternavn>
|
21
|
+
<foedselsdato>1975-07-07T00:00:00</foedselsdato>
|
22
|
+
<fornavn>André Oktay</fornavn>
|
23
|
+
<id>ADA</id>
|
24
|
+
<kjoenn>mann</kjoenn>
|
25
|
+
<fylke>
|
26
|
+
<versjon>1.0</versjon>
|
27
|
+
<id>Ak</id>
|
28
|
+
<navn>Akershus</navn>
|
29
|
+
</fylke>
|
30
|
+
<parti>
|
31
|
+
<versjon>1.0</versjon>
|
32
|
+
<id>H</id>
|
33
|
+
<navn>Høyre</navn>
|
34
|
+
</parti>
|
35
|
+
</representant>
|
36
|
+
</representanter_liste>
|
37
|
+
</representanter_oversikt>
|
38
|
+
XML
|
39
|
+
|
40
|
+
representatives = Representative.from_storting_doc(parse(xml))
|
41
|
+
representatives.size.should == 1
|
42
|
+
|
43
|
+
rep = representatives.first
|
44
|
+
rep.first_name.should == 'André Oktay'
|
45
|
+
rep.last_name.should == 'Dahl'
|
46
|
+
rep.gender.should == 'M'
|
47
|
+
rep.district.should == 'Akershus'
|
48
|
+
rep.party.should == 'Høyre'
|
49
|
+
rep.external_id.should == 'ADA'
|
50
|
+
rep.date_of_birth.should == '1975-07-07T00:00:00'
|
51
|
+
rep.date_of_death.should == '0001-01-01T00:00:00'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'converts itself into HDO XML' do
|
55
|
+
rep = create_representative
|
56
|
+
rep.to_hdo_xml.should == <<-XML
|
57
|
+
<representative>
|
58
|
+
<externalId>ADA</externalId>
|
59
|
+
<firstName>André Oktay</firstName>
|
60
|
+
<lastName>Dahl</lastName>
|
61
|
+
<gender>M</gender>
|
62
|
+
<dateOfBirth>1975-07-07T00:00:00</dateOfBirth>
|
63
|
+
<dateOfDeath>0001-01-01T00:00:00</dateOfDeath>
|
64
|
+
<district>Akershus</district>
|
65
|
+
<party>Høyre</party>
|
66
|
+
<committees>
|
67
|
+
<committee>Justiskomiteen</committee>
|
68
|
+
</committees>
|
69
|
+
<period>2011-2012</period>
|
70
|
+
</representative>
|
71
|
+
XML
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can deserialize HDO XML' do
|
75
|
+
rep = create_representative
|
76
|
+
Representative.from_hdo_node(parse(rep.to_hdo_xml)).should == rep
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|