Esempio n. 1
0
def populate():
	""" Test data """
	db.flushdb()
	"""
	print "[ MANAGER ]: Inserting test data"
	nic = ['Bluetooth', 'Wifi', 'Xbee']
	boards = ['Arduino UNO', 'Arduino Nano', 'Arduino Micro', 'BeagleBone Black',
		'Raspberry Pi A+', 'Raspberry Pi B+', 'Trinket Pro', 'Waspmote']
	signal = ['A', 'D']
	direction = ['R', 'W']
	for i in range(1, 5):
		node = {}
		node[N_NAME] = "Super Node " + str(i)
		node[N_BOARD] = boards[random.randint(0, len(boards) - 1)]
		node[N_NIC] = nic[random.randint(0, len(nic) - 1)]
		sensors = []
		for j in range(0, 3):
			sensor = {}
			sensor[S_NAME] = 'TMP3' + str(j)
			sensor[S_SIGNAL] = signal[random.randint(0, len(signal) - 1)]
			sensor[S_PIN] = random.randint(0, 10)
			sensor[S_DIRECTION] = direction[random.randint(0, len(direction) - 1)]
			sensor[S_REFRESH] = 1000 * random.randint(1, 10)
			sensors.append(sensor)
		node[N_SENSORS] = sensors
		insert_node(node)
	"""
	"""
	node = {}
	node[N_NAME] = "Testing Node "
	node[N_BOARD] = 'Arduino Uno'
	node[N_NIC] = 'Bluetooth'
	node[N_ADDR] = '/dev/ttyACM0'
	sensors = []
	sensor = {}
	sensor[S_NAME] = 'TESTING SENSOR'
	sensor[S_SIGNAL] = 'D'
	sensor[S_PIN] = '7'
	sensor[S_DIRECTION] = 'W'
	sensor[S_REFRESH] = '1000'
	"""
	"""
	sensor2 = {}
	sensor2[S_NAME] = 'TESTING sensor2'
	sensor2[S_SIGNAL] = 'A'
	sensor2[S_PIN] = '1'
	sensor2[S_DIRECTION] = 'R'
	sensor2[S_REFRESH] = 10000
	sensors.append(sensor2)
	"""
	"""
Esempio n. 2
0
def populate_test2():
    """ Add test data. """
    db.flushdb()
    user = {KEY_USER: '******', KEY_PASSWORD: '******', KEY_EMAIL: '*****@*****.**'}
    insert_user(user)
    user[KEY_EMAIL] = '*****@*****.**'
    user[KEY_USER] = 'panfrosio'
    insert_user(user)
    post = {
        KEY_TITLE : "How to install Node.js",
        KEY_CONTENTS: "Download files and sudo make, sudo make intall",
        KEY_TAGS: ["node.js", "How-to"]
    }
    insert_post(post, 'seven')
    insert_post(post, 'panfrosio')

    post2 = {
        KEY_TITLE : "On eating doughnuts",
        KEY_CONTENTS: "You shouldn't eat those. They have oxygenated fat.",
        KEY_TAGS: ["food", "health"]
    }
    insert_post(post2, 'seven')
    insert_post(post2, 'panfrosio')

    post_tem = {
        KEY_TITLE : "",
        KEY_CONTENTS: "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\
         sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
        KEY_TAGS: ["lorem", "ipsum"]
    }
    for i in range(3):
        post_tem[KEY_TITLE] = "Post Num " + str(i)
        post_tem[KEY_TAGS].append("Tag number " + str(i))
        insert_post(post_tem, 'seven')
        insert_post(post_tem, 'panfrosio')

    debug("Database created with testing data")
Esempio n. 3
0
def _clear_database():
    """ Clears all data."""
    db.flushdb()