Exemplo n.º 1
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)
Exemplo n.º 2
0
 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'
     }
Exemplo n.º 3
0
    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'
        }
Exemplo n.º 4
0
 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()
     self.db.tess.resetCounters()
 def setUp(self):
     try:
         os.remove(options['connection_string'])
     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)
Exemplo n.º 6
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}
        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 InstrDeployTestCase2(unittest.TestCase):


    TEST_INSTRUMENTS = [
        { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0},
        { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 10.0},
        { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 15.0},
        { 'name': 'test3', 'mac': '12:34:56:78:90:AD', 'calib': 10.0},
        { 'name': 'test3', 'mac': '12:34:56:78:90:AD', 'calib': 17.0},
        { 'name': 'test4', 'mac': '12:34:56:78:90:AE', 'calib': 10.0},
    ]


    TEST_DEPLOYMENTS2 = [
        { 'name': 'test1', 'site': 'Centro Equivocado'},
        { 'name': 'test2', 'site': 'Observatorio Astronomica de Mallorca'},
    ]


    @inlineCallbacks
    def setUp(self):
        try:
            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_DEPLOYMENTS2, f)
        self.db = DBaseService(parent=None, options=options)
        yield self.db.schema()
        yield self.registerInstrument()
       

    def tearDown(self):
        self.db.pool.close()


    @inlineCallbacks
    def registerInstrument(self):
        for row in self.TEST_INSTRUMENTS:
            yield deferLater(reactor, 0, lambda: None)
            yield self.db.register(row)


    def test_assign_wrong_loc(self):
        d = self.db.reloadService(options)
        return self.assertFailure(d, sqlite3.IntegrityError)
Exemplo n.º 8
0
 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()
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
    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'}
Exemplo n.º 12
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)
Exemplo n.º 13
0
 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'}
Exemplo n.º 14
0
else:
   options = None

# Start the logging subsystem
log_file = options['tessdb']['log_file']
startLogging(console=cmdline_opts.console, filepath=log_file)

# ------------------------------------------------
# Assemble application from its service components
# ------------------------------------------------

application = Application("TESSDB")

tessdbService  = TESSDBService(options['tessdb'], config_file)
tessdbService.setName(TESSDBService.NAME)
tessdbService.setServiceParent(application)

dbaseService = DBaseService(options['dbase'])
dbaseService.setName(DBaseService.NAME)
dbaseService.setServiceParent(tessdbService)

mqttService = MQTTService(options['mqtt'])
mqttService.setName(MQTTService.NAME)
mqttService.setServiceParent(tessdbService)

# --------------------------------------------------------
# Store direct links to subservices in our manager service
# --------------------------------------------------------


__all__ = [ "application" ]
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
0
class RegistryNominalTestCase(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()
        self.db.tess.resetCounters()

    def tearDown(self):
        self.db.pool.close()
    
    @inlineCallbacks
    def test_registerOneInstrument(self):
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 1)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,0)

    @inlineCallbacks
    def test_registerSameInstrTwice(self):
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 2)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,0)


    @inlineCallbacks
    def test_changeNameOnly(self):
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test2', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 2)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 1)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,0)
    
    @inlineCallbacks
    def test_changeConstantOnly(self):
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 17.0}
        yield self.db.register(row)
        #self.assertEqual(res, 0x01 | 0x04)
        self.assertEqual(self.db.tess.nregister, 2)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,1)
    
    @inlineCallbacks
    def test_changeNameAndConstant(self):
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test2', 'mac': '12:34:56:78:90:AB', 'calib': 17.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 2)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 1)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,1)

    @inlineCallbacks
    def test_failChangeName(self):
        '''
        Fail to change the second instrument name to the first's one 
        '''
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AC', 'calib': 10.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 3)
        self.assertEqual(self.db.tess.nCreation, 2)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  1)
        self.assertEqual(self.db.tess.nUpdCalibChange,0)

    @inlineCallbacks
    def test_failRegisterNew(self):
        '''
        Fail to register a second instrument with different MAC but same name
        '''
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AC', 'calib': 10.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 2)
        self.assertEqual(self.db.tess.nCreation, 1)
        self.assertEqual(self.db.tess.rejCreaDupName, 1)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  0)
        self.assertEqual(self.db.tess.nUpdCalibChange,0)

    @inlineCallbacks
    def test_failChangeNameConstantOk(self):
        '''
        Fail to change the second instrument name to the first's one
        but changes constant ok.
        '''
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 10.0}
        yield self.db.register(row)
        row = { 'name': 'test1', 'mac': '12:34:56:78:90:AC', 'calib': 17.0}
        yield self.db.register(row)
        self.assertEqual(self.db.tess.nregister, 3)
        self.assertEqual(self.db.tess.nCreation, 2)
        self.assertEqual(self.db.tess.rejCreaDupName, 0)
        self.assertEqual(self.db.tess.nUpdNameChange, 0)
        self.assertEqual(self.db.tess.rejUpdDupName,  1)
        self.assertEqual(self.db.tess.nUpdCalibChange,1)
