Skip to content

Commit 3311a35

Browse files
committed
Add tests for currency change and prices being not available
1 parent 3a9cf06 commit 3311a35

File tree

6 files changed

+329
-17
lines changed

6 files changed

+329
-17
lines changed

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,25 @@ Python library for fetching Nord Pool Elspot and Elbas prices.
1414

1515
#### Example
1616

17-
```
17+
```python
1818
# Import library for fetching Elspot data
19-
from nordpool import elspot, elbas
19+
from nordpool import elspot
2020
from pprint import pprint
2121

2222
# Initialize class for fetching Elspot prices
2323
prices_spot = elspot.Prices()
2424

25-
# Initialize class for fetching Elsbas prices
26-
prices_bas = elbas.Prices()
27-
2825
# Fetch hourly Elspot prices for Finland and print the resulting dictionary
26+
# If the prices are reported as None, it means that the prices fetched aren't yet available.
27+
# The library by default tries to fetch prices for tomorrow and they're released ~13:00 Swedish time.
2928
pprint(prices_spot.hourly(areas=['FI']))
30-
31-
# Fetch hourly Elbas prices for Finland and print the resulting dictionary
32-
pprint(prices_bas.hourly(areas=['FI']))
33-
3429
```
3530

3631
###### Output
3732

3833
```python
3934
{u'areas': {
4035
u'FI': {
41-
u'Average': 32.54,
42-
u'Max': 37.31,
43-
u'Min': 30.04,
44-
u'Off-peak 1': 30.74,
45-
u'Off-peak 2': 32.07,
46-
u'Peak': 33.9,
4736
u'values': [
4837
{u'end': datetime.datetime(2014, 10, 3, 23, 0, tzinfo=<UTC>),
4938
u'start': datetime.datetime(2014, 10, 3, 22, 0, tzinfo=<UTC>),

example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
# Initialize class for fetching Elspot prices
88
prices_spot = elspot.Prices()
99

10-
# Fetch hourly Elspot prices for Finland and print the resulting dictionary
10+
# Fetch hourly Elspot prices for Finland and print the resulting dictionary.
11+
# If the prices are reported as None, it means that the prices fetched aren't yet available.
12+
# The library by default tries to fetch prices for tomorrow and they're released ~13:00 Swedish time.
1113
pprint(prices_spot.hourly(areas=["FI"]))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nordpool"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "Python library for fetching Nord Pool spot prices."
55
authors = ["Kimmo Huoman <kipenroskaposti@gmail.com>"]
66
license = "MIT"

tests/test_elspot.py

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,3 +3006,248 @@ def test_single_area_yearly(self):
30063006
),
30073007
},
30083008
)
3009+
3010+
def test_prices_not_available(self):
3011+
with vcr.use_cassette("prices_not_available.yaml"):
3012+
elspot = Prices()
3013+
prices = elspot.fetch(elspot.HOURLY, end_date="2024-10-17", areas=["FI"])
3014+
self.assertIsNone(prices)
3015+
3016+
def test_different_currency(self):
3017+
with vcr.use_cassette("different_currency.yaml"):
3018+
elspot = Prices(currency="SEK")
3019+
prices = elspot.fetch(elspot.HOURLY, end_date="2024-10-15", areas=["SE1"])
3020+
# pprint(prices)
3021+
self.assertEqual(
3022+
prices,
3023+
{
3024+
"areas": {
3025+
"SE1": {
3026+
"values": [
3027+
{
3028+
"end": datetime.datetime(
3029+
2024, 10, 14, 23, 0, tzinfo=utc
3030+
),
3031+
"start": datetime.datetime(
3032+
2024, 10, 14, 22, 0, tzinfo=utc
3033+
),
3034+
"value": 95.81,
3035+
},
3036+
{
3037+
"end": datetime.datetime(
3038+
2024, 10, 15, 0, 0, tzinfo=utc
3039+
),
3040+
"start": datetime.datetime(
3041+
2024, 10, 14, 23, 0, tzinfo=utc
3042+
),
3043+
"value": 75.33,
3044+
},
3045+
{
3046+
"end": datetime.datetime(
3047+
2024, 10, 15, 1, 0, tzinfo=utc
3048+
),
3049+
"start": datetime.datetime(
3050+
2024, 10, 15, 0, 0, tzinfo=utc
3051+
),
3052+
"value": 84.55,
3053+
},
3054+
{
3055+
"end": datetime.datetime(
3056+
2024, 10, 15, 2, 0, tzinfo=utc
3057+
),
3058+
"start": datetime.datetime(
3059+
2024, 10, 15, 1, 0, tzinfo=utc
3060+
),
3061+
"value": 77.6,
3062+
},
3063+
{
3064+
"end": datetime.datetime(
3065+
2024, 10, 15, 3, 0, tzinfo=utc
3066+
),
3067+
"start": datetime.datetime(
3068+
2024, 10, 15, 2, 0, tzinfo=utc
3069+
),
3070+
"value": 119.48,
3071+
},
3072+
{
3073+
"end": datetime.datetime(
3074+
2024, 10, 15, 4, 0, tzinfo=utc
3075+
),
3076+
"start": datetime.datetime(
3077+
2024, 10, 15, 3, 0, tzinfo=utc
3078+
),
3079+
"value": 165.45,
3080+
},
3081+
{
3082+
"end": datetime.datetime(
3083+
2024, 10, 15, 5, 0, tzinfo=utc
3084+
),
3085+
"start": datetime.datetime(
3086+
2024, 10, 15, 4, 0, tzinfo=utc
3087+
),
3088+
"value": 173.64,
3089+
},
3090+
{
3091+
"end": datetime.datetime(
3092+
2024, 10, 15, 6, 0, tzinfo=utc
3093+
),
3094+
"start": datetime.datetime(
3095+
2024, 10, 15, 5, 0, tzinfo=utc
3096+
),
3097+
"value": 182.97,
3098+
},
3099+
{
3100+
"end": datetime.datetime(
3101+
2024, 10, 15, 7, 0, tzinfo=utc
3102+
),
3103+
"start": datetime.datetime(
3104+
2024, 10, 15, 6, 0, tzinfo=utc
3105+
),
3106+
"value": 204.48,
3107+
},
3108+
{
3109+
"end": datetime.datetime(
3110+
2024, 10, 15, 8, 0, tzinfo=utc
3111+
),
3112+
"start": datetime.datetime(
3113+
2024, 10, 15, 7, 0, tzinfo=utc
3114+
),
3115+
"value": 227.47,
3116+
},
3117+
{
3118+
"end": datetime.datetime(
3119+
2024, 10, 15, 9, 0, tzinfo=utc
3120+
),
3121+
"start": datetime.datetime(
3122+
2024, 10, 15, 8, 0, tzinfo=utc
3123+
),
3124+
"value": 247.83,
3125+
},
3126+
{
3127+
"end": datetime.datetime(
3128+
2024, 10, 15, 10, 0, tzinfo=utc
3129+
),
3130+
"start": datetime.datetime(
3131+
2024, 10, 15, 9, 0, tzinfo=utc
3132+
),
3133+
"value": 260.92,
3134+
},
3135+
{
3136+
"end": datetime.datetime(
3137+
2024, 10, 15, 11, 0, tzinfo=utc
3138+
),
3139+
"start": datetime.datetime(
3140+
2024, 10, 15, 10, 0, tzinfo=utc
3141+
),
3142+
"value": 272.87,
3143+
},
3144+
{
3145+
"end": datetime.datetime(
3146+
2024, 10, 15, 12, 0, tzinfo=utc
3147+
),
3148+
"start": datetime.datetime(
3149+
2024, 10, 15, 11, 0, tzinfo=utc
3150+
),
3151+
"value": 279.58,
3152+
},
3153+
{
3154+
"end": datetime.datetime(
3155+
2024, 10, 15, 13, 0, tzinfo=utc
3156+
),
3157+
"start": datetime.datetime(
3158+
2024, 10, 15, 12, 0, tzinfo=utc
3159+
),
3160+
"value": 277.87,
3161+
},
3162+
{
3163+
"end": datetime.datetime(
3164+
2024, 10, 15, 14, 0, tzinfo=utc
3165+
),
3166+
"start": datetime.datetime(
3167+
2024, 10, 15, 13, 0, tzinfo=utc
3168+
),
3169+
"value": 263.88,
3170+
},
3171+
{
3172+
"end": datetime.datetime(
3173+
2024, 10, 15, 15, 0, tzinfo=utc
3174+
),
3175+
"start": datetime.datetime(
3176+
2024, 10, 15, 14, 0, tzinfo=utc
3177+
),
3178+
"value": 252.27,
3179+
},
3180+
{
3181+
"end": datetime.datetime(
3182+
2024, 10, 15, 16, 0, tzinfo=utc
3183+
),
3184+
"start": datetime.datetime(
3185+
2024, 10, 15, 15, 0, tzinfo=utc
3186+
),
3187+
"value": 226.78,
3188+
},
3189+
{
3190+
"end": datetime.datetime(
3191+
2024, 10, 15, 17, 0, tzinfo=utc
3192+
),
3193+
"start": datetime.datetime(
3194+
2024, 10, 15, 16, 0, tzinfo=utc
3195+
),
3196+
"value": 187.41,
3197+
},
3198+
{
3199+
"end": datetime.datetime(
3200+
2024, 10, 15, 18, 0, tzinfo=utc
3201+
),
3202+
"start": datetime.datetime(
3203+
2024, 10, 15, 17, 0, tzinfo=utc
3204+
),
3205+
"value": 175.24,
3206+
},
3207+
{
3208+
"end": datetime.datetime(
3209+
2024, 10, 15, 19, 0, tzinfo=utc
3210+
),
3211+
"start": datetime.datetime(
3212+
2024, 10, 15, 18, 0, tzinfo=utc
3213+
),
3214+
"value": 171.03,
3215+
},
3216+
{
3217+
"end": datetime.datetime(
3218+
2024, 10, 15, 20, 0, tzinfo=utc
3219+
),
3220+
"start": datetime.datetime(
3221+
2024, 10, 15, 19, 0, tzinfo=utc
3222+
),
3223+
"value": 170.12,
3224+
},
3225+
{
3226+
"end": datetime.datetime(
3227+
2024, 10, 15, 21, 0, tzinfo=utc
3228+
),
3229+
"start": datetime.datetime(
3230+
2024, 10, 15, 20, 0, tzinfo=utc
3231+
),
3232+
"value": 160.1,
3233+
},
3234+
{
3235+
"end": datetime.datetime(
3236+
2024, 10, 15, 22, 0, tzinfo=utc
3237+
),
3238+
"start": datetime.datetime(
3239+
2024, 10, 15, 21, 0, tzinfo=utc
3240+
),
3241+
"value": 115.61,
3242+
},
3243+
]
3244+
}
3245+
},
3246+
"currency": "SEK",
3247+
"end": datetime.datetime(2024, 10, 15, 22, 0, tzinfo=utc),
3248+
"start": datetime.datetime(2024, 10, 14, 22, 0, tzinfo=utc),
3249+
"updated": datetime.datetime(
3250+
2024, 10, 14, 11, 17, 2, 702631, tzinfo=utc
3251+
),
3252+
},
3253+
)

tests/vcr/different_currency.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- python-requests/2.32.3
13+
method: GET
14+
uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?currency=SEK&market=DayAhead&deliveryArea=SE1&date=2024-10-15
15+
response:
16+
body:
17+
string: '{"deliveryDateCET":"2024-10-15","version":3,"updatedAt":"2024-10-14T11:17:02.7026319Z","deliveryAreas":["SE1"],"market":"DayAhead","multiAreaEntries":[{"deliveryStart":"2024-10-14T22:00:00Z","deliveryEnd":"2024-10-14T23:00:00Z","entryPerArea":{"SE1":95.81}},{"deliveryStart":"2024-10-14T23:00:00Z","deliveryEnd":"2024-10-15T00:00:00Z","entryPerArea":{"SE1":75.33}},{"deliveryStart":"2024-10-15T00:00:00Z","deliveryEnd":"2024-10-15T01:00:00Z","entryPerArea":{"SE1":84.55}},{"deliveryStart":"2024-10-15T01:00:00Z","deliveryEnd":"2024-10-15T02:00:00Z","entryPerArea":{"SE1":77.60}},{"deliveryStart":"2024-10-15T02:00:00Z","deliveryEnd":"2024-10-15T03:00:00Z","entryPerArea":{"SE1":119.48}},{"deliveryStart":"2024-10-15T03:00:00Z","deliveryEnd":"2024-10-15T04:00:00Z","entryPerArea":{"SE1":165.45}},{"deliveryStart":"2024-10-15T04:00:00Z","deliveryEnd":"2024-10-15T05:00:00Z","entryPerArea":{"SE1":173.64}},{"deliveryStart":"2024-10-15T05:00:00Z","deliveryEnd":"2024-10-15T06:00:00Z","entryPerArea":{"SE1":182.97}},{"deliveryStart":"2024-10-15T06:00:00Z","deliveryEnd":"2024-10-15T07:00:00Z","entryPerArea":{"SE1":204.48}},{"deliveryStart":"2024-10-15T07:00:00Z","deliveryEnd":"2024-10-15T08:00:00Z","entryPerArea":{"SE1":227.47}},{"deliveryStart":"2024-10-15T08:00:00Z","deliveryEnd":"2024-10-15T09:00:00Z","entryPerArea":{"SE1":247.83}},{"deliveryStart":"2024-10-15T09:00:00Z","deliveryEnd":"2024-10-15T10:00:00Z","entryPerArea":{"SE1":260.92}},{"deliveryStart":"2024-10-15T10:00:00Z","deliveryEnd":"2024-10-15T11:00:00Z","entryPerArea":{"SE1":272.87}},{"deliveryStart":"2024-10-15T11:00:00Z","deliveryEnd":"2024-10-15T12:00:00Z","entryPerArea":{"SE1":279.58}},{"deliveryStart":"2024-10-15T12:00:00Z","deliveryEnd":"2024-10-15T13:00:00Z","entryPerArea":{"SE1":277.87}},{"deliveryStart":"2024-10-15T13:00:00Z","deliveryEnd":"2024-10-15T14:00:00Z","entryPerArea":{"SE1":263.88}},{"deliveryStart":"2024-10-15T14:00:00Z","deliveryEnd":"2024-10-15T15:00:00Z","entryPerArea":{"SE1":252.27}},{"deliveryStart":"2024-10-15T15:00:00Z","deliveryEnd":"2024-10-15T16:00:00Z","entryPerArea":{"SE1":226.78}},{"deliveryStart":"2024-10-15T16:00:00Z","deliveryEnd":"2024-10-15T17:00:00Z","entryPerArea":{"SE1":187.41}},{"deliveryStart":"2024-10-15T17:00:00Z","deliveryEnd":"2024-10-15T18:00:00Z","entryPerArea":{"SE1":175.24}},{"deliveryStart":"2024-10-15T18:00:00Z","deliveryEnd":"2024-10-15T19:00:00Z","entryPerArea":{"SE1":171.03}},{"deliveryStart":"2024-10-15T19:00:00Z","deliveryEnd":"2024-10-15T20:00:00Z","entryPerArea":{"SE1":170.12}},{"deliveryStart":"2024-10-15T20:00:00Z","deliveryEnd":"2024-10-15T21:00:00Z","entryPerArea":{"SE1":160.10}},{"deliveryStart":"2024-10-15T21:00:00Z","deliveryEnd":"2024-10-15T22:00:00Z","entryPerArea":{"SE1":115.61}}],"blockPriceAggregates":[{"blockName":"Off-peak
18+
1","deliveryStart":"2024-10-14T22:00:00Z","deliveryEnd":"2024-10-15T06:00:00Z","averagePricePerArea":{"SE1":{"average":121.85,"min":75.33,"max":182.97}}},{"blockName":"Peak","deliveryStart":"2024-10-15T06:00:00Z","deliveryEnd":"2024-10-15T18:00:00Z","averagePricePerArea":{"SE1":{"average":239.72,"min":175.24,"max":279.58}}},{"blockName":"Off-peak
19+
2","deliveryStart":"2024-10-15T18:00:00Z","deliveryEnd":"2024-10-15T22:00:00Z","averagePricePerArea":{"SE1":{"average":154.22,"min":115.61,"max":171.03}}}],"currency":"SEK","exchangeRate":11.37896,"areaStates":[{"state":"Final","areas":["SE1"]}],"areaAverages":[{"areaCode":"SE1","price":186.18}]}'
20+
headers:
21+
Connection:
22+
- keep-alive
23+
Content-Encoding:
24+
- gzip
25+
Content-Type:
26+
- application/json; charset=utf-8
27+
Date:
28+
- Wed, 16 Oct 2024 06:50:02 GMT
29+
Request-Context:
30+
- appId=cid-v1:ddfe5a25-b9d8-4f0e-b951-f04e01c2922f
31+
Set-Cookie:
32+
- route=1729061403.917.28.454779|9898ac1b7e0bd8fc3874537f2a76b591; Expires=Fri,
33+
18-Oct-24 06:50:02 GMT; Max-Age=172800; Path=/; Secure; HttpOnly
34+
Strict-Transport-Security:
35+
- max-age=31536000
36+
Transfer-Encoding:
37+
- chunked
38+
Vary:
39+
- Accept-Encoding
40+
status:
41+
code: 200
42+
message: OK
43+
version: 1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- python-requests/2.32.3
13+
method: GET
14+
uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?currency=EUR&market=DayAhead&deliveryArea=FI&date=2024-10-17
15+
response:
16+
body:
17+
string: ''
18+
headers:
19+
Connection:
20+
- keep-alive
21+
Date:
22+
- Wed, 16 Oct 2024 06:47:32 GMT
23+
Request-Context:
24+
- appId=cid-v1:ddfe5a25-b9d8-4f0e-b951-f04e01c2922f
25+
Set-Cookie:
26+
- route=1729061253.345.30.936500|9898ac1b7e0bd8fc3874537f2a76b591; Expires=Fri,
27+
18-Oct-24 06:47:32 GMT; Max-Age=172800; Path=/; Secure; HttpOnly
28+
Strict-Transport-Security:
29+
- max-age=31536000
30+
status:
31+
code: 204
32+
message: No Content
33+
version: 1

0 commit comments

Comments
 (0)