Add version extraction to parser
This commit is contained in:
parent
bb4b85851e
commit
7134dc65d8
2 changed files with 15 additions and 2 deletions
|
@ -8,3 +8,6 @@ class NomieParser(Parser):
|
||||||
def __init__(self, data="{}") -> None:
|
def __init__(self, data="{}") -> None:
|
||||||
"""Load a data set and prepare parser data"""
|
"""Load a data set and prepare parser data"""
|
||||||
self.data = jsonloads(data)
|
self.data = jsonloads(data)
|
||||||
|
|
||||||
|
def extract_version(self) -> str:
|
||||||
|
return self.data["nomie"]["number"]
|
||||||
|
|
|
@ -3,16 +3,26 @@ import json
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_data():
|
||||||
|
return '{ "nomie": { "number": "5.6.4", "created": "2021-08-26T08:15:36.898Z", "startDate": "2021-08-26T08:15:36.898Z", "endDate": "2021-08-26T08:15:36.898Z" }}'
|
||||||
|
|
||||||
|
|
||||||
def test_nomie_parser_exists():
|
def test_nomie_parser_exists():
|
||||||
sut = NomieParser()
|
sut = NomieParser()
|
||||||
assert type(sut) == NomieParser
|
assert type(sut) == NomieParser
|
||||||
|
|
||||||
|
|
||||||
def test_nomie_Parser_errors_on_invalid_data():
|
def test_nomie_parser_errors_on_invalid_data():
|
||||||
with pytest.raises(json.decoder.JSONDecodeError):
|
with pytest.raises(json.decoder.JSONDecodeError):
|
||||||
NomieParser(data="invalid_test_data")
|
NomieParser(data="invalid_test_data")
|
||||||
|
|
||||||
|
|
||||||
def test_nomie_Parser_saves_data():
|
def test_nomie_parser_saves_data():
|
||||||
sut = NomieParser(data='{"test": "entry"}')
|
sut = NomieParser(data='{"test": "entry"}')
|
||||||
assert sut.data == {"test": "entry"}
|
assert sut.data == {"test": "entry"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_nomie_parser_extracts_version(sample_data):
|
||||||
|
sut = NomieParser(data=sample_data)
|
||||||
|
assert sut.extract_version() == "5.6.4"
|
||||||
|
|
Loading…
Reference in a new issue