Example #1
0
def create(event, context):
    data = json.loads(event['body'])
    if 'text' not in data:
        logging.error("Validation Failed")
        raise Exception("Couldn't create the todo item.")

    data = {
        'text': data['text'],
        'checked': False,
        'createdAt': query.time('now'),
        'updatedAt': query.time('now')
    }

    # write the todo to the database
    created = client.query(query.create(TODOS, {'data': data}))

    # create a response
    response = {
        "statusCode": 200,
        "body": json.dumps(make_result(created))
    }

    return response
Example #2
0
def update(event, context):
    data = json.loads(event['body'])
    if 'text' not in data or 'checked' not in data:
        logging.error("Validation Failed")
        raise Exception("Couldn't update the todo item.")

    data = {
        'text': data['text'],
        'checked': data['checked'],
        'updatedAt': query.time('now')
    }

    # update the todo in the database
    ref = Ref(TODOS, event['pathParameters']['id'])
    updated = client.query(query.update(ref, {'data': data}))

    # create a response
    response = {
        "statusCode": 200,
        "body": json.dumps(make_result(updated))
    }

    return response
Example #3
0
 def __init__(self, collection, argument="argument"):
     self.collection = collection
     self.parsers = {
         "cursor_ref": lambda value: q.ref(q.collection(self.collection), value),
         "cursor_time": lambda value: q.time(value),
     }
    def test_time(self):
        time = "1970-01-01T00:00:00.123456789Z"
        self.assertEqual(self._q(query.time(time)), FaunaTime(time))

        # "now" refers to the current time.
        self.assertIsInstance(self._q(query.time("now")), FaunaTime)
    def test_now(self):
        t1 = self._q(query.now())
        self.assertIsInstance(t1, FaunaTime)

        self.assertEqual(self._q(query.equals(query.now(), query.time("now"))),
                         True)
 def test_minute(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.minute(query.time(now.isoformat() + 'Z'))),
         now.minute)
 def test_second(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.second(query.time(now.isoformat() + 'Z'))),
         now.second)
 def test_year(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.year(query.time(now.isoformat() + 'Z'))), now.year)
 def test_day_of_week(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.day_of_week(query.time(now.isoformat() + 'Z'))),
         now.weekday() + 1)
Example #10
0
 def test_day_of_month(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.day_of_month(query.time(now.isoformat() + 'Z'))),
         now.day)
Example #11
0
 def test_day_of_year(self):
     now = datetime.now()
     self.assertEqual(
         self._q(query.day_of_year(query.time(now.isoformat() + 'Z'))),
         now.timetuple().tm_yday)
Example #12
0
 def test_time(self):
     self.assertJson(query.time("1970-01-01T00:00:00+00:00"),
                     '{"time":"1970-01-01T00:00:00+00:00"}')