class StatusTestCase(TestCase):
    @override_settings(DEBUG=True)
    def setUp(self):

        self.db_name = 'test_db'
        self.Client = Influx()
        try:
            self.Client.create_database(self.db_name)
        except:
            self.Client.delete_database(self.db_name)
            sleep(1)
            self.Client.create_database(self.db_name)
            pass

        self.vrm = VRM_Account.objects.create(vrm_user_id='*****@*****.**',vrm_password='******')
        self.location = Geoposition(-1.5,29.5)
        #create Sesh_Site
        self.site = Sesh_Site.objects.create(site_name='Mukuyu',
                                             comission_date = timezone.datetime(2014,12,12,12,12),
                                             location_city='kigali',
                                             location_country='Rwanda',
                                             vrm_account=self.vrm,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=24,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=1200,
                                             has_genset = True,
                                             has_grid=True)

        #creating Site_Weather_Data
        self.site_weather = Site_Weather_Data.objects.create(site = self.site,
                                                             date = timezone.datetime(2016, 10, 10, 10, 10),
                                                             temp = 0,
                                                             condition = "none",
                                                             cloud_cover = 1,
                                                             sunrise = timezone.now(),
                                                             sunset = timezone.now())

        Sesh_User.objects.create_superuser(username='******',password='******',email='*****@*****.**')

    def test_status(self):
        #insert_point in influx
        self.Client.insert_point(self.site,'soc',20.0)
        sites = Sesh_Site.objects.all()
        response = get_quick_status(sites)
        print 'The reponse is: %s' % response
        self.assertEqual(response[0]['battery'],'red')
        self.assertEqual(response[0]['weather'],'yellow')

    #testing get_site_measurements function
    def test_get_measurements(self):
        site_measurements = get_site_measurements(self.site)
        measurements = Site_Measurements.objects.all()
        self.assertEqual(len(measurements),1)
Esempio n. 2
0
class StatusTestCase(TestCase):
    @override_settings(DEBUG=True)
    def setUp(self):

        self.db_name = 'test_db'
        self.Client = Influx()
        try:
            self.Client.create_database(self.db_name)
        except:
            self.Client.delete_database(self.db_name)
            sleep(1)
            self.Client.create_database(self.db_name)
            pass

        self.vrm = VRM_Account.objects.create(vrm_user_id='*****@*****.**',
                                              vrm_password='******')
        self.location = Geoposition(-1.5, 29.5)
        #create Sesh_Site
        self.site = Sesh_Site.objects.create(site_name='Mukuyu',
                                             comission_date=timezone.datetime(
                                                 2014, 12, 12, 12, 12),
                                             location_city='kigali',
                                             location_country='Rwanda',
                                             vrm_account=self.vrm,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=24,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=1200,
                                             has_genset=True,
                                             has_grid=True)

        #creating Site_Weather_Data
        self.site_weather = Site_Weather_Data.objects.create(
            site=self.site,
            date=timezone.datetime(2016, 10, 10, 10, 10),
            temp=0,
            condition="none",
            cloud_cover=1,
            sunrise=timezone.now(),
            sunset=timezone.now())

        Sesh_User.objects.create_superuser(username='******',
                                           password='******',
                                           email='*****@*****.**')

    def test_status(self):
        #insert_point in influx
        self.Client.insert_point(self.site, 'soc', 20.0)
        sites = Sesh_Site.objects.all()
        response = get_quick_status(sites)
        print 'The reponse is: %s' % response
        self.assertEqual(response[0]['battery'], 'red')
        self.assertEqual(response[0]['weather'], 'yellow')

    #testing get_site_measurements function
    def test_get_measurements(self):
        site_measurements = get_site_measurements(self.site)
        measurements = Site_Measurements.objects.all()
        self.assertEqual(len(measurements), 1)
