Beispiel #1
0
 def test_fd_update_rule(self):
     intent = TestAccount.get_intent()
     intentid = intent["ID"]
     candidates = [
         c.attribute_values
         for c in Item.query("rule", Item.parent.__eq__(intentid))
     ]
     rule = candidates[0]
     ruleid = rule["ID"]
     print ">>", ruleid
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "updateRule",
         "path": "Mutation/updateRule",
         "arguments": {
             "ruleid": ruleid,
             "input": {
                 "description": "updated"
             }
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["description"], "updated")
Beispiel #2
0
 def test_ed_update_variable(self):
     entity = TestAccount.get_entity()
     entityid = entity["ID"]
     candidates = [
         c.attribute_values
         for c in Item.query("variable", Item.parent.__eq__(entityid))
     ]
     variable = candidates[0]
     variableid = variable["ID"]
     print ">>", variableid
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "updateVariable",
         "path": "Mutation/updateVariable",
         "arguments": {
             "variableid": variableid,
             "input": {
                 "description": "updated"
             }
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["description"], "updated")
Beispiel #3
0
 def test_ac_list_myaccount(self):
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "listMyAccounts",
         "path": "Query/listMyAccounts",
         "arguments": {}
     }
     x = App.handler(event, {})
     for user in x:
         print user
Beispiel #4
0
    def test_aa_clean(self):
        event = {
            "identity": {
                "claims": TestAccount.get_claim()
            },
            "field": "listMyAccounts",
            "path": "Query/listMyAccounts",
            "arguments": {}
        }
        accounts = App.handler(event, {})

        if type(accounts) == type(["a", "list"]):
            print "Found", len(accounts), "accounts"
            print accounts
            for accountdoc in accounts:
                a = Item.get('account', accountdoc["ID"])
                a.delete()

            x = App.handler(event, {})
            self.assertTrue(len(x) == 0)
        else:
            self.assertTrue(True, "no accounts")
Beispiel #5
0
 def test_bc_get_bot(self):
     accountid = TestAccount.get_accountid()
     bots = TestAccount.get_bots()
     bot = bots[0]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "getBot",
         "path": "Query/getBot",
         "arguments": {
             "botid": bot["ID"]
         }
     }
     r = App.handler(event, {})
     self.assertEqual(r["name"], bot["name"])
Beispiel #6
0
 def test_ad_invite(self):
     accountid = TestAccount.get_accountid()
     print "accountid = ,", accountid
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "inviteUser",
         "path": "Mutation/inviteUser",
         "arguments": {
             "accountid": accountid,
             "email": "*****@*****.**",
         }
     }
     x = App.handler(event, {})
     print x
Beispiel #7
0
    def test_bb_list_bots(self):
        accountid = TestAccount.get_accountid()
        event = {
            "identity": {
                "claims": TestAccount.get_claim()
            },
            "field": "listBots",
            "path": "Account/listBots",
            "arguments": {},
            "source": {
                "ID": accountid
            }
        }

        r = App.handler(event, {})
        print r
        print pprint.pformat(r)
        self.assertTrue(len(r) == 1)
Beispiel #8
0
    def test_eb_list_variables(self):
        entity = TestAccount.get_entity()
        entityid = entity["ID"]
        event = {
            "identity": {
                "claims": TestAccount.get_claim()
            },
            "field": "listVariables",
            "path": "Entity/listVariables",
            "arguments": {},
            "source": {
                "ID": entityid
            }
        }

        r = App.handler(event, {})
        print r
        print pprint.pformat(r)
        self.assertTrue(len(r) == 1)
Beispiel #9
0
 def test_ab_create_account(self):
     print "+-+" * 30
     print "CREATION"
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "createAccount",
         "path": "Mutation/createAccount",
         "arguments": {
             "input": {
                 "name": "testaccount"
             }
         }
     }
     self.assertTrue(True)
     w = App.handler(event, {})
     print "Creation "
     print pprint.pformat(w)
Beispiel #10
0
    def test_fb_list_rules(self):
        intent = TestAccount.get_intent()
        intentid = intent["ID"]
        event = {
            "identity": {
                "claims": TestAccount.get_claim()
            },
            "field": "listRules",
            "path": "Intent/listRules",
            "arguments": {},
            "source": {
                "ID": intentid
            }
        }

        r = App.handler(event, {})
        print r
        print pprint.pformat(r)
        self.assertTrue(len(r) == 1)
Beispiel #11
0
 def test_fa_create_rule(self):
     intent = TestAccount.get_intent()
     intentid = intent["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "createRule",
         "path": "Mutation/createRule",
         "arguments": {
             "intentid": intentid,
             "input": {
                 "name": "mytestrule",
                 "description": "test"
             }
         }
     }
     self.assertTrue(True)
     w = App.handler(event, {})
     print pprint.pformat(w)
Beispiel #12
0
 def test_ba_create_bot(self):
     accountid = TestAccount.get_accountid()
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "createBot",
         "path": "Mutation/createBot",
         "arguments": {
             "accountid": accountid,
             "input": {
                 "name": "mytestbot",
                 "description": "test"
             }
         }
     }
     self.assertTrue(True)
     w = App.handler(event, {})
     print "Creation "
     print pprint.pformat(w)
