Esempio n. 1
0
 def test_index_exists(self):
     util.create_test_index(self.endpoint, self.index)
     url = "{0}{1}".format(self.endpoint, self.index)
     response = util.send_data(url)
     self.assertEqual(response.status_code, 200)
     assert "error" not in response.text
     url = "{0}{1}".format(self.endpoint, "_cat/indices?v=")
     response = util.send_data(url)
     assert "bank" in response.text
    def test_delete(self):
        util.sample_data(self.endpoint, self.index)
        url = "{0}{1}{2}".format(self.endpoint, self.index, "/doc/1")
        response = util.send_data(url, "DELETE")
        json_data = response.json()
        self.assertEqual(json_data["result"], "deleted")
        self.assertEqual(json_data["_id"], "1")

        fetch_url = "{0}{1}{2}".format(self.endpoint, self.index, "/doc/1")
        fetch_response = util.send_data(fetch_url, "GET")
        fetch_json_data = fetch_response.json()
        self.assertEqual(fetch_json_data["found"], False)
 def test_read(self):
     util.sample_data(self.endpoint, self.index)
     url = "{0}{1}{2}".format(self.endpoint, self.index, "/doc/1")
     response = util.send_data(url, "GET")
     json_data = response.json()
     self.assertEqual(json_data["found"], True)
     self.assertEqual(json_data["_id"], "1")
Esempio n. 4
0
 def sell(self, id, price=0):
     global TotalCost
     data = {'op' : 1023, 'id' : str(id)}
     res = util.send_data(data)
     if res:
         TotalCost -= int(price)
     logger.info('sell equip %s succeed'%(id))
 def sell(self, id, price=0):
     global TotalCost
     data = {"op": 1023, "id": str(id)}
     res = util.send_data(data)
     if res:
         TotalCost -= int(price)
     logger.info("sell equip %s succeed" % (id))
 def test_cluster_health(self):
     url="{0}{1}".format(self.endpoint,"_cluster/health?pretty")
     response = util.send_data(url)
     json_data = response.json()
     self.assertEqual(json_data["status"], "green")
     self.assertEqual(json_data["timed_out"], False)
     self.assertGreater(json_data["number_of_nodes"], 1)
Esempio n. 7
0
 def do_degrade(self, eid):
     data = {
             'op' : 1005,
             'id' : str(eid),
         }
     res = util.send_data(data)
     logger.info('degrade %s succeed'%(eid))
