Пример #1
0
 def test_can_load_from_api_dict(self):
     start_time = dateutil.parser.parse('2008-09-03T20:00:00.000000Z')
     # Timer must be running or elapsed time will be zero
     timer = Timer(startTime = start_time,  running=True, id=ObjectId("56259a278c57cf02f9692b31"))
     timer.set_seconds_today(99)
     d = timer.to_api_dict()
     t2 = Timer.load_from_dict(d)
     assert(timer.notes == t2.notes)
     assert(timer.id == t2.id)
     assert(timer.entries[0].dateRecorded == t2.entries[0].dateRecorded)
     assert(len(timer.entries) == len(t2.entries))
     assert(timer.entries[0].seconds == t2.entries[0].seconds)
     d["notes"] = "Testing"
     t2 = Timer.load_from_dict(d)
     assert(t2.notes == "Testing")
Пример #2
0
 def post(self):
     json = request.json
     timer = Timer.load_from_dict(json)
     timer.save()
     location = api_root + "/timer/" + str(timer.id)
     response = jsonify(timer.to_api_dict())
     response.headers["location"] = location
     response.status_code = 201
     return response
Пример #3
0
 def put(self, timer_id):
     # To do review exceptions, also, does json ID match timer_id?
     # If not return bad request
     timer = Timer.load_from_dict(request.json)
     TimerDao().save_timer(timer)
     return(None, 204)