Beispiel #13
0
 def test_ea_create_variable(self):
     entity = TestAccount.get_entity()
     entityid = entity["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "createVariable",
         "path": "Mutation/createVariable",
         "arguments": {
             "entityid": entityid,
             "input": {
                 "name": "mytestvariable",
                 "description": "test"
             }
         }
     }
     self.assertTrue(True)
     w = App.handler(event, {})
     print pprint.pformat(w)
Beispiel #14
0
 def test_dc_get_intent(self):
     accountid = TestAccount.get_accountid()
     bots = TestAccount.get_bots()
     bot = bots[0]
     botid = bot["ID"]
     intents = TestAccount.get_intents(botid)
     intent = intents[0]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "getIntent",
         "path": "Query/getIntent",
         "arguments": {
             "intentid": intent["ID"]
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["name"], intent["name"])
Beispiel #15
0
 def test_cc_get_entity(self):
     accountid = TestAccount.get_accountid()
     bots = TestAccount.get_bots()
     bot = bots[0]
     botid = bot["ID"]
     entities = TestAccount.get_entities(botid)
     entity = entities[0]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "getEntity",
         "path": "Query/getEntity",
         "arguments": {
             "entityid": entity["ID"]
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["name"], entity["name"])
Beispiel #16
0
 def test_be_list_bots_with_search(self):
     accountid = TestAccount.get_accountid()
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "listBots",
         "path": "Account/listBots",
         "arguments": {
             "options": {
                 "search": "updated"
             }
         },
         "source": {
             "ID": accountid
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(len(r), 1)
Beispiel #17
0
 def test_bd_update_bot(self):
     accountid = TestAccount.get_accountid()
     bots = TestAccount.get_bots()
     bot = bots[0]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "updateBot",
         "path": "Mutation/updateBot",
         "arguments": {
             "botid": bot["ID"],
             "input": {
                 "description": "updated"
             }
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["description"], "updated")
Beispiel #18
0
    def test_cb_list_entities(self):
        accountid = TestAccount.get_accountid()
        bots = TestAccount.get_bots()
        bot = bots[0]
        botid = bot["ID"]
        event = {
            "identity": {
                "claims": TestAccount.get_claim()
            },
            "field": "listEntities",
            "path": "Bot/listEntities",
            "arguments": {},
            "source": {
                "ID": botid
            }
        }

        r = App.handler(event, {})
        print r
        print pprint.pformat(r)
        self.assertTrue(len(r) == 1)
Beispiel #19
0
 def test_ee_list_variables_with_search(self):
     entity = TestAccount.get_entity()
     entityid = entity["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "listVariables",
         "path": "Entity/listVariables",
         "arguments": {
             "options": {
                 "search": "updated"
             }
         },
         "source": {
             "ID": entityid
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(len(r), 1)
Beispiel #20
0
 def test_fe_list_rules_with_search(self):
     intent = TestAccount.get_intent()
     intentid = intent["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "listRules",
         "path": "Entity/listRules",
         "arguments": {
             "options": {
                 "search": "updated"
             }
         },
         "source": {
             "ID": intentid
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(len(r), 1)
Beispiel #21
0
 def test_da_create_intent(self):
     bots = TestAccount.get_bots()
     bot = bots[0]
     print "??", bot
     botid = bot["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "createIntent",
         "path": "Mutation/createIntent",
         "arguments": {
             "botid": botid,
             "input": {
                 "name": "mytestintent",
                 "description": "test"
             }
         }
     }
     self.assertTrue(True)
     w = App.handler(event, {})
     print pprint.pformat(w)
Beispiel #22
0
 def test_ec_get_variable(self):
     entity = TestAccount.get_entity()
     entityid = entity["ID"]
     candidates = [
         c.attribute_values
         for c in Item.query("variable", Item.parent.__eq__(entityid))
     ]
     variable = candidates[0]
     variableid = variable["ID"]
     print ">>", variableid
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "getVariable",
         "path": "Query/getVariable",
         "arguments": {
             "variableid": variableid
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["name"], variable["name"])
Beispiel #23
0
 def test_fc_get_rule(self):
     intent = TestAccount.get_intent()
     intentid = intent["ID"]
     candidates = [
         c.attribute_values
         for c in Item.query("rule", Item.parent.__eq__(intentid))
     ]
     rule = candidates[0]
     ruleid = rule["ID"]
     print ">>", ruleid
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "getRule",
         "path": "Query/getRule",
         "arguments": {
             "ruleid": ruleid
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["name"], rule["name"])
Beispiel #24
0
 def test_cd_update_entity(self):
     accountid = TestAccount.get_accountid()
     bots = TestAccount.get_bots()
     bot = bots[0]
     botid = bots[0]["ID"]
     entities = TestAccount.get_entities(botid)
     entity = entities[0]
     entityid = entity["ID"]
     event = {
         "identity": {
             "claims": TestAccount.get_claim()
         },
         "field": "updateEntity",
         "path": "Mutation/updateEntity",
         "arguments": {
             "entityid": entityid,
             "input": {
                 "description": "updated"
             }
         }
     }
     r = App.handler(event, {})
     print r
     self.assertEqual(r["description"], "updated")
Beispiel #25
0
if __name__=="__main__" :

    event = {
        "field": "askBot",
        "path": "Query/askBot",
        "arguments": {
            "identity": "service",
            "botid": "uri:bot:demo:salesbot",
            #"question": "show average revenue of sales with country equals Australia per country"
            #"question": "show number of sales"
            "question": "tell me average revenue of sales by country"
        }

    }
    b = App.route(event)
    print pprint.pformat(b)

    exit()
    print getBotStatus(botid="uri:bot:demo:salesbot", identity="xxx")

    event = {
        "field": "createOrUpdateLexBot",
        "path": "Mutation/createOrUpdateLexBot",
        "arguments": {
            "identity": "service",
            "botid": "uri:bot:demo:salesbot"
        }

    }
    b = App.route(event)
Beispiel #26
0
def handler(event, context):
    x = App.handler(event, context)
    print x
    return x
Beispiel #27
0
            "Sorry, this is not clear for and old bot",
            "Can you try to reformulate ?",
            "Hmm, i'm just a bot",
            "Well, this is clear, i'm not really awake right now"
        ])



if __name__=="__main__" :


    print App.route(
        {
            "field" : "askBot",
            "arguments": {
                "botid":"uri:bot:demo:FinancialCoach",
                "question" : "how many people are living in paris"
            }
         }
    )

    r= askBot(identity="", botid="uri:bot:demo:FinancialCoach", question="how many people are living in paris")
    print pprint.pformat(r)

    exit()
    #print     Bot.put_alias("FinancialCoach")
    print     Bot.put_bot_version("FinancialCoach")

    exit()

    print getBotStatus(identity="", botid="uri:bot:demo:FinancialCoach")
    def test_entity_api(self):
        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "createBot",
            "path": "Mutation/createBot",
            "arguments": {
                "accountid": "testaccount",
                "input": {
                    "name": "mytestbot",
                    "description": "test"
                }
            }
        }
        self.assertTrue(True)
        b = App.handler(event, {})
        print b

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "createEntity",
            "path": "Mutation/createEntity",
            "arguments": {
                "botid": b["ID"],
                "input": {
                    "name": "mytestbot",
                    "description": "test"
                }
            }
        }

        e = App.handler(event, {})
        print e

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "createEntity",
            "path": "Mutation/createEntity",
            "arguments": {
                "botid": b["ID"],
                "input": {
                    "name": "mytestbot",
                    "description": "test"
                }
            }
        }

        w = App.handler(event, {})
        print w

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "getEntity",
            "path": "Query/getEntity",
            "arguments": {
                "entityid": w["ID"],
            }
        }

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "updateEntity",
            "path": "Mutation/updateEntity",
            "arguments": {
                "entityid": w["ID"],
                "input": {
                    "tags": "x,y,z"
                }
            }
        }
        u = App.handler(event, {})
        print "U = ", u

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "listEntities",
            "path": "Query/listentities",
            "arguments": {
                "botid": b["ID"]
            }
        }
        l = App.handler(event, {})
        print "entities = ", l

        event = {
            "identity": {
                "claims": TestEndToEnd.get_claim()
            },
            "field": "deleteEntity",
            "path": "Mutation/deleteEntity",
            "arguments": {
                "entityid": w["ID"]
            }
        }
        d = App.handler(event, {})
        print "D = ", d
