示例#1
0
def get_rmc_config(request):
    """
    View to return the config file for a given rmc given
    an api key for the rmc account
    """
    context_dict = {}
    api_key = request.GET.get('api_key', '')
    context_dict['api_key'] = api_key

    rmc_account = Sesh_RMC_Account.objects.filter(api_key=api_key).first()

    if not rmc_account:
        logger.debug("There is no rmc account associated with the api key")
        logger.debug("Make sure you rmc site is configured on the server")
        return HttpResponseForbidden()

    site = rmc_account.site
    associated_sensors = get_all_associated_sensors(site)

    configuration, bmv_number = get_config_sensors(associated_sensors)
    context_dict['configuration']  = configuration
    context_dict['bmv_number'] = bmv_number

    conf = get_template('seshdash/configs/rmc_config.conf')

    return HttpResponse(conf.render(context_dict), content_type='text/plain')
示例#2
0
    def test_get_rmc_config(self):
        """
        Testing the generation of the rmc config file for a
        given file
        """

        response = self.client.get('/get_rmc_config', {'api_key': 'testing'})

        associated_sensors = get_all_associated_sensors(self.site)
        configuration, victron_device_number = get_config_sensors(
            associated_sensors)

        self.assertRegexpMatches(configuration, 'sensor_node_1')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Type'), 'text/plain')

        # Testing for invalid apikeys
        response = self.client.get('/get_rmc_config', {'api_key': 'incorrect'})
        self.assertEqual(response.status_code, 403)
    def test_get_rmc_config(self):
        """
        Testing the generation of the rmc config file for a
        given file
        """

        response = self.client.get('/get_rmc_config', {'api_key': 'testing'})

        associated_sensors = get_all_associated_sensors(self.site)
        configuration, victron_device_number = get_config_sensors(associated_sensors)

        self.assertRegexpMatches(configuration, 'emonTH_1')
        self.assertRegexpMatches(configuration, 'emonPi_')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Type'), 'text/plain')

	# Testing for invalid apikeys
        response = self.client.get('/get_rmc_config', {'api_key': 'incorrect'})
        self.assertEqual(response.status_code, 403)