Esempio n. 1
0
    def test_len(self, mock_abstract_exercise):
        length = 3
        mock_abstract_exercise.workloads.all().count.return_value = length

        ret_val = AbstractExercise.__len__(mock_abstract_exercise)

        assert ret_val == length
Esempio n. 2
0
    def test_getitem_fail(self, mock_abstract_exercise):
        target_ret_val = None
        arg = 1
        mock_abstract_exercise.get.return_value = target_ret_val

        with pytest.raises(KeyError):
            _ = AbstractExercise.__getitem__(mock_abstract_exercise, arg)
Esempio n. 3
0
    def test_getitem(self, mock_abstract_exercise):
        target_ret_val = 3
        arg = 1
        mock_abstract_exercise.get.return_value = target_ret_val

        ret_val = AbstractExercise.__getitem__(mock_abstract_exercise, arg)

        assert ret_val == target_ret_val
Esempio n. 4
0
    def test_append(self, mock_abstract_exercise, movement_factory, units,
                    order, num_workloads, set_factory):
        mock_abstract_exercise.__len__.return_value = num_workloads
        movement = movement_factory.build()
        sets = set_factory.json(reps=12)

        AbstractExercise.append(mock_abstract_exercise,
                                movement,
                                units,
                                order=order,
                                sets=sets)

        called_order = order or num_workloads
        mock_abstract_exercise.workloads.create.assert_called_once_with(
            movement=movement, units=units, order=called_order, sets=sets)
        if order is None or order == 0:
            mock_abstract_exercise.__len__.assert_called_once()
        else:
            mock_abstract_exercise.__len__.assert_not_called()
Esempio n. 5
0
    def test_get(self, mock_abstract_exercise):
        call_arg = 3
        return_value = 1
        mock_abstract_exercise.workloads.get.return_value = return_value

        ret_val = AbstractExercise.get(mock_abstract_exercise, call_arg)

        assert ret_val == return_value
        mock_abstract_exercise.workloads.get.assert_called_once_with(
            order=call_arg)
Esempio n. 6
0
    def test_get_default(self, mock_abstract_exercise, side_effect, default):
        call_arg = 3
        mock_abstract_exercise.workloads.get.side_effect = side_effect

        ret_value = AbstractExercise.get(mock_abstract_exercise,
                                         call_arg,
                                         default=default)

        assert ret_value == default
        mock_abstract_exercise.workloads.get.assert_called_once_with(
            order=call_arg)
Esempio n. 7
0
    def test_repr(self, workload_factory, mock_abstract_exercise):
        test_name = 'test'
        workloads = workload_factory.build_batch(3)
        mock_abstract_exercise.workloads.all.return_value = workloads
        mock_abstract_exercise.__str__.return_value = test_name

        ret_val = AbstractExercise.__repr__(mock_abstract_exercise)

        assert test_name in ret_val
        for workload in workloads:
            assert str(workload) in ret_val
Esempio n. 8
0
    def test_remove(self, mock_abstract_exercise):
        idx = 1
        AbstractExercise.remove(mock_abstract_exercise, idx)

        mock_abstract_exercise.__delitem__.assert_called_once_with(idx)
Esempio n. 9
0
    def test_extend(self, mock_abstract_exercise, workload_factory):
        workloads = workload_factory.json_batch(3)
        AbstractExercise.extend(mock_abstract_exercise, workloads)

        calls = [mock.call(**workload) for workload in workloads]
        mock_abstract_exercise.append.assert_has_calls(calls)