Beispiel #29
0
               "/arguments/identity": "identity"
           })
def invite(accountid, email, identity):
    accountid = accountid.split(":")[2]
    user = Item(parent=accountid,
                name=email,
                objecttype="user",
                creator=identity,
                createdat=ID.now(),
                ID="uri:user:%(accountid)s:%(email)s" % vars(),
                search=email)
    user.save()


if __name__ == "__main__":
    response = App.route({
        "field": "listBots",
        "path": "Account/listBots",
        "arguments": {
            "identity": "*****@*****.**",
            "options": {
                "limit": 1,
                "offset": 1
            }
        },
        "source": {
            "ID": "uri:account:20180911183119"
        }
    })
    print pprint.pformat(response)
Beispiel #30
0
               "/arguments/identity": "identity",
               "/arguments/options": "options"
           })
def list_accounts(identity, options):
    accounts = []
    iterator = apply_options(Item.query("user", Item.name.__eq__(identity)),
                             options)
    for user in iterator:
        try:
            print user.attribute_values
            account = Item.get("account", user.parent)
            accounts.append(account.attribute_values)
        except Exception, e:
            pass
    return accounts


if __name__ == "__main__":

    response = App.route({
        "field": "listMyAccounts",
        "path": "Query/listMyAccounts",
        "arguments": {
            "identity": "*****@*****.**",
            "options": {
                "limit": 200
            }
        }
    })
    #response = list_accounts("*****@*****.**",None)
    print pprint.pformat(response)