aemo 0.5.1 → 0.6.0
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.
- checksums.yaml +4 -4
- data/lib/aemo/dispatchable.rb +2 -2
- data/lib/aemo/exceptions/invalid_nmi_allocation_type.rb +1 -1
- data/lib/aemo/exceptions/time_error.rb +20 -0
- data/lib/aemo/market/interval.rb +4 -4
- data/lib/aemo/market/node.rb +9 -3
- data/lib/aemo/market.rb +2 -4
- data/lib/aemo/msats.rb +70 -54
- data/lib/aemo/nem12/data_stream_suffix.rb +1 -1
- data/lib/aemo/nem12/quality_method.rb +14 -10
- data/lib/aemo/nem12/unit_of_measurement.rb +42 -42
- data/lib/aemo/nem12.rb +300 -94
- data/lib/aemo/nem13.rb +1 -2
- data/lib/aemo/nmi/allocation.rb +6 -7
- data/lib/aemo/nmi.rb +48 -38
- data/lib/aemo/region.rb +4 -3
- data/lib/aemo/register.rb +7 -7
- data/lib/aemo/struct.rb +3 -0
- data/lib/aemo/time.rb +112 -0
- data/lib/aemo/version.rb +1 -2
- data/lib/aemo.rb +13 -11
- data/lib/data/xml_to_json.rb +2 -4
- data/spec/aemo_spec.rb +0 -7
- data/spec/lib/aemo/market/interval_spec.rb +30 -12
- data/spec/lib/aemo/market/node_spec.rb +11 -9
- data/spec/lib/aemo/market_spec.rb +5 -4
- data/spec/lib/aemo/meter_spec.rb +2 -2
- data/spec/lib/aemo/msats_spec.rb +68 -56
- data/spec/lib/aemo/nem12_spec.rb +154 -43
- data/spec/lib/aemo/nmi/allocation_spec.rb +23 -18
- data/spec/lib/aemo/nmi_spec.rb +98 -72
- data/spec/lib/aemo/region_spec.rb +23 -18
- data/spec/spec_helper.rb +13 -13
- metadata +13 -435
data/spec/lib/aemo/msats_spec.rb
CHANGED
@@ -5,37 +5,39 @@ require 'spec_helper'
|
|
5
5
|
describe AEMO::MSATS do
|
6
6
|
describe 'instance methods' do
|
7
7
|
it 'creates a new instance' do
|
8
|
-
expect(
|
8
|
+
expect(described_class.new.class).to eq(described_class)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'class methods' do
|
13
13
|
describe 'nmi details' do
|
14
14
|
describe 'valid MSATS user' do
|
15
|
-
before
|
16
|
-
|
15
|
+
before do
|
16
|
+
described_class.authorize('ER', 'ER', 'ER')
|
17
17
|
end
|
18
18
|
|
19
|
-
it '
|
20
|
-
nmi_detail_query =
|
19
|
+
it 'gets data for a valid nmi' do
|
20
|
+
nmi_detail_query = described_class.nmi_detail('4001234567')
|
21
21
|
expect(nmi_detail_query.class).to eq(Hash)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
|
+
it 'gets a 404 for a nonexistent nmi' do
|
24
25
|
# nmi_detail_query = AEMO::MSATS.nmi_detail('4001234566')
|
25
26
|
# TODO workout what the different errors are here...
|
26
27
|
end
|
27
|
-
|
28
|
-
|
28
|
+
|
29
|
+
it 'raises an error for a bad nmi' do
|
30
|
+
expect { described_class.nmi_detail('BOBISAFISH') }.to raise_error(ArgumentError)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
describe 'invalid MSATS user' do
|
33
|
-
before
|
34
|
-
|
35
|
+
before do
|
36
|
+
described_class.authorize('NOTER', 'NOTER', 'NOTER')
|
35
37
|
end
|
36
38
|
|
37
|
-
it '
|
38
|
-
nmi_detail_query =
|
39
|
+
it 'gets data for a valid nmi' do
|
40
|
+
nmi_detail_query = described_class.nmi_detail('4001234567')
|
39
41
|
expect(nmi_detail_query.class).to eq(HTTParty::Response)
|
40
42
|
end
|
41
43
|
end
|
@@ -43,25 +45,26 @@ describe AEMO::MSATS do
|
|
43
45
|
|
44
46
|
describe '#c4' do
|
45
47
|
describe 'valid MSATS account' do
|
46
|
-
before
|
47
|
-
|
48
|
+
before do
|
49
|
+
described_class.authorize('ER', 'ER', 'ER')
|
48
50
|
end
|
49
51
|
|
50
|
-
it '
|
51
|
-
expect(
|
52
|
+
it 'returns a hash of information' do
|
53
|
+
expect(described_class.c4('4001234567', Time.now, Time.now, Time.now)).to be_a(Hash)
|
52
54
|
end
|
53
|
-
|
54
|
-
|
55
|
+
|
56
|
+
it 'raises an error for a bad nmi' do
|
57
|
+
expect { described_class.c4('BOBISAFISH') }.to raise_error(ArgumentError)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
describe 'invalid MSATS account' do
|
59
|
-
before
|
60
|
-
|
62
|
+
before do
|
63
|
+
described_class.authorize('NOTER', 'NOTER', 'NOTER')
|
61
64
|
end
|
62
65
|
|
63
|
-
it '
|
64
|
-
expect(
|
66
|
+
it 'returns response' do
|
67
|
+
expect(described_class.c4(
|
65
68
|
'4001234567',
|
66
69
|
Time.now,
|
67
70
|
Time.now,
|
@@ -73,80 +76,89 @@ describe AEMO::MSATS do
|
|
73
76
|
|
74
77
|
describe '#msats_limits' do
|
75
78
|
describe 'valid MSATS user' do
|
76
|
-
before
|
77
|
-
|
79
|
+
before do
|
80
|
+
described_class.authorize('ER', 'ER', 'ER')
|
78
81
|
end
|
79
82
|
|
80
|
-
it '
|
81
|
-
expect(
|
83
|
+
it 'gives details of msats_limits' do
|
84
|
+
expect(described_class.msats_limits.class).to eq(Hash)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
85
88
|
describe 'invalid MSATS user' do
|
86
|
-
before
|
87
|
-
|
89
|
+
before do
|
90
|
+
described_class.authorize('NOTER', 'NOTER', 'NOTER')
|
88
91
|
end
|
89
92
|
|
90
|
-
it '
|
91
|
-
expect(
|
93
|
+
it 'does not give details of msats_limits' do
|
94
|
+
expect(described_class.msats_limits.class).to eq(HTTParty::Response)
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
96
99
|
describe '#nmi_discovery_by_*' do
|
97
100
|
describe 'valid MSATS user' do
|
98
|
-
before
|
99
|
-
|
101
|
+
before do
|
102
|
+
described_class.authorize('ER', 'ER', 'ER')
|
100
103
|
end
|
101
|
-
|
102
|
-
|
104
|
+
|
105
|
+
it 'finds by address' do
|
106
|
+
expect(described_class.nmi_discovery_by_address('NSW', house_number: 6, street_name: 'Macquarie',
|
107
|
+
suburb_or_place_or_locality: 'Sydney', postcode: 2000).class).to eq(Array)
|
103
108
|
end
|
104
|
-
|
105
|
-
|
109
|
+
|
110
|
+
it 'finds by meter_serial_number' do
|
111
|
+
expect(described_class.nmi_discovery_by_meter_serial_number('NSW', 666).class).to eq(Array)
|
106
112
|
end
|
107
|
-
|
108
|
-
|
113
|
+
|
114
|
+
it 'finds by meter_serial_number' do
|
115
|
+
expect { described_class.nmi_discovery_by_delivery_point_identifier('NSW', 666) }.to raise_error(ArgumentError)
|
109
116
|
end
|
110
|
-
|
111
|
-
|
117
|
+
|
118
|
+
it 'finds by meter_serial_number' do
|
119
|
+
expect(described_class.nmi_discovery_by_delivery_point_identifier('NSW', 10_000_001).class).to eq(Array)
|
112
120
|
end
|
113
121
|
end
|
114
122
|
|
115
123
|
describe 'invalid MSATS user' do
|
116
|
-
before
|
117
|
-
|
124
|
+
before do
|
125
|
+
described_class.authorize('NOTER', 'NOTER', 'NOTER')
|
118
126
|
end
|
119
127
|
|
120
|
-
it '
|
121
|
-
expect(
|
128
|
+
it 'finds by address' do
|
129
|
+
expect(described_class.nmi_discovery_by_address('NSW', house_number: 6, street_name: 'Macquarie',
|
130
|
+
suburb_or_place_or_locality: 'Sydney', postcode: 2000).class).to eq(HTTParty::Response)
|
122
131
|
end
|
123
|
-
|
124
|
-
|
132
|
+
|
133
|
+
it 'finds by meter_serial_number' do
|
134
|
+
expect(described_class.nmi_discovery_by_meter_serial_number('NSW', 666).class).to eq(HTTParty::Response)
|
125
135
|
end
|
126
|
-
|
127
|
-
|
136
|
+
|
137
|
+
it 'finds by meter_serial_number' do
|
138
|
+
expect(described_class.nmi_discovery_by_delivery_point_identifier('NSW',
|
139
|
+
10_000_001).class).to eq(HTTParty::Response)
|
128
140
|
end
|
129
141
|
end
|
130
142
|
end
|
131
143
|
|
132
144
|
describe '#system_status' do
|
133
145
|
describe 'valid MSATS user' do
|
134
|
-
before
|
135
|
-
|
146
|
+
before do
|
147
|
+
described_class.authorize('ER', 'ER', 'ER')
|
136
148
|
end
|
137
149
|
|
138
|
-
it '
|
139
|
-
|
150
|
+
it 'provides a status' do
|
151
|
+
described_class.system_status
|
140
152
|
end
|
141
153
|
end
|
142
154
|
|
143
155
|
describe 'invalid MSATS user' do
|
144
|
-
before
|
145
|
-
|
156
|
+
before do
|
157
|
+
described_class.authorize('NOTER', 'NOTER', 'NOTER')
|
146
158
|
end
|
147
159
|
|
148
|
-
it '
|
149
|
-
expect(
|
160
|
+
it 'provides a status' do
|
161
|
+
expect(described_class.system_status.class).to eq(HTTParty::Response)
|
150
162
|
end
|
151
163
|
end
|
152
164
|
end
|
data/spec/lib/aemo/nem12_spec.rb
CHANGED
@@ -6,97 +6,208 @@ require 'json'
|
|
6
6
|
describe AEMO::NEM12 do
|
7
7
|
let(:json) { JSON.parse(fixture('nmi_checksum.json').read) }
|
8
8
|
|
9
|
-
describe '
|
10
|
-
it '
|
11
|
-
expect(
|
9
|
+
describe '#parse_nem12' do
|
10
|
+
it 'rejects an empty NEM12 string' do
|
11
|
+
expect(described_class.parse_nem12('')).to eq([])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '
|
16
|
-
|
17
|
-
Dir.entries(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12'))
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
describe '.parse_nem12_file' do
|
16
|
+
let(:files) do
|
17
|
+
Dir.entries(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12')).reject do |f|
|
18
|
+
%w[. .. .DS_Store].include?(f)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'parses a file' do
|
23
|
+
files.each do |file|
|
24
|
+
expect(described_class.parse_nem12_file(fixture(File.join('NEM12', file))).length).not_to eq(0)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
describe '
|
28
|
-
it '
|
29
|
-
expect
|
29
|
+
describe '.parse_nem12_100' do
|
30
|
+
it 'raises datetime error' do
|
31
|
+
expect { described_class.parse_nem12_100('100,NEM12,666,CNRGYMDP,NEMMCO') }.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'raises datetime error' do
|
35
|
+
expect do
|
36
|
+
described_class.parse_nem12_100('100,NEM12,666,CNRGYMDP,NEMMCO', strict: true)
|
37
|
+
end.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does not raise an error' do
|
41
|
+
expect { described_class.parse_nem12_100('100,NEM12,201603010000,CNRGYMDP,NEMMCO', strict: true) }.not_to raise_error
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
33
|
-
describe '.
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
describe '.to_nem12_csv' do
|
46
|
+
let(:now) { Time.parse('2023-04-05T06:07:08+10:00') }
|
47
|
+
|
48
|
+
context 'with empty nem12s' do
|
49
|
+
let(:nem12s) { [] }
|
50
|
+
let(:expected) { ['100,NEM12,202304050607,ENOSI,ENOSI', '900', ''].join("\r\n") }
|
51
|
+
|
52
|
+
before { Timecop.freeze(now) }
|
53
|
+
after { Timecop.return }
|
54
|
+
|
55
|
+
it 'returns expected' do
|
56
|
+
expect(described_class.to_nem12_csv(nem12s:)).to eq(expected)
|
37
57
|
end
|
38
58
|
end
|
39
|
-
end
|
40
59
|
|
41
|
-
|
42
|
-
|
43
|
-
|
60
|
+
context 'with non-empty nem12s not containing flags' do
|
61
|
+
let(:nem12_filepath) do
|
62
|
+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12', 'NEM12#000000000000001#CNRGYMDP#NEMMCO.csv')
|
63
|
+
end
|
64
|
+
let(:nem12s) { described_class.parse_nem12_file(nem12_filepath) }
|
65
|
+
let(:expected) do
|
66
|
+
[
|
67
|
+
'100,NEM12,202304050607,ENOSI,ENOSI',
|
68
|
+
'200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,',
|
69
|
+
'300,20050315,300.0,266.1,191.55,247.8,288.6,280.8,282.45,206.1,204.75,289.5,390.6,360.15,407.7,432.6,435.0,491.85,600.9,541.95,474.6,565.35,548.55,491.85,593.25,602.4,571.35,450.15,509.4,559.95,522.0,520.95,541.2,538.05,484.8,330.9,329.25,331.65,330.75,333.75,335.25,294.15,185.25,184.8,186.45,256.8,329.7,320.1,316.5,321.15,A,,,20050316014209,',
|
70
|
+
'200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,',
|
71
|
+
'300,20050315,113.1,87.6,33.75,60.6,81.9,79.5,81.15,39.75,25.65,58.8,174.3,197.1,390.6,392.55,394.2,418.5,484.95,407.7,407.7,466.5,455.7,386.85,486.9,489.45,465.15,360.0,387.45,458.7,381.9,424.8,446.25,444.45,383.55,172.65,154.05,164.4,164.25,174.45,170.1,110.1,44.55,44.25,39.9,72.3,109.05,102.45,103.95,103.05,A,,,20050316014209,',
|
72
|
+
'200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,',
|
73
|
+
'300,20050316,321.9,326.4,302.7,298.65,304.5,295.35,309.75,312.3,312.0,338.1,376.95,411.9,546.45,548.25,497.85,528.45,580.8,525.0,435.6,569.4,587.4,577.05,487.35,492.15,588.45,455.55,553.65,515.4,539.7,561.6,540.3,555.6,493.8,349.5,323.7,321.3,322.2,317.55,318.45,324.45,324.6,324.6,321.9,318.75,318.6,317.85,317.1,321.3,A,,,20050317032944,',
|
74
|
+
'200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,',
|
75
|
+
'300,20050316,104.85,103.5,82.95,64.8,72.3,71.4,72.9,80.1,94.5,121.05,185.1,282.9,427.8,427.95,322.8,381.45,464.4,413.4,332.25,442.95,472.8,466.35,401.55,400.2,470.7,352.8,426.3,381.3,435.45,453.75,433.2,453.0,388.35,226.05,148.05,149.55,142.65,115.65,105.75,107.1,109.35,111.45,107.1,104.25,103.05,101.85,103.2,107.55,A,,,20050317032944,',
|
76
|
+
'200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,',
|
77
|
+
'300,20050317,322.35,318.0,302.4,294.45,298.65,296.4,315.15,315.6,326.55,358.2,389.7,397.2,513.15,511.2,520.65,510.3,543.45,549.9,419.85,529.2,527.85,506.1,535.05,538.05,369.6,380.85,555.15,558.6,477.9,334.5,337.2,335.25,339.15,335.55,316.2,312.75,312.6,320.25,320.25,315.75,317.25,315.6,314.7,315.3,315.0,315.75,314.4,315.9,A,,,20050318014032,',
|
78
|
+
'200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,',
|
79
|
+
'300,20050317,104.1,100.8,85.8,70.5,70.95,69.45,53.25,55.65,66.6,106.8,182.1,266.55,408.9,402.15,410.7,414.45,436.2,427.8,325.35,442.2,439.2,432.15,435.3,418.8,283.5,294.0,450.45,455.4,368.4,156.0,160.5,137.55,138.0,134.4,112.35,105.6,103.35,111.75,111.15,107.55,106.5,103.95,102.3,105.75,103.8,97.5,99.75,102.0,A,,,20050318014032,',
|
80
|
+
'200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,',
|
81
|
+
'300,20050318,315.15,313.8,296.55,298.5,295.2,298.95,300.75,322.95,330.45,350.7,345.75,346.95,345.9,348.6,300.15,337.5,336.75,345.9,330.45,327.15,334.8,345.75,335.85,320.1,325.5,325.2,326.4,330.6,332.7,332.25,321.0,316.5,299.85,302.4,301.05,263.85,255.45,142.05,138.3,138.3,136.8,138.3,136.05,135.75,135.75,136.65,136.05,130.8,A,,,20050319014041,',
|
82
|
+
'200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,',
|
83
|
+
'300,20050318,103.05,98.85,81.15,75.6,72.15,73.95,74.55,81.15,89.25,124.2,125.7,128.7,136.8,151.05,177.9,174.45,204.0,210.15,180.15,164.4,187.95,211.95,193.8,122.85,124.8,121.2,129.3,131.25,130.95,130.05,118.05,105.75,77.1,75.9,75.0,51.15,44.4,12.3,12.75,12.15,12.45,11.55,14.4,14.55,15.0,14.7,15.75,21.9,A,,,20050319014041,', '900',
|
84
|
+
''
|
85
|
+
].join("\r\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
before { Timecop.freeze(now) }
|
89
|
+
after { Timecop.return }
|
90
|
+
|
91
|
+
it 'returns expected' do
|
92
|
+
expect(described_class.to_nem12_csv(nem12s:)).to eq(expected)
|
93
|
+
end
|
44
94
|
end
|
45
|
-
|
46
|
-
|
95
|
+
|
96
|
+
context 'with non-empty nem12s containing flags' do
|
97
|
+
let(:nem12_filepath) do
|
98
|
+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12', 'NEM12#000000000000004#CNRGYMDP#NEMMCO.csv')
|
99
|
+
end
|
100
|
+
let(:nem12s) { described_class.parse_nem12_file(nem12_filepath) }
|
101
|
+
let(:expected) do
|
102
|
+
[
|
103
|
+
'100,NEM12,202304050607,ENOSI,ENOSI',
|
104
|
+
'200,NEM1204062,E1,E1,E1,N1,04062,KWH,30,20050503',
|
105
|
+
'300,20040527,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.735,0.625,0.618,0.63,0.893,1.075,1.263,1.505,1.645,1.073,0.938,1.15,0.75,1.35,1.093,0.973,1.018,0.735,0.718,0.735,0.64,0.638,0.65,0.645,0.73,0.63,0.673,0.688,0.663,0.625,0.628,0.628,0.633,0.645,0.625,0.62,0.623,0.78,V,,,20040609153903,',
|
106
|
+
'400,1,10,F52,71,',
|
107
|
+
'400,11,48,E52,,',
|
108
|
+
'200,NEM1204062,E1,E1,E1,N1,04062,KWH,30,20050503',
|
109
|
+
'300,20040528,0.68,0.653,0.62,0.623,0.618,0.625,0.613,0.623,0.618,0.615,0.613,0.76,0.665,0.638,0.61,0.648,0.65,0.645,0.895,0.668,0.645,0.648,0.655,0.73,0.695,0.67,0.638,0.643,0.64,0.723,0.653,0.645,0.633,0.71,0.683,0.648,0.625,0.63,0.625,0.63,0.638,0.635,0.633,0.638,0.673,0.765,0.65,0.628,V,,,20040609000001,',
|
110
|
+
'400,1,48,E52,,',
|
111
|
+
'200,NEM1204062,E1,E1,E1,N1,04062,KWH,30,20050503',
|
112
|
+
'300,20040529,0.633,0.613,0.628,0.618,0.625,0.623,0.623,0.613,0.655,0.663,0.645,0.708,0.608,0.618,0.63,0.625,0.62,0.635,0.63,0.638,0.693,0.71,0.683,0.645,0.638,0.653,0.653,0.648,0.655,0.745,0.69,0.695,0.68,0.643,0.645,0.635,0.628,0.625,0.635,0.628,0.673,0.688,0.685,0.66,0.638,0.718,0.638,0.63,V,,,20040609000001,',
|
113
|
+
'400,1,48,E52,,',
|
114
|
+
'900',
|
115
|
+
''
|
116
|
+
].join("\r\n")
|
117
|
+
end
|
118
|
+
|
119
|
+
before { Timecop.freeze(now) }
|
120
|
+
after { Timecop.return }
|
121
|
+
|
122
|
+
it 'returns expected' do
|
123
|
+
expect(described_class.to_nem12_csv(nem12s:)).to eq(expected)
|
124
|
+
end
|
47
125
|
end
|
48
|
-
|
49
|
-
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '::RECORD_INDICATORS' do
|
129
|
+
it 'is a hash' do
|
130
|
+
expect(AEMO::NEM12::RECORD_INDICATORS.class).to eq(Hash)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#nmi_identifier' do
|
135
|
+
it 'returns the NMI identifier or nil' do
|
136
|
+
Dir.entries(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12'))
|
137
|
+
.reject { |f| %w[. .. .DS_Store].include?(f) }
|
138
|
+
.each do |file|
|
139
|
+
described_class.parse_nem12_file(fixture(File.join('NEM12', file))).each do |nem12|
|
140
|
+
expect(nem12.nmi_identifier).to be_a String
|
141
|
+
end
|
142
|
+
end
|
50
143
|
end
|
51
144
|
end
|
52
145
|
|
53
146
|
describe '#parse_nem12_200' do
|
54
147
|
context 'non-strict mode' do
|
55
|
-
it '
|
56
|
-
expect(
|
148
|
+
it 'does not raise validation warning with bad NMI configuration' do
|
149
|
+
expect(described_class.parse_nem12_file(
|
150
|
+
fixture(File.join('NEM12-Errors', 'NEM12#DerpyNMIConfig#CNRGYMDP#NEMMCO.csv')), strict: false
|
151
|
+
))
|
57
152
|
.to be_truthy
|
58
153
|
end
|
59
154
|
end
|
60
155
|
|
61
156
|
context 'strict mode (default)' do
|
62
|
-
it '
|
63
|
-
expect
|
157
|
+
it 'raises validation warning with bad NMI configuration' do
|
158
|
+
expect do
|
159
|
+
described_class.parse_nem12_file(fixture(File.join('NEM12-Errors', 'NEM12#DerpyNMIConfig#CNRGYMDP#NEMMCO.csv')))
|
160
|
+
end
|
64
161
|
.to raise_error(ArgumentError, 'NMIConfiguration is not valid')
|
65
162
|
end
|
66
163
|
end
|
67
164
|
end
|
68
165
|
|
69
166
|
describe '#parse_nem12_300' do
|
70
|
-
it '
|
167
|
+
it 'raises invalid record length error' do
|
71
168
|
bad_file = fixture(File.join('NEM12-Errors', 'NEM12#InvalidIntervalDataLength#CNRGYMDP#NEMMCO.csv'))
|
72
|
-
expect {
|
169
|
+
expect { described_class.parse_nem12_file(bad_file) }.to raise_error(TypeError, 'Invalid record length')
|
73
170
|
end
|
74
171
|
|
75
|
-
it '
|
172
|
+
it 'raises argument error on 300 empty cells' do
|
76
173
|
nem12_empty_cells_300_record = fixture(File.join('NEM12-Errors', 'NEM12#EmptyCells300Record#CNRGYMDP#NEMMCO.csv'))
|
77
|
-
expect {
|
174
|
+
expect { described_class.parse_nem12_file(nem12_empty_cells_300_record) }.to raise_error(ArgumentError)
|
78
175
|
end
|
79
176
|
end
|
80
177
|
|
81
178
|
describe '#parse_nem12_400' do
|
82
|
-
it '
|
179
|
+
it 'raises argument error on 400 empty cells' do
|
83
180
|
nem12_empty_cells_400_record = fixture(File.join('NEM12-Errors', 'NEM12#EmptyCells400Record#CNRGYMDP#NEMMCO.csv'))
|
84
|
-
expect {
|
181
|
+
expect { described_class.parse_nem12_file(nem12_empty_cells_400_record) }.to raise_error(ArgumentError)
|
85
182
|
end
|
86
183
|
end
|
87
184
|
|
88
|
-
describe '#parse_nem12_500' do
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#parse_nem12_900' do
|
92
|
-
end
|
93
|
-
|
94
185
|
describe '#flag_to_s' do
|
95
186
|
it 'converts the flags to a string' do
|
96
187
|
flag = { quality_flag: 'S', method_flag: 11, reason_code: 53 }
|
97
|
-
nem12 =
|
188
|
+
nem12 = described_class.new('NEEE000010')
|
98
189
|
expect(nem12.flag_to_s(flag))
|
99
190
|
.to eq 'Substituted Data - Check - Bees/Wasp In Meter Box'
|
100
191
|
end
|
101
192
|
end
|
193
|
+
|
194
|
+
describe '#to_nem12_csv' do
|
195
|
+
let(:nem12_filepath) do
|
196
|
+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'NEM12', 'NEM12#000000000000004#CNRGYMDP#NEMMCO.csv')
|
197
|
+
end
|
198
|
+
let(:nem12) { described_class.parse_nem12_file(nem12_filepath).first }
|
199
|
+
let(:expected) do
|
200
|
+
"100,NEM12,200505121137,CNRGYMDP,NEMMCO\r
|
201
|
+
200,NEM1204062,E1,E1,E1,N1,04062,KWH,30,20050503\r
|
202
|
+
300,20040527,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.735,0.625,0.618,0.63,0.893,1.075,1.263,1.505,1.645,1.073,0.938,1.15,0.75,1.35,1.093,0.973,1.018,0.735,0.718,0.735,0.64,0.638,0.65,0.645,0.73,0.63,0.673,0.688,0.663,0.625,0.628,0.628,0.633,0.645,0.625,0.62,0.623,0.78,V,,,20040609153903,\r
|
203
|
+
400,1,10,F52,71,\r
|
204
|
+
400,11,48,E52,,\r
|
205
|
+
900\r
|
206
|
+
"
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'returns a correct NEM12 file' do
|
210
|
+
expect(nem12.to_nem12_csv).to eq(expected)
|
211
|
+
end
|
212
|
+
end
|
102
213
|
end
|
@@ -7,21 +7,21 @@ describe AEMO::NMI::Allocation do
|
|
7
7
|
# CLASS METHODS
|
8
8
|
# ---
|
9
9
|
describe '.all' do
|
10
|
-
it '
|
11
|
-
expect(
|
12
|
-
expect(
|
10
|
+
it 'returns an array of all the Allocations' do
|
11
|
+
expect(described_class.all).to be_a Array
|
12
|
+
expect(described_class.all.first).to be_a described_class
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '.each' do
|
17
|
-
it '
|
18
|
-
expect(
|
17
|
+
it 'returns an enumerable of all the Allocations' do
|
18
|
+
expect(described_class.each).to be_a Enumerable
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '.first' do
|
23
|
-
it '
|
24
|
-
expect(
|
23
|
+
it 'returns the first Allocation' do
|
24
|
+
expect(described_class.first).to be_a described_class
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -30,20 +30,25 @@ describe AEMO::NMI::Allocation do
|
|
30
30
|
# ---
|
31
31
|
describe '#initialize' do
|
32
32
|
context 'valid' do
|
33
|
-
it '
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
33
|
+
it 'returns an Allocation' do
|
34
|
+
expect(described_class.new('My great LNSP', :electricity)).to be_a described_class
|
35
|
+
expect(described_class.new('My great LNSP', 'electricity')).to be_a described_class
|
36
|
+
expect(described_class.new('My great gas LNSP', :gas)).to be_a described_class
|
37
|
+
expect(described_class.new('My great gas LNSP', 'gas')).to be_a described_class
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
40
41
|
context 'invalid' do
|
41
|
-
it '
|
42
|
-
expect {
|
43
|
-
expect
|
44
|
-
|
45
|
-
|
46
|
-
expect {
|
42
|
+
it 'raises an InvalidNMIAllocationType error' do
|
43
|
+
expect { described_class.new('My terrible LNSP', :water) }.to raise_error AEMO::InvalidNMIAllocationType
|
44
|
+
expect do
|
45
|
+
described_class.new('My terrible LNSP', :broccoli)
|
46
|
+
end.to raise_error AEMO::InvalidNMIAllocationType
|
47
|
+
expect { described_class.new('My terrible LNSP', 'Ch4') }.to raise_error AEMO::InvalidNMIAllocationType
|
48
|
+
expect do
|
49
|
+
described_class.new('My terrible LNSP', 'Natural gas')
|
50
|
+
end.to raise_error AEMO::InvalidNMIAllocationType
|
51
|
+
expect { described_class.new('My terrible LNSP', :coal) }.to raise_error AEMO::InvalidNMIAllocationType
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|