Exemplo n.º 1
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.º 2
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)