class UpdateRegisteredTestCase(unittest.TestCase): @inlineCallbacks def setUp(self): try: os.remove(options['connection_string']) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0} yield self.db.register(row) def tearDown(self): self.db.pool.close() @inlineCallbacks def test_updateWithInstrument(self): ''' Test insert a reading with instrument registered. It should be inserted ''' now = datetime.datetime.utcnow() row = { 'name': 'test1', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp': now} yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 1) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateTooFast(self): ''' Test fast inserting two readings with instrument registered. The first one should be inserted, the second one not. ''' now = datetime.datetime.utcnow() row = { 'name': 'test1', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp': now} yield self.db.update(row) row = { 'name': 'test1', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp': now} yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 1) self.assertEqual(self.db.tess_readings.rejOther, 0)
class UpdateUnregisteredTestCase(unittest.TestCase): @inlineCallbacks def setUp(self): try: os.remove(options['connection_string']) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() def tearDown(self): self.db.pool.close() @inlineCallbacks def test_updateWithNoInstrument(self): ''' Test insert reading with no instrument registered. It should not be inserted ''' now = datetime.datetime.utcnow() row = { 'name': 'test1', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp': now} yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 1) self.assertEqual(self.db.tess_readings.rejNotRegistered,1) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)
class UpdateUnregisteredTestCase(unittest.TestCase): @inlineCallbacks def setUp(self): try: os.remove(options["connection_string"]) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() def tearDown(self): self.db.pool.close() @inlineCallbacks def test_updateWithNoInstrument(self): """ Test insert reading with no instrument registered. It should not be inserted """ now = datetime.datetime.utcnow() row = { "name": "test1", "seq": 1, "freq": 1000.01, "mag": 12.0, "tamb": 0, "tsky": -12, "tstamp": now, "tstamp_src": "Subscriber", } yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 1) self.assertEqual(self.db.tess_readings.rejNotRegistered, 1) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)
class MobileInstrumentTestCase(unittest.TestCase): TEST_INSTRUMENTS = [{ 'name': 'TESS-AH', 'mac': '12:34:56:78:90:AB', 'calib': 10.0 }, { 'name': 'TESS-OAM', 'mac': '21:34:56:78:90:AB', 'calib': 10.0 }] @inlineCallbacks def setUp(self): try: options['connection_string'] = 'mobile.db' os.remove(options['connection_string']) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() yield self.registerInstrument() self.row1 = { 'name': 'TESS-AH', 'seq': 1, 'freq': 1000.01, 'mag': 12.0, 'tamb': 0, 'tsky': -12, 'lat': 40.418561, 'long': -3.551502, 'height': 650.0, 'tstamp_src': 'Subscriber' } self.row2 = { 'name': 'TESS-OAM', 'seq': 1, 'freq': 1000.01, 'mag': 12.0, 'tamb': 0, 'tsky': -12, 'lat': 39.64269, 'long': 2.950533, 'height': 100.0, 'tstamp_src': 'Subscriber' } def tearDown(self): self.db.pool.close() # -------------- # Helper methods # -------------- @inlineCallbacks def registerInstrument(self): for row in self.TEST_INSTRUMENTS: yield self.db.register(row) # ---------- # Test cases # ---------- @inlineCallbacks def test_updateAtDaytime(self): ''' Both will be rejected, since the timestamp at both locations is always at day, no matter the day of the year ''' now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 2) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtNight(self): ''' Both will be accepted, since the timestamp at both locations is always at night, no matter the day of the year ''' now = datetime.datetime(2016, 02, 21, 22, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtTwilight(self): ''' OAM observatory at night -> acepted AH observatory at day -> rejected ''' now = datetime.datetime(2016, 02, 21, 17, 35, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 1) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)
class FixedInstrumentTestCase(unittest.TestCase): TEST_INSTRUMENTS = [{ 'name': 'TESS-AH', 'mac': '12:34:56:78:90:AB', 'calib': 10.0 }, { 'name': 'TESS-OAM', 'mac': '21:34:56:78:90:AB', 'calib': 10.0 }] TEST_DEPLOYMENTS1 = [ { 'name': 'TESS-AH', 'site': 'Centro de Recursos Asociativos El Cerro' }, { 'name': 'TESS-OAM', 'site': 'Observatorio Astronomico de Mallorca' }, ] @inlineCallbacks def setUp(self): try: options['connection_string'] = 'fixed.db' os.remove(options['connection_string']) #os.remove('tess_location.json') #os.remove('locations.json') except OSError as e: pass with open('locations.json', 'w') as f: json.dump(TEST_LOCATIONS, f) with open('tess_location.json', 'w') as f: json.dump(self.TEST_DEPLOYMENTS1, f) self.db = DBaseService(parent=None, options=options) yield self.db.schema() yield self.registerInstrument() yield self.db.reloadService(options) self.row1 = { 'name': 'TESS-AH', 'seq': 1, 'freq': 1000.01, 'mag': 12.0, 'tamb': 0, 'tsky': -12, 'tstamp_src': 'Subscriber' } self.row2 = { 'name': 'TESS-OAM', 'seq': 1, 'freq': 1000.01, 'mag': 12.0, 'tamb': 0, 'tsky': -12, 'tstamp_src': 'Subscriber' } def tearDown(self): self.db.pool.close() # -------------- # Helper methods # -------------- @inlineCallbacks def registerInstrument(self): for row in self.TEST_INSTRUMENTS: yield self.db.register(row) # ---------- # Test cases # ---------- @inlineCallbacks def test_updateRejLackSunrise(self): ''' Both rejected by lack of sunrise/sunse data in their locations ''' now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 2) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtDaytime(self): ''' Both will be rejected, since the timestamp at both locations is always at day, no matter the day of the year ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 2) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtNight(self): ''' Both will be accepted, since the timestamp at both locations is always at night, no matter the day of the year ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 22, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtTwilight(self): ''' OAM observatory at night -> acepted AH observatory at day -> rejected ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 17, 35, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 1) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)
class UpdateRegisteredTestCase(unittest.TestCase): @inlineCallbacks def setUp(self): try: os.remove(options["connection_string"]) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() row = {"name": "test1", "mac": "12:34:56:78:90:AB", "calib": 10.0} yield self.db.register(row) def tearDown(self): self.db.pool.close() @inlineCallbacks def test_updateWithInstrument(self): """ Test insert a reading with instrument registered. It should be inserted """ now = datetime.datetime.utcnow() row = { "name": "test1", "seq": 1, "freq": 1000.01, "mag": 12.0, "tamb": 0, "tsky": -12, "tstamp": now, "tstamp_src": "Subscriber", } yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 1) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateTooFast(self): """ Test fast inserting two readings with instrument registered. The first one should be inserted, the second one not. """ now = datetime.datetime.utcnow() row = { "name": "test1", "seq": 1, "freq": 1000.01, "mag": 12.0, "tamb": 0, "tsky": -12, "tstamp": now, "tstamp_src": "Subscriber", } yield self.db.update(row) row = { "name": "test1", "seq": 1, "freq": 1000.01, "mag": 12.0, "tamb": 0, "tsky": -12, "tstamp": now, "tstamp_src": "Subscriber", } yield self.db.update(row) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered, 0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 1) self.assertEqual(self.db.tess_readings.rejOther, 0)
class MobileInstrumentTestCase(unittest.TestCase): TEST_INSTRUMENTS = [ { 'name': 'TESS-AH', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}, { 'name': 'TESS-OAM', 'mac': '21:34:56:78:90:AB', 'calib': 10.0} ] @inlineCallbacks def setUp(self): try: options['connection_string'] = 'mobile.db' os.remove(options['connection_string']) except OSError as e: pass self.db = DBaseService(parent=None, options=options) yield self.db.schema() yield self.registerInstrument() self.row1 = { 'name': 'TESS-AH', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'lat': 40.418561, 'long': -3.551502, 'height': 650.0, 'tstamp_src': 'Subscriber'} self.row2 = { 'name': 'TESS-OAM', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'lat': 39.64269, 'long': 2.950533, 'height': 100.0, 'tstamp_src': 'Subscriber'} def tearDown(self): self.db.pool.close() # -------------- # Helper methods # -------------- @inlineCallbacks def registerInstrument(self): for row in self.TEST_INSTRUMENTS: yield self.db.register(row) # ---------- # Test cases # ---------- @inlineCallbacks def test_updateAtDaytime(self): ''' Both will be rejected, since the timestamp at both locations is always at day, no matter the day of the year ''' now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 2) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtNight(self): ''' Both will be accepted, since the timestamp at both locations is always at night, no matter the day of the year ''' now = datetime.datetime(2016, 02, 21, 22, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtTwilight(self): ''' OAM observatory at night -> acepted AH observatory at day -> rejected ''' now = datetime.datetime(2016, 02, 21, 17, 35, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 1) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)
class FixedInstrumentTestCase(unittest.TestCase): TEST_INSTRUMENTS = [ { 'name': 'TESS-AH', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}, { 'name': 'TESS-OAM', 'mac': '21:34:56:78:90:AB', 'calib': 10.0} ] TEST_DEPLOYMENTS1 = [ { 'name': 'TESS-AH', 'site': 'Centro de Recursos Asociativos El Cerro'}, { 'name': 'TESS-OAM', 'site': 'Observatorio Astronomico de Mallorca'}, ] @inlineCallbacks def setUp(self): try: options['connection_string'] = 'fixed.db' os.remove(options['connection_string']) #os.remove('tess_location.json') #os.remove('locations.json') except OSError as e: pass with open('locations.json','w') as f: json.dump(TEST_LOCATIONS, f) with open('tess_location.json','w') as f: json.dump(self.TEST_DEPLOYMENTS1, f) self.db = DBaseService(parent=None, options=options) yield self.db.schema() yield self.registerInstrument() yield self.db.reloadService(options) self.row1 = { 'name': 'TESS-AH', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp_src': 'Subscriber'} self.row2 = { 'name': 'TESS-OAM', 'seq': 1, 'freq': 1000.01, 'mag':12.0, 'tamb': 0, 'tsky': -12, 'tstamp_src': 'Subscriber'} def tearDown(self): self.db.pool.close() # -------------- # Helper methods # -------------- @inlineCallbacks def registerInstrument(self): for row in self.TEST_INSTRUMENTS: yield self.db.register(row) # ---------- # Test cases # ---------- @inlineCallbacks def test_updateRejLackSunrise(self): ''' Both rejected by lack of sunrise/sunse data in their locations ''' now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 2) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtDaytime(self): ''' Both will be rejected, since the timestamp at both locations is always at day, no matter the day of the year ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 13, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 2) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtNight(self): ''' Both will be accepted, since the timestamp at both locations is always at night, no matter the day of the year ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 22, 00, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 0) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0) @inlineCallbacks def test_updateAtTwilight(self): ''' OAM observatory at night -> acepted AH observatory at day -> rejected ''' yield self.db.sunrise(today=TODAY) now = datetime.datetime(2016, 02, 21, 17, 35, 00) self.row1['tstamp'] = now yield self.db.update(self.row1) self.row2['tstamp'] = now yield self.db.update(self.row2) self.assertEqual(self.db.tess_readings.nreadings, 2) self.assertEqual(self.db.tess_readings.rejNotRegistered,0) self.assertEqual(self.db.tess_readings.rejLackSunrise, 0) self.assertEqual(self.db.tess_readings.rejSunrise, 1) self.assertEqual(self.db.tess_readings.rejDuplicate, 0) self.assertEqual(self.db.tess_readings.rejOther, 0)