コード例 #1
0
ファイル: tests.py プロジェクト: mappsys/OpenProximity
    def test_006_push_sdp_data_into_server(self):
	for key in ['server', 'hash_id', 'password']:
	    self.assertTrue('agent2_%s' % key in environ)
    	    methods.setSetting(key, environ['agent2_%s' % key])

	camp1 = op_models.MarketingCampaign(service=0, enabled=False)
	camp2 = op_models.MarketingCampaign(service=1, enabled=False)
	camp1.save()
	camp2.save()

	amount_records=randrange(10,30)
	self.__generate_sdp_records(amount_records)

	camp1.enabled=True
	camp1.save()
	self.__generate_sdp_records(amount_records)

	camp2.enabled=True
	camp2.save()
	self.__generate_sdp_records(amount_records)


	pks=methods.getLockOverRecords(models.uploadSDPRecord)
	records = methods.getRecordsForUpload(models.uploadSDPRecord, pks)
        remotes = methods.getRemotesForUpload(models.uploadSDPRecord, pks)

	self.assertEqual(amount_records*3, 
	    methods.pushRecords(models.uploadSDPRecord, records, remotes))
	op_models.MarketingCampaign.objects.filter(pk__in=[camp1.pk, camp2.pk]).delete()
コード例 #2
0
def dosetup(**kwargs):
    if 'enabled' not in kwargs:
        kwargs['enabled'] = False

    kwargs['server'] = kwargs['server'][:-1]  # take out extra /
    for set in [
            'hash_id', 'server', 'password', 'enabled', 'cron_minute',
            'cron_hour', 'cron_dom', 'cron_month', 'cron_dow'
    ]:
        setSetting(set, kwargs[set])

    old_crontab = Popen(['crontab', '-l'], stdout=PIPE).communicate()[0]
    print old_crontab

    filename = tempfile.mkstemp('crontab')[1]
    new_crontab = file(filename, 'w')
    for line in old_crontab.splitlines():
        if line.find('pushrecords') == -1:
            new_crontab.write('%s\n' % line)

    if kwargs['enabled']:
        line = '%(cron_minute)s %(cron_hour)s %(cron_dom)s %(cron_month)s %(cron_dow)s' % kwargs
        line = '%s cd /opt/openproximity2; /bin/bash manager.sh egg_command pushrecords >> /tmp/pushrecords.log' % line
        new_crontab.write('%s\n' % line)
    new_crontab.close()

    call(['crontab', filename])
    print Popen(['crontab', '-l'], stdout=PIPE).communicate()[0]
    os.unlink(filename)
コード例 #3
0
ファイル: views.py プロジェクト: OpenProximity/plugins-agent2
def dosetup(**kwargs):
    if 'enabled' not in kwargs:
	kwargs['enabled'] = False

    kwargs['server']=kwargs['server'][:-1] # take out extra /
    for set in ['hash_id', 'server', 'password', 'enabled',
		'cron_minute', 'cron_hour', 'cron_dom', 'cron_month', 'cron_dow']:
	setSetting(set, kwargs[set])

    old_crontab=Popen(['crontab', '-l'], stdout=PIPE).communicate()[0]
    print old_crontab

    filename = tempfile.mkstemp('crontab')[1]
    new_crontab=file(filename, 'w')
    for line in old_crontab.splitlines():
	if line.find('pushrecords')==-1:
	    new_crontab.write('%s\n' % line)

    if kwargs['enabled']:
	line = '%(cron_minute)s %(cron_hour)s %(cron_dom)s %(cron_month)s %(cron_dow)s' % kwargs
	line = '%s cd /opt/openproximity2; /bin/bash manager.sh egg_command pushrecords >> /tmp/pushrecords.log' % line
	new_crontab.write('%s\n' % line)
    new_crontab.close()

    call(['crontab', filename])
    print Popen(['crontab', '-l'], stdout=PIPE).communicate()[0]
    os.unlink(filename)
コード例 #4
0
ファイル: tests.py プロジェクト: mappsys/OpenProximity
    def test_007_test_helper(self):
	for key in ['server', 'hash_id', 'password']:
	    self.assertTrue('agent2_%s' % key in environ)
    	    methods.setSetting(key, environ['agent2_%s' % key])

	amount_records=randrange(10,30)
	self.__generate_found_records(randrange(10,30))
	camp1=op_models.MarketingCampaign(service=randrange(0,1), enabled=True)
	camp1.save()
	self.__generate_sdp_records(randrange(10,30))
	self.assertTrue(methods.doRecordsAndLog())
	op_models.MarketingCampaign.objects.filter(pk__in=[camp1.pk]).delete()
コード例 #5
0
ファイル: tests.py プロジェクト: mappsys/OpenProximity
    def test_004_push_scan_data_into_server(self):
	for key in ['server', 'hash_id', 'password']:
	    self.assertTrue('agent2_%s' % key in environ)
    	    methods.setSetting(key, environ['agent2_%s' % key])

	amount_records=randrange(10,30)
	self.__generate_found_records(amount_records)

	pks=methods.getLockOverRecords(models.uploadFoundRecord)
	records = methods.getRecordsForUpload(models.uploadFoundRecord, pks)
        remotes = methods.getRemotesForUpload(models.uploadFoundRecord, pks)
        
	self.assertEqual(amount_records, 
		methods.pushRecords(models.uploadFoundRecord, records, remotes)
	)
コード例 #6
0
ファイル: tests.py プロジェクト: mappsys/OpenProximity
    def test_002_set_settings(self):
	self.assertEqual(methods.setSetting('enabled', True), True)
	self.assertEqual(methods.setSetting('server', 'http://test.com'),
						    'http://test.com')