コード例 #1
0
    def test_fixtureCreation(self):
        with orm.db_session:

            plantsNS = ns.loads("""\
                plants:
                - plant:
                    name: alcolea
                    codename: SCSOM04
                    description: la bonica planta
                    meters:
                    - meter:
                        name: '1234578'
                    inverters:
                    - inverter:
                        name: '5555'
                    - inverter:
                        name: '6666'
                    irradiationSensors:
                    - irradiationSensor:
                        name: alberto
                    temperatureModuleSensors:
                    - temperatureModuleSensor:
                        name: pol
                    temperatureAmbientSensors:
                    - temperatureAmbientSensor:
                        name: joana
            """)

            importPlants(self.pony.db, plantsNS)

        #TODO test the whole fixture, not just the plant data
        expectedPlantns = exportPlants(self.pony.db)
        self.assertNsEqual(expectedPlantns, plantsNS)
コード例 #2
0
 def setupPlants(self, time, alternativeMeter="12345678", plantsData = None):
     delta = dt.timedelta(minutes=30)
     plantsns = self.samplePlantsNS(altMeter=alternativeMeter)
     importPlants(self.pony.db, plantsns)
     plantsData = plantsData or self.samplePlantsData(time, delta, altMeter=alternativeMeter)
     self.pony.db.Plant.insertPlantsData(plantsData)
     orm.flush()
コード例 #3
0
    def test_Plant_importPlants__manyPlants(self):
        plantsns = self.samplePlantsNS()

        importPlants(self.pony.db, plantsns)

        resultPlantns = exportPlants(self.pony.db, skipEmpty=True)

        self.assertNsEqual(plantsns, resultPlantns)
コード例 #4
0
    def test__Meter_updateMeterProtocol_deprecatedMetersIgnored(self):
        plantsns = self.samplePlantsNS()
        importPlants(self.pony.db, plantsns)

        # Should not fail
        self.pony.db.Meter.updateMeterProtocol({
            '1234578': 'moxa',
            'OLDMETER': 'moxa',
        })
        meter = self.pony.db.Meter.get(name='OLDMETER')
        self.assertEqual(meter, None)
コード例 #5
0
    def test__Meter_updateMeterProtocol_unknownMetersIgnored(self):
        # This adds many more meters such as 9876 which we are not updating
        plantsns = self.samplePlantsNS()
        importPlants(self.pony.db, plantsns)

        self.pony.db.Meter.updateMeterProtocol({
            '1234578': 'moxa',
        })
        meter = self.pony.db.Meter.get(name='1234578')
        self.assertEqual(meter.connection_protocol, 'moxa')
        meter = self.pony.db.Meter.get(name='9876')
        self.assertEqual(meter.connection_protocol, 'ip')
コード例 #6
0
    def setUpPlant(self):
        plantsns = ns.loads("""\
            plants:
            - plant:
                name: Alcolea
                codename: SCSOM04
                description: la bonica planta
                inverters:
                - inverter:
                    name: 'inversor1'
            """)

        importPlants(self.pony.db, plantsns)
コード例 #7
0
    def test_Plant_importPlants__ManyMunicipalities(self):
        plantsns = ns()

        municipalitiesns = ns.loads("""\
        - municipality:
            name: Figueres
            ineCode: '17066'
        - municipality:
            name: Girona
            ineCode: '17003'
            """)

        plantsns['municipalities'] = municipalitiesns

        importPlants(self.pony.db, plantsns)

        storedMunicipalitiesns = exportPlants(self.pony.db)
        plantsns['plants'] = []
        self.assertNsEqual(plantsns, storedMunicipalitiesns)
コード例 #8
0
    def test_Plant_importPlants__manyPlants_ManyMunicipalities(self):

        plantsns = self.samplePlantsNS()

        # municipalitiesns = ns.loads("""\
        # - municipality:
        #     name: Figueres
        #     ineCode: '17066'
        # - municipality:
        #     name: Girona
        #     ineCode: '17003'
        #     """)

        # plantsns['municipalities'] = municipalitiesns

        importPlants(self.pony.db, plantsns)
        # orm.flush()

        resultPlantns = exportPlants(self.pony.db, skipEmpty=True)
        self.assertNsEqual(plantsns, resultPlantns)
コード例 #9
0
    def test__Plant_str2model__sameNameDifferentPlant(self):
        plantsns = self.samplePlantsNS()
        plantsns.plants[0].plant.inverters[0].inverter.name = '4444'
        importPlants(self.pony.db, plantsns)
        orm.flush()

        plant = self.pony.db.Plant.get(name='alcolea')

        alcoleainverter = self.pony.db.Plant.str2device(
            plant, 'Inverter', '4444')

        self.assertNotEqual(alcoleainverter, None)

        plant = self.pony.db.Plant.get(name='figuerea')

        figuereainverter = self.pony.db.Plant.str2device(
            plant, 'Inverter', '4444')

        self.assertNotEqual(figuereainverter, None)

        self.assertNotEqual(alcoleainverter.plant.name,
                            figuereainverter.plant.name)
コード例 #10
0
    def test__Plant_importPlantsData__many(self):
        plantsns = self.samplePlantsNS()
        importPlants(self.pony.db, plantsns)

        time = dt.datetime(2020,
                           12,
                           10,
                           15,
                           5,
                           10,
                           588861,
                           tzinfo=dt.timezone.utc)
        delta = dt.timedelta(minutes=30)
        plantsData = self.samplePlantsData(time, delta)
        self.pony.db.Plant.insertPlantsData(plantsData)
        # orm.flush()

        for plantData in plantsData:
            self.assertDictEqual(
                dict(plantData),
                self.pony.db.Plant.get(name=plantData['plant']).plantData(
                    skipEmpty=True))
コード例 #11
0
    def test_Municipality__importMunicipality__OneMunicipality(self):
        plantsns = ns()

        municipalitiesns = ns.loads("""\
        - municipality:
            name: Figueres
            ineCode: '17066'
            countryCode: ES
            country: Spain
            regionCode: '08'
            region: Catalonia
            provinceCode: '17'
            province: Girona
            """)

        plantsns['municipalities'] = municipalitiesns

        importPlants(self.pony.db, plantsns)

        storedMunicipalitiesns = exportPlants(self.pony.db)
        plantsns['plants'] = []
        self.assertNsEqual(plantsns, storedMunicipalitiesns)
コード例 #12
0
def importPlantsFromFile(db, yamlFilename):
    nsplants = ns.load(yamlFilename)

    with orm.db_session:
        importPlants(db, nsplants)