예제 #1
0
 def test_validate_comment_null(self):
     task = TaskFactory.create()
     self.db.session.commit()
     valid_data = TimeEntryFactory.stub(task=None, comment=None).__dict__
     valid_data['task_id'] = task.id
     valid_data['duration'] = valid_data['duration'].total_seconds()
     assert valid_data['comment'] is None
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(valid_data)
     assert not errors
예제 #2
0
 def test_validate_comment_null(self):
     task = TaskFactory.create()
     self.db.session.commit()
     valid_data = TimeEntryFactory.stub(task=None, comment=None).__dict__
     valid_data['task_id'] = task.id
     valid_data['duration'] = valid_data['duration'].total_seconds()
     assert valid_data['comment'] is None
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(valid_data)
     assert not errors
예제 #3
0
 def test_update(self):
     time_entry = TimeEntryFactory.create()
     self.db.session.commit()
     data = TimeEntryFactory.stub(task=None).__dict__
     data['id'] = time_entry.id
     data['task_id'] = time_entry.task.id
     data['duration'] = data['duration'].total_seconds()
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.id == time_entry.id
     assert instance.duration.total_seconds() == data['duration']
     assert instance.task_id == time_entry.task.id
예제 #4
0
 def test_update(self):
     time_entry = TimeEntryFactory.create()
     self.db.session.commit()
     data = TimeEntryFactory.stub(task=None).__dict__
     data['id'] = time_entry.id
     data['task_id'] = time_entry.task.id
     data['duration'] = data['duration'].total_seconds()
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(data)
     assert not errors
     assert instance.id == time_entry.id
     assert instance.duration.total_seconds() == data['duration']
     assert instance.task_id == time_entry.task.id
예제 #5
0
 def test_validate_duration(self):
     task = TaskFactory.create()
     self.db.session.commit()
     data = TimeEntryFactory.stub(task=None).__dict__
     data['task_id'] = task.id
     # Min
     invalid_data = data.copy()
     invalid_data['duration'] = 30
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
     # Max
     invalid_data = data.copy()
     invalid_data['duration'] = 101 * 3600
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
     # Seconds
     invalid_data = data.copy()
     invalid_data['duration'] = 11111
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
예제 #6
0
 def test_validate_duration(self):
     task = TaskFactory.create()
     self.db.session.commit()
     data = TimeEntryFactory.stub(task=None).__dict__
     data['task_id'] = task.id
     # Min
     invalid_data = data.copy()
     invalid_data['duration'] = 30
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
     # Max
     invalid_data = data.copy()
     invalid_data['duration'] = 101 * 3600
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
     # Seconds
     invalid_data = data.copy()
     invalid_data['duration'] = 11111
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(invalid_data)
     assert 'duration' in errors
예제 #7
0
 def test_validate_task_id(self):
     data = TimeEntryFactory.stub(task=None).__dict__
     data['task_id'] = 0
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(data)
     assert 'task_id' in errors
예제 #8
0
 def test_validate_task_id(self):
     data = TimeEntryFactory.stub(task=None).__dict__
     data['task_id'] = 0
     serializer = TimeEntrySerializer(exclude=['added_at'])
     instance, errors = serializer.load(data)
     assert 'task_id' in errors