Ejemplo n.º 1
0
 def test_elapsed_time_correct(self):
     now = datetime.utcnow()
     tenSecondsAgo = now - timedelta(seconds=10)
     # Timer must be running or elapsed time will be zero
     timer = Timer(startTime = tenSecondsAgo, running=True)
     timer.set_seconds_today(20)
     elapsed = timer.current_elapsed()
     total = timer.total_elapsed()
     assert(elapsed == 10)
     assert(total == 30)
Ejemplo n.º 2
0
 def delete_timer(self, timer_id):
     timer = Timer.objects(id = timer_id).first()
     if (timer):
         # Todo can this still throw exception
         timer.delete()
         return True
     else:
         return False
Ejemplo n.º 3
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
Ejemplo n.º 4
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")
Ejemplo n.º 5
0
 def test_to_api_dict_correct(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"))
     d = timer.to_api_dict()
     json = dumps(d)
     assert('"notes": null' in json)
     assert('"id": "56259a278c57cf02f9692b31"' in json)
     assert('"entries": []' in json)
     #assert('"seconds": 20' in json)
     timer.notes = "Testing the JSON!"
     timer.set_seconds_today(99)
     d = timer.to_api_dict()
     json = dumps(d)
     assert('"notes": "Testing the JSON!"' in json)
     assert('"seconds": 99' in json)
Ejemplo n.º 6
0
 def test_can_start_and_stop(self):
     notes = "Testing start and stop"
     t = Timer(notes=notes)
     t.start()
     t.stop()
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def timers_for_user(self, user_id):
     return [t for t in Timer.objects(userId = user_id).order_by("-lastRestart").all()]
Ejemplo n.º 9
0
 def timer_by_id(self, id):
     return Timer.objects(id = id).first()