#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, os, shutil, time, requests, json


userDir = "/mnt2/users/"
url = "http://10.17.0.85:8091/"
headers = {'Content-type': 'application/json'}


def go():
	print "Test 1 Booking"

	r = requests.post(url+"booking", data=json.dumps({"username" : "default"}), headers=headers)
	response = json.loads(r.text)
	if response['status'] != 'OK':
		print "Test 1 faild "+response['value']
	else:
		print "Test 1 success"
	

	print "Test 2 Confirmation"
	files = [userDir+"default/dummy2_testfile_"+str(num) for num in range (1,2)]
	for f in files:
		print f
		open(f, 'a').close()
	r = requests.post(url+"confirmation", data=json.dumps({"data": {"tool":"dummy2","files":files,"options":{"model":"xyz"}}}), headers=headers)
	response = json.loads(r.text)
	if response['status'] != 'OK':
		print "Test 2 faild "+response['value']
	else:
		print "Test 2 success"

	print "Test 3 Checking"
	for token in response['value']:
		r = requests.post(url+"checking", data=json.dumps({"token": token, "tool": "dummy2"}), headers=headers)
		response = json.loads(r.text)
		while response['status'] != 'DONE':
			time.sleep(1)
			print str(token) +" "+ str(r.text)
			r = requests.post(url+"checking", data=json.dumps({"token": token, "tool": "dummy2"}), headers=headers)
                	response = json.loads(r.text)		
		print str(token) +" "+ str(r.text)

if __name__ == '__main__':
	go()
