Exemplo n.º 1
0
    def test_init_inconsistent(self):
        """Test the __init__ of the Parameters class where _check_consistency raises an exception."""
        self.kwargs["contract_address"] = "some_contract_address"
        error_message = "If the contract address is set, then good ids and currency id must be provided and consistent."

        with pytest.raises(ValueError, match=error_message):
            assert Parameters(**self.kwargs, )
Exemplo n.º 2
0
 def setup(cls):
     """Setup the test class."""
     super().setup()
     cls.kwargs = {
         "ledger_id": "some_ledger_id",
         "contract_address": None,
         "good_ids": [],
         "currency_ids": [],
         "min_nb_agents": 2,
         "money_endowment": 200,
         "nb_goods": 9,
         "nb_currencies": 1,
         "tx_fee": 1,
         "base_good_endowment": 2,
         "lower_bound_factor": 1,
         "upper_bound_factor": 1,
         "registration_start_time": "01 01 2020  00:01",
         "registration_timeout": 60,
         "item_setup_timeout": 60,
         "competition_timeout": 300,
         "inactivity_timeout": 30,
         "whitelist": [],
         "location": {
             "longitude": 0.1270,
             "latitude": 51.5194
         },
         "service_data": {
             "key": "tac",
             "value": "v1"
         },
         "name": "parameters",
         "skill_context": cls._skill.skill_context,
     }
     cls.parameters = Parameters(**cls.kwargs)
Exemplo n.º 3
0
    def test_init_now_after_start(self):
        """Test the init of Parameters where now is after the registration_start_time."""
        mocked_start_time = self._time("01 01 2020 00:01")
        mocked_now_time = self._time("01 01 2020 00:02")

        datetime_mock = Mock(wraps=datetime.datetime)
        datetime_mock.now.return_value = mocked_now_time

        with patch("datetime.datetime", new=datetime_mock):
            with patch.object(self.parameters.context.logger,
                              "log") as mocked_logger:
                Parameters(**self.kwargs)
        mocked_logger.assert_any_call(
            logging.WARNING,
            f"TAC registration start time {mocked_start_time} is in the past! Deregistering skill.",
        )
        assert self.skill.skill_context.is_active is False
Exemplo n.º 4
0
    def test_init_now_before_start(self):
        """Test the init of Parameters where now is before the registration_start_time."""
        mocked_start_time_str = "01 01 2020  00:03"

        mocked_start_time = self._time(mocked_start_time_str)
        mocked_now_time = self._time("01 01 2020  00:02")

        datetime_mock = Mock(wraps=datetime.datetime)
        datetime_mock.now.return_value = mocked_now_time

        self.kwargs["registration_start_time"] = mocked_start_time_str

        with patch("datetime.datetime", new=datetime_mock):
            with patch.object(self.parameters.context.logger,
                              "log") as mocked_logger:
                par = Parameters(**self.kwargs)
        mocked_logger.assert_any_call(
            logging.INFO,
            f"TAC registation start time: {mocked_start_time}, and registration end time: {par.registration_end_time}, and start time: "
            f"{par.start_time}, "
            f"and end time: {par.end_time}",
        )