def testGoodBadGoodResponse(self, mock_eof, mock_get, mock_empty, mock_sleep, mock_database): ''' Sends a "good" RTL_433 response, then a "bad" (blank) response, then good again. Test should continue without any faults. ''' DB_FILE = "/tmp/tempdb.sqlite" RTL433 = "/home/ciaran/Code/rtl_433/build/src/rtl_433" DEBUG = False empty_string = ''.encode() good_string = ( '{"time" : "@0.000000s",' ' "model" : "WG-PB12V1",' ' "id" : 8,' ' "temperature_C" : 20.900,' ' "io" : "111111110011001001100001011010001111111101001100"}' ).encode() calls = [good_string, empty_string, good_string] mock_get.side_effect = calls db = rtl_433_2sqlite.initDatabase(sq, DB_FILE) try: rtl_433_2sqlite.startSubProcess(RTL433, db, DEBUG) except CallableExhausted: # To catch the error thrown by third loop, see ErrorAfter() pass self.assertEqual(mock_get.call_count, 3) # check database calls. self.assertEqual(mock_database.call_count, 2) # check database calls. json_good = json.loads(good_string.decode('utf-8')) expected = [((json_good, ), ), ((json_good, ), )] self.assertEqual(mock_database.call_args_list, expected)
def setUp(self): ''' ''' db_path = '/tmp/test_db.sqlite' try: os.remove(db_path) except FileNotFoundError: # Not a problem. pass self.db_path = "/tmp/test_db.sqlite" self.db = rtl_433_2sqlite.initDatabase(sq, self.db_path) self.db.connect()
def testRTL4332sqlitePIDDeleted(self, mock_eof, mock_get, mock_empty, mock_sleep, mock_database, mock_getpid): ''' Test that when RTL_433_2sqlite been errors out that the PID file is no longer present. ''' DB_FILE = "/tmp/tempdb.sqlite" RTL433 = "/home/ciaran/Code/rtl_433/build/src/rtl_433" DEBUG = False db = rtl_433_2sqlite.initDatabase(sq, DB_FILE) rtl_433_2sqlite.startSubProcess(RTL433, db, DEBUG) with self.assertRaises(FileNotFoundError): open('/tmp/rtl_433_2sqlite.pid')
def testBlankResponse(self, mock_eof, mock_get, mock_empty, mock_sleep, mock_database): ''' Sends a blank ('') response from rtl_433 to rtl_433_2sqlite. ''' DB_FILE = "/tmp/tempdb.sqlite" RTL433 = "/home/ciaran/Code/rtl_433/build/src/rtl_433" DEBUG = False empty_string = ''.encode() mock_get.return_value = empty_string db = rtl_433_2sqlite.initDatabase(sq, DB_FILE) rtl_433_2sqlite.startSubProcess(RTL433, db, DEBUG) self.assertEqual(mock_get.call_count, 2) # Data retrived from # fileReader self.assertEqual(mock_database.call_count, 0) # Should be no database
#! /usr/bin/env python3 # -*- coding: utf-8 -*- # # Starts the RTL_433_2sqlite logger for logging temperature sensor data from # RTL_433 # CiarĂ¡n Mooney 2017 import rtl_433_2sqlite as to_sqlite # cannot have 2sqlite, invalid syntax import sqlite3 as sq # BEGIN CONFIG DB_FILE = "/tmp/tempdb.sqlite" RTL433 = "/home/ciaran/Code/rtl_433/build/src/rtl_433" DEBUG = False TESTS = "/home/ciaran/Code/rtl_433_tests/" # END CONFIG if __name__ == '__main__': db = to_sqlite.initDatabase(sq, DB_FILE) to_sqlite.startSubProcess(RTL433, db, DEBUG) print("Closing down")