-
Notifications
You must be signed in to change notification settings - Fork 0
/
fppost.py
85 lines (59 loc) · 2.3 KB
/
fppost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# A. Staubert, 11-2015
#
# This library implements the functions to interface with the Rails Application (Database) via WEB
#
import requests
import json
import fplog
USEURL = 'https://immense-cliffs-8170.herokuapp.com/'
#useurl = 'http://localhost:3000/'
# Function to query of web-site is active
#
def poquerysite(logtype="prod"):
fplog.l("=> in fppost.py/poquerysite",logtype)
fplog.l('Using URL: ' + str(USEURL),logtype)
r = requests.get(USEURL)
fplog.l('Got response from URL: ' + str(r),logtype)
tagstatus = "False"
if r.status_code == 200:
tagstatus = "True"
fplog.l("<= out fppost, return value: tagstatus = " + str(tagstatus),logtype)
return tagstatus
# Function to query if a tag exists
#
def poquerytag(tagsn, logtype="prod"):
fplog.l("=> in fppost.py/poquerytag",logtype)
fplog.l('Using URL: ' + str(USEURL),logtype)
r = requests.get(USEURL + '/flowerquery/' + str(tagsn))
fplog.l('Got response from URL: ' + str(r),logtype)
tagstatus = "not_existing"
if r.status_code == 200:
tagstatus = "existing"
fplog.l("<= out fppost, return value: tagstatus = " + str(tagstatus),logtype)
return tagstatus
# ...run automated tests if library is started as a script
if __name__ == "__main__":
fplog.l("+++ In: fppost.py Test +++ ","test")
poquerysite("test")
tagsn = input('Please enter tagsn: ')
querytag = poquerytag(tagsn, "test")
if querytag == "existing":
fplog.l('Tag matches to following flower: ',"test")
r = requests.get(USEURL + '/flowerquery/' + str(tagsn))
fplog.l(r.text,"test")
flower_hash = json.loads(r.text)
fplog.l('The flower is a: ' + str(flower_hash["flowertype"]),"test")
else:
fplog.l("Sorry, tag does not exist!","test")
fplog.l("But it will try to create one","test")
payload = {'tagsn': tagsn, 'pisn': '4711pisn', 'flowertype': 'new dummy', 'litershould': '0'}
r = requests.post(USEURL + '/flowers.json', json=payload)
if r.status_code == 201:
fplog.l("... success in creating new flower","test")
flower_hash = json.loads(r.text)
fplog.l('The ID of the new flower is: ' + str(flower_hash["id"]),"test")
else:
fplog.l("Sorry, was not able to create a new tag","test")
fplog.l('Response code is: ' + str(r.status_code),"test")
fplog.l('Response text is: ' + str(r.text),"test")
fplog.l("+++ Goodby from: fppost.py Test +++","test")