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)
Пример #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)
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)
Пример #4
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)