def test_can_remove_datapoint_with_uuid(run_in_one_goal_store_with_one_point): run = run_in_one_goal_store_with_one_point goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] result = run.invoke(main, ['remove', 'dummy', point.uuid[:5]]) assert result.exit_code == 0 assert 'removed successfully!' in result.output goal = Goal.fromYAML('dummy.yaml') assert len(goal.datapoints) == 0
def test_can_edit_datapoint_comment(run_in_one_goal_store_with_one_point): run = run_in_one_goal_store_with_one_point goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] result = run.invoke(main, ['edit', 'dummy', point.uuid[:5], '-c', 'bar']) assert result.exit_code == 0 assert 'edited successfully!' in result.output goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] assert point.comment == 'bar'
def test_can_edit_datapoint_time(run_in_one_goal_store_with_one_point): run = run_in_one_goal_store_with_one_point goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] result = run.invoke(main, ['edit', 'dummy', point.uuid[:5], '-t', '1 min ago']) assert result.exit_code == 0 assert 'edited successfully!' in result.output goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] assert abs(point.stamp - dt.datetime.now() + dt.timedelta(minutes=1)) < dt.timedelta(seconds=5)
def load_goal(self, name): if not name in self.list_goal_names(): raise KeyError( 'There is no goal named {} in this store'.format(name)) goal = Goal.fromYAML(self.get_path_to_goal(name)) goal.store = self return goal
def test_can_add_datapoint_with_comment(run_in_one_goal_store): run = run_in_one_goal_store result = run.invoke(main, ['add', 'dummy', '10', '-c', 'test']) assert result.exit_code == 0 goal = Goal.fromYAML('dummy.yaml') assert len(goal.datapoints) == 1 assert goal.datapoints[0].comment == 'test' assert "added successfully" in result.output
def dummy_goal(): reference_points = (create_point( stamp=dt.datetime.now() + relativedelta(minutes=-1), value=0, ), create_point( stamp=dt.datetime.now() + relativedelta(days=1), value=1, )) goal = Goal(name='Dummy', pledge=0, reference_points=reference_points) return goal
def test_can_list_datapoints_with_uuid(run_in_one_goal_store_with_one_point): run = run_in_one_goal_store_with_one_point result = run.invoke(main, ['list', 'dummy']) assert result.exit_code == 0 assert '10' in result.output assert 'test' in result.output assert dt.datetime.now().strftime('%Y-%m-%d') in result.output goal = Goal.fromYAML('dummy.yaml') point = goal.datapoints[0] assert point.uuid[:8] in result.output
def test_add_goal_with_parameter(run_in_store): result = run_in_store.invoke( main, ['new', 'dummy', '--slope', '10', '--pledge', '10']) assert result.exit_code == 0 assert os.path.exists('dummy.yaml') goal = Goal.fromYAML('dummy.yaml') assert goal.name == 'dummy' assert goal.pledge == 10 same_goal = create_goal(name='dummy', daily_slope=10, pledge=0) assert goal.reference_points[1].value == same_goal.reference_points[ 1].value
def test_add_goal(run_in_store): result = run_in_store.invoke(main, ['new', 'dummy']) assert result.exit_code == 0 assert os.path.exists('dummy.yaml') goal = Goal.fromYAML('dummy.yaml') assert goal.name == 'dummy' assert goal.pledge == 0 same_goal = create_goal(name='dummy', daily_slope=1, pledge=0) assert goal.reference_points[1].value == same_goal.reference_points[ 1].value assert 'Goal named dummy with daily slope of 1 and a pledge of 0€ created successfully!' in result.output
def test_can_parse_goal_from_yaml(one_goal, tmpfile): one_goal.toYAML(tmpfile) clone = Goal.fromYAML(tmpfile) assert one_goal == clone
def one_goal_clone(one_goal): return Goal(one_goal.name, one_goal.pledge, one_goal.reference_points, one_goal.active, one_goal.datapoints)