Skip to content

Commit

Permalink
added first tests for hmip_cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
coreGreenberet committed May 7, 2018
1 parent 895f053 commit 2c3030b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
command: |
. venv/bin/activate
export PYTHONPATH=`pwd`;
pytest --cov=./ --junitxml=test-reports/junit.xml tests/test_base_connection.py tests/test_home.py tests/test_devices.py tests/test_groups.py
pytest --cov=./ --junitxml=test-reports/junit.xml tests/test_base_connection.py tests/test_home.py tests/test_devices.py tests/test_groups.py tests/test_hmip_cli.py
bash <(curl -s https://codecov.io/bash)
- store_test_results:
Expand Down
8 changes: 4 additions & 4 deletions hmip_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def main():
#generate dummy SGTIN
c = anonymizeConfig(c,'3014F711[A-Z0-9]{16}','3014F711{0:0>16}')
#remove refresh Token
c = anonymizeConfig(c,'"refreshToken": "[^"]+"','"refreshToken": null')
c = anonymizeConfig(c,'"refreshToken": ?"[^"]+"','"refreshToken": null')
#location
c = anonymizeConfig(c,'"city": "[^"]+"','"city": "1010, Vienna, Austria"')
c = anonymizeConfig(c,'"latitude": "[^"]+"','"latitude": "48.208088"')
c = anonymizeConfig(c,'"longitude": "[^"]+"','"longitude": "16.358608"')
c = anonymizeConfig(c,'"city": ?"[^"]+"','"city": "1010, Vienna, Austria"')
c = anonymizeConfig(c,'"latitude": ?"[^"]+"','"latitude": "48.208088"')
c = anonymizeConfig(c,'"longitude": ?"[^"]+"','"longitude": "16.358608"')

print(c)

Expand Down
3 changes: 3 additions & 0 deletions homematicip.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<Compile Include="tests\test_base_connection.py" />
<Compile Include="tests\test_groups.py" />
<Compile Include="tests\test_devices.py" />
<Compile Include="tests\test_hmip_cli.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="tests\test_home.py">
<SubType>Code</SubType>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
pytest.main('tests/test_home.py')
pytest.main('tests/test_devices.py')
pytest.main('tests/test_groups.py')
pytest.main('tests/test_hmip_cli.py')
41 changes: 41 additions & 0 deletions tests/test_hmip_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json
from hmip_cli import getRssiBarString, anonymizeConfig


def test_getRssiBarString():
assert getRssiBarString(-50) == '[**********]'
assert getRssiBarString(-55) == '[*********_]'
assert getRssiBarString(-60) == '[********__]'
assert getRssiBarString(-65) == '[*******___]'
assert getRssiBarString(-70) == '[******____]'
assert getRssiBarString(-75) == '[*****_____]'
assert getRssiBarString(-80) == '[****______]'
assert getRssiBarString(-85) == '[***_______]'
assert getRssiBarString(-90) == '[**________]'
assert getRssiBarString(-95) == '[*_________]'
assert getRssiBarString(-100) == '[__________]'

def test_anonymizeConfig():
c = ('{"id":"d0fea2b1-ef3b-44b1-ae96-f9b31f75de84","inboxGroup":"2dc54a8d-ceee-4626-8f27-b24e78dc05de","location":'
'{"city": "Vatican City, Vatican","latitude":"41.9026011","longitude":"12.4533701"}}')
c = anonymizeConfig(c,'[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}','00000000-0000-0000-0000-{0:0>12}')
#generate dummy SGTIN
c = anonymizeConfig(c,'3014F711[A-Z0-9]{16}','3014F711{0:0>16}')
#remove refresh Token
c = anonymizeConfig(c,'"refreshToken": ?"[^"]+"','"refreshToken": null')
#location
c = anonymizeConfig(c,'"city": ?"[^"]+"','"city": "1010, Vienna, Austria"')
c = anonymizeConfig(c,'"latitude": ?"[^"]+"','"latitude": "48.208088"')
c = anonymizeConfig(c,'"longitude": ?"[^"]+"','"longitude": "16.358608"')

js = json.loads(c)

assert js["id"] == '00000000-0000-0000-0000-000000000000'
assert js["inboxGroup"] == '00000000-0000-0000-0000-000000000001'

l = js["location"]
assert l["city"] == '1010, Vienna, Austria'
assert l["latitude"] == '48.208088'
assert l["longitude"] == '16.358608'


0 comments on commit 2c3030b

Please sign in to comment.