Exemplo n.º 19
0
    options = None

# Start the logging subsystem
startLogging(console=cmdline_opts.console, filepath=cmdline_opts.log_file)

# ------------------------------------------------
# Assemble application from its service components
# ------------------------------------------------

application = Application("TESSDB")

tessdbService = TESSDBService(options['tessdb'], config_file)
tessdbService.setName(TESSDBService.NAME)
tessdbService.setServiceParent(application)

dbaseService = DBaseService(options['dbase'])
dbaseService.setName(DBaseService.NAME)
dbaseService.setServiceParent(tessdbService)

filterService = FilterService(options['filter'])
filterService.setName(FilterService.NAME)
filterService.setServiceParent(tessdbService)

mqttService = MQTTService(options['mqtt'])
mqttService.setName(MQTTService.NAME)
mqttService.setServiceParent(tessdbService)

# --------------------------------------------------------
# Store direct links to subservices in our manager service
# --------------------------------------------------------
class InstrDeployTestCase3(unittest.TestCase):

    TEST_INSTRUMENTS = [
        { 'name': 'test1', 'mac': '12:34:56:78:90:AB', 'calib': 10.0},
        { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 10.0},
        { 'name': 'test2', 'mac': '12:34:56:78:90:AC', 'calib': 15.0},
        { 'name': 'test3', 'mac': '12:34:56:78:90:AD', 'calib': 10.0},
        { 'name': 'test3', 'mac': '12:34:56:78:90:AD', 'calib': 17.0},
        { 'name': 'test4', 'mac': '12:34:56:78:90:AE', 'calib': 10.0},
    ]

    TEST_DEPLOYMENTS1 = [
        { 'name': 'test1', 'site': 'Centro de Recursos Asociativos El Cerro'},
        { 'name': 'test2', 'site': 'Observatorio Astronomica de Mallorca'},
    ]

    TEST_DEPLOYMENTS3 = [
        { 'name': 'wrong-tess1', 'site': 'Centro de Recursos Asociativos El Cerro'},
        { 'name': 'wrong-tess2', 'site': 'Observatorio Astronomico de Mallorca'},
    ]

    @inlineCallbacks
    def setUp(self):
        try:
            os.remove(options['connection_string'])
        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)
       
    def tearDown(self):
        self.db.pool.close()

    @inlineCallbacks
    def registerInstrument(self):
        for row in self.TEST_INSTRUMENTS:
            yield deferLater(reactor, 0, lambda: None)
            yield self.db.register(row)

    @inlineCallbacks
    def test_assign_wrong_instr(self):
        with open('tess_location.json','w') as f:
            json.dump(self.TEST_DEPLOYMENTS3, f)
        d = self.db.reloadService(options)
        rows = yield self.db.pool.runQuery('SELECT name,location_id,tess_id FROM tess_t ORDER BY tess_id ASC')
        self.assertEqual( rows[0][0], 'test1')
        self.assertEqual( rows[0][2], 1)
        self.assertEqual( rows[0][1], 0)

        self.assertEqual( rows[1][0], 'test2')
        self.assertEqual( rows[1][2], 2)
        self.assertEqual( rows[1][1], 1)

        self.assertEqual( rows[2][0], 'test2')
        self.assertEqual( rows[2][2], 3)
        self.assertEqual( rows[2][1], 1)
Exemplo n.º 21
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)
Exemplo n.º 22
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)