class RMCTestCase(TestCase):
    def setUp(self):

        self.VRM = VRM_Account.objects.create(vrm_user_id='*****@*****.**',vrm_password="******")
        self.location = Geoposition(52.5,24.3)
        self._influx_db_name = 'test_db'

        self.i = Influx(database=self._influx_db_name)

        try:
            self.i.create_database(self._influx_db_name)
            #Generate random data  points for 24h
        except:
           self.i.delete_database(self._influx_db_name)
           sleep(1)
           self.i.create_database(self._influx_db_name)
           pass



        self.site = Sesh_Site.objects.create(site_name=u"Test_aggregate",
                                             comission_date=timezone.datetime(2015, 12, 11, 22, 0),
                                             location_city=u"kigali",
                                             location_country=u"rwanda",
                                             vrm_account = self.VRM,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=12,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=12321,
                                             has_genset=True,
                                             has_grid=True)
        self.test_rmc_account = Sesh_RMC_Account.objects.create(site = self.site, api_key='lcda5c15ae5cdsac464zx8f49asc16a')

        timestamp = timezone.localtime(timezone.now()) - timedelta(minutes=60)
        #print ""
        #print timestamp
        #timestamp = timezone.now()
        self.i.insert_point(self.site,'status', 1, time = timestamp)

        sleep(1)
        self.test_user = Sesh_User.objects.create_user(username="******",email="*****@*****.**",password="******")
        #assign a user to the sites
        assign_perm("view_Sesh_Site",self.test_user,self.site)


    def tearDown(self):
        #self.i.delete_database(self._influx_db_name)
        pass

    def test_rmc_stat(self):
        """
        Check that when a bom data point is added that the corresponding rmc status is triggered
        """
        rmc_status_update()

        dps = RMC_status.objects.filter(site=self.site)
        self.assertNotEqual(dps.count(), 0)

        sleep(2)
        dps = dps.first()
        self.assertEqual(dps.minutes_last_contact, 60)
class RMCTestCase(TestCase):
    def setUp(self):

        self.VRM = VRM_Account.objects.create(vrm_user_id='*****@*****.**',
                                              vrm_password="******")
        self.location = Geoposition(52.5, 24.3)
        self._influx_db_name = 'test_db'

        self.i = Influx(database=self._influx_db_name)

        try:
            self.i.create_database(self._influx_db_name)
            #Generate random data  points for 24h
        except:
            self.i.delete_database(self._influx_db_name)
            sleep(1)
            self.i.create_database(self._influx_db_name)
            pass

        self.site = Sesh_Site.objects.create(site_name=u"Test_aggregate",
                                             comission_date=timezone.datetime(
                                                 2015, 12, 11, 22, 0),
                                             location_city=u"kigali",
                                             location_country=u"rwanda",
                                             vrm_account=self.VRM,
                                             installed_kw=123.0,
                                             position=self.location,
                                             system_voltage=12,
                                             number_of_panels=12,
                                             vrm_site_id=213,
                                             battery_bank_capacity=12321,
                                             has_genset=True,
                                             has_grid=True)
        self.test_rmc_account = Sesh_RMC_Account.objects.create(
            site=self.site, api_key='lcda5c15ae5cdsac464zx8f49asc16a')

        timestamp = timezone.localtime(timezone.now()) - timedelta(minutes=60)
        #print ""
        #print timestamp
        #timestamp = timezone.now()
        self.i.insert_point(self.site, 'status', 1, time=timestamp)

        sleep(1)
        self.test_user = Sesh_User.objects.create_user(username="******",
                                                       email="*****@*****.**",
                                                       password="******")
        #assign a user to the sites
        assign_perm("view_Sesh_Site", self.test_user, self.site)

    def tearDown(self):
        #self.i.delete_database(self._influx_db_name)
        pass

    def test_rmc_stat(self):
        """
        Check that when a bom data point is added that the corresponding rmc status is triggered
        """
        rmc_status_update()

        dps = RMC_status.objects.filter(site=self.site)
        self.assertNotEqual(dps.count(), 0)

        sleep(2)
        dps = dps.first()
        self.assertEqual(dps.minutes_last_contact, 60)