def test_config_property_with_new_config_property_model(self) -> None:
     config_model = config_models.ConfigPropertyModel(
         id='config_model', value='new_value')
     config_model.commit(feconf.SYSTEM_COMMITTER_ID, [])
     retrieved_model = config_domain.ConfigProperty(
         'config_model',
         config_domain.BOOL_SCHEMA,
         'description',
         False
     )
     self.assertEqual(retrieved_model.value, 'new_value')
     self.assertEqual(retrieved_model.description, 'description')
Example #2
0
    def test_commit(self) -> None:
        config_model1 = config_models.ConfigPropertyModel(id='config_model1',
                                                          value='c')
        config_model1.commit(feconf.SYSTEM_COMMITTER_ID, [])
        retrieved_model1 = config_models.ConfigPropertyModel.get_version(
            'config_model1', 1)
        # Ruling out the possibility of None for mypy type checking.
        assert retrieved_model1 is not None

        self.assertEqual(retrieved_model1.value, 'c')
        retrieved_model1.value = 'd'
        retrieved_model1.commit(feconf.SYSTEM_COMMITTER_ID, [])
        retrieved_model2 = config_models.ConfigPropertyModel.get_version(
            'config_model1', 2)
        # Ruling out the possibility of None for mypy type checking.
        assert retrieved_model2 is not None

        self.assertEqual(retrieved_model2.value, 'd')
Example #3
0
    def set_value(self, committer_id: str, raw_value: str) -> None:
        """Sets the value of the property. In general, this should not be
        called directly -- use config_services.set_property() instead.
        """
        value = self.normalize(raw_value)

        # Set value in datastore.
        model_instance = config_models.ConfigPropertyModel.get(self.name,
                                                               strict=False)
        if model_instance is None:
            model_instance = config_models.ConfigPropertyModel(id=self.name)
        model_instance.value = value
        model_instance.commit(committer_id, [{
            'cmd': CMD_CHANGE_PROPERTY_VALUE,
            'new_value': value
        }])

        # Set value in memcache.
        caching_services.set_multi(caching_services.CACHE_NAMESPACE_CONFIG,
                                   None,
                                   {model_instance.id: model_instance.value})
Example #4
0
 def test_create_model(self):
     # type: () -> None
     config_model = config_models.ConfigPropertyModel(
         value='b')
     self.assertEqual(config_model.value, 'b')