Skip to content

Commit

Permalink
Update test_purpleair_data_logger.py
Browse files Browse the repository at this point in the history
- testing as much as possible for PurpleAirDataLogger public interfaces. Next step is move out more logic so the while true loops just call other functions that can be tested individually
  • Loading branch information
carlkidcrypto committed Nov 12, 2023
1 parent e223333 commit 7ab16d7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_purpleair_data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,44 @@ def test_purpleair_data_logger_error(self):
# Expected Result
self.assertEqual(retval.message, self.error_msg_str)
self.assertEqual(retval.__class__, PurpleAirDataLoggerError)

def test_purpleair_data_logger_getters_setters(self):
"""
Test PurpleAirDataLogger getters/setters
"""

# Setup
fake_url_request = "https://api.purpleair.com/v1/keys"

# Action and Expected Result
with requests_mock.Mocker() as m:
m.get(
fake_url_request,
text='{"api_version" : "1.1.1", "time_stamp": 123456789, "api_key_type": "READ"}',
status_code=200,
)
padl = PurpleAirDataLogger(PurpleAirApiReadKey="123456789")

padl.send_request_every_x_seconds = 100
self.assertEqual(padl.send_request_every_x_seconds, 100)

def test_purpleair_data_logger_store_sensor_data(self):
"""
Test PurpleAirDataLogger store_sensor_data method raises, since inherting classes
must implment it.
"""

# Setup
fake_url_request = "https://api.purpleair.com/v1/keys"

# Action and Expected Result
with requests_mock.Mocker() as m:
m.get(
fake_url_request,
text='{"api_version" : "1.1.1", "time_stamp": 123456789, "api_key_type": "READ"}',
status_code=200,
)
padl = PurpleAirDataLogger(PurpleAirApiReadKey="123456789")

with self.assertRaises(NotImplementedError):
padl.store_sensor_data({})

0 comments on commit 7ab16d7

Please sign in to comment.