# -*- coding: utf-8 -*-
import requests

from lettuce import step, world
from tornado.escape import json_encode, json_decode

class Client():
    def __init__(self, host="localhost:3000"):
        self.host = "http://%s/" % host

    def get(self, path, data):
        response = requests.get(self.host + path)
        return json_decode(response["data"])

    def post(self, path, data):
        return requests.get(self.host + path, data=json_encode(data))

    def put(self, path, data):
        return requests.put(self.host + path, data=json_encode(data))

client = Client()


@step(u'Send a request to check existence of Note with id equal to 123')
def send_a_request_to_check_existence_of_note_with_id_equal_to_123(step):
    data = {
        "id":123,
        "dataType":"Note",
    }
    world.response = client.post("exists/", data)

@step(u'Check that {exists: false} is returned')
def check_that_exists_false_is_returned(step):
    assert "exists" in world.response
    assert not world.response["exists"]

@step(u'Send a request to create a note')
def send_a_request_to_create_a_note(step):
    data = {
        "id":123,
        "dataType":"Note",
        "title":"Test note 01",
        "content":"test content 01"
    }
    world.newNote = client.post("create/", data)

@step(u'Send a request to check existence of Note with id equal to note ID')
def send_a_request_to_check_existence_of_note_with_id_equal_to_note_id(step):
    data = {
        "id": world.newNote["_id"],
        "dataType":"Note",
    }
    world.response = client.post("exists/", data)

@step(u'Check that {exists: true} is returned')
def check_that_exists_true_is_returned(step):
    assert "exists" in world.response
    assert world.response["exists"]




@@ -384,36 +384,40 @@
 ata):%0A        re
-turn
+sponse =
  requests.get(se
@@ -455,16 +455,61 @@
 e(data))
+%0A        return json_decode(response%5B%22data%22%5D)
 %0A%0A    de
@@ -543,20 +543,24 @@
       re
-turn
+sponse =
  request
@@ -606,16 +606,61 @@
 e(data))
+%0A        return json_decode(response%5B%22data%22%5D)
 %0A%0Aclient

debug test client methods