Esempio n. 8
0
 def get_max_level(self, tpe):
     ret = 1
     data = {'op' : 1019}
     res = util.send_data(data, 'userAppoints')
     for ap in res['userAppoints']:
         if int(tpe) == int(ap['type']):
             ret = max(ret, int(ap['appointLevel']))
     return str(ret)
 def get_max_level(self, tpe):
     ret = 1
     data = {"op": 1019}
     res = util.send_data(data, "userAppoints")
     for ap in res["userAppoints"]:
         if int(tpe) == int(ap["type"]):
             ret = max(ret, int(ap["appointLevel"]))
     return str(ret)
 def test_create(self):
     data = {"name": "Jane Smith"}
     payload = json.dumps(data)
     url = "{0}{1}{2}".format(self.endpoint, self.index, "/doc")
     response = util.send_data(url, "POST", data=payload)
     json_data = response.json()
     self.assertIn(response.status_code, [200, 201])
     self.assertEqual(json_data["result"], "created")
 def test_update(self):
     util.sample_data(self.endpoint, self.index)
     data = {"name": "Jane Smith"}
     payload = json.dumps(data)
     url = "{0}{1}{2}".format(self.endpoint, self.index, "/doc/1")
     response = util.send_data(url, "PUT", data=payload)
     json_data = response.json()
     self.assertEqual(json_data["result"], "updated")
     self.assertEqual(json_data["_id"], "1")
     self.assertGreater(json_data["_version"], 1)
 def test_bulk_api(self):
     file = cfg.es_sample_data_path
     # if file and not os.path.isfile(file):
     #     raise FileNotFoundError('File not found: ' + file)
     url = "{0}{1}{2}".format(self.endpoint, self.index, "/_bulk")
     file = open(file, 'rb')
     data = file.read()
     file.close()
     response = util.send_data(url, "POST", data=data)
     json_data = response.json()
     self.assertEqual(json_data["errors"], False)
 def print_info(self):
     data = {"op": 1323}
     res = util.send_data(data, "integral")
     # print json.dumps(res, sort_keys = False, indent = 4)
     print "Order: %d" % (res.get("order", 0) or 0)
     print "Integral: %s" % (res["integral"])
     print "Award: %d" % (res["award"])
     print "IsGet: %s" % ("True" if res["isGet"] == "1" else "False")
     print "ServerTime: %s" % (util.format_time(res["serverTime"]))
     print "EndTime: %s" % (util.format_time(res["endTime"]))
     print "OrderList:"
     for pp in res["orderList"] or []:
         print "\tOrder:%d\tIntegle:%s\tName:%s" % (pp["order"], pp["integle"], pp["userName"])
 def test_search(self):
     util.bulk_sample_data(self.endpoint, self.index)
     util.bulk_sample_data(self.endpoint, self.index)
     # print(res.json())
     data = {
         "query": {
             "match_all": {}
         },
         "sort": [{
             "balance": {
                 "order": "desc"
             }
         }]
     }
     payload = json.dumps(data)
     url = "{0}{1}{2}".format(self.endpoint, self.index, "/_search")
     response = util.send_data(url, "POST", data=payload)
     json_data = response.json()
     # print(json_data["hits"]['total']['value'])
     self.assertEqual(json_data["timed_out"], False)
     self.assertGreaterEqual(json_data["hits"]['total']['value'], 0)
Esempio n. 15
0
def sync():
    for tweet_id in unsynced_created_tweets:
        send_data(
            master + '/sync/create/',
            db.execute('SELECT * FROM Tweets WHERE id = ?',
                       [tweet_id]).fetchone().to_dict())
    for tweet_id in unsynced_updated_tweets:
        send_data(
            master + '/sync/update/',
            db.execute('SELECT * FROM Tweets WHERE id = ?',
                       [tweet_id]).fetchone().to_dict())
    for tweet_id in unsynced_deleted_tweets:
        send_data(master + '/sync/delete/', {'id': tweet_id})
    del unsynced_created_tweets[:]
    del unsynced_updated_tweets[:]
    del unsynced_deleted_tweets[:]
    db.commit()
    threading.Timer(syncing_period, sync).start()
Esempio n. 16
0
def get_server_index(tablet_index):
    return tablet_index // tablets_per_server


def get_tablet_index(tweet):
    return min(
        int((tweet.get_datetime() - first_datetime).total_seconds() /
            timespan.total_seconds()), number_of_tablets - 1)


def get_server(tweet):
    return tablet_servers[get_server_index(get_tablet_index(tweet))]


for tweet in all_tweets:
    send_data(get_server(tweet) + '/master/create/', tweet.to_dict())


@app.route('/', methods=['GET'])
def index():
    return render_template(
        'index.html',
        first_datetime=first_datetime.strftime(datetime_format),
        last_datetime=last_datetime.strftime(datetime_format),
        now=datetime.datetime.now().strftime(datetime_format),
        new_id=uuid.uuid4().hex)


@app.route('/create/', methods=['POST'])
def create():
    return jsonify(
 def get_money(self):
     data = {"op": 1325}
     res = util.send_data(data)
     logger.info("Got huodong money")
     return res
 def test_endpoint_health(self):
     response=util.send_data(self.endpoint)
     self.assertEqual(response.status_code, 200)
 def test_cluster_running(self):
     response = util.send_data(self.endpoint)
     json_data = response.json()
     self.assertNotEqual(json_data["cluster_uuid"], "_na_")
     self.assertEqual(json_data["cluster_name"], "k8s-logs")
Esempio n. 20
0
 def test_index_create(self):
     url = "{0}{1}".format(self.endpoint, self.index)
     response = util.send_data(url, "PUT")
     self.assertIn(response.status_code, [200, 201])