Example #1
0
    def test_defaults_for(self, command_type, data_type, expected_defaults):
        config = Configuration.create("acct:[email protected]", 2)

        config.raw["defaults"] = [
            ["*", "*", {
                "a": 1,
                "last": "wild"
            }],
            ["create", "*", {
                "b": 2,
                "last": "command"
            }],
            ["*", "user", {
                "c": 3,
                "last": "data"
            }],
            ["create", "user", {
                "d": 4,
                "last": "both"
            }],
        ]

        defaults = config.defaults_for(command_type, data_type)

        assert defaults == expected_defaults
Example #2
0
    def test_accessors(self):
        config = Configuration.create(effective_user="******",
                                      total_instructions=100)

        assert config.view is ViewType.NONE
        assert config.effective_user == "acct:[email protected]"
        assert config.total_instructions == 100
Example #3
0
    def test_it_raises_InvalidDeclarationError_with_non_lms_authority(self):
        config = Configuration.create(
            effective_user="******", total_instructions=2
        )

        with pytest.raises(InvalidDeclarationError):
            BulkExecutor(sentinel.db).configure(config)
Example #4
0
 def test_configure_raises_if_the_effective_user_does_not_exist(self, db_session):
     with pytest.raises(InvalidDeclarationError):
         BulkExecutor(db_session).configure(
             Configuration.create(
                 effective_user="******", total_instructions=2
             )
         )
Example #5
0
    def body(self):
        """
        Get the body of this command.

        :return: A Configuration object
        """
        return Configuration(self.raw[1])
Example #6
0
    def test_configure_looks_up_the_effective_user(self, db_session, user):
        executor = BulkExecutor(db_session)

        assert executor.effective_user_id is None

        executor.configure(
            Configuration.create(effective_user=user.userid, total_instructions=2)
        )

        assert executor.effective_user_id == user.id
Example #7
0
    def configure(cls, effective_user, total_instructions, view=ViewType.NONE):
        """
        Create a configuration command.

        :param effective_user: The user to execute actions as
        :param total_instructions: The total number of instructions
        :rtype: ConfigCommand
        """
        return ConfigCommand.create(
            Configuration.create(effective_user, total_instructions, view=view),
        )
Example #8
0
    def test_create(self):
        config = Configuration.create(effective_user="******",
                                      total_instructions="100")

        assert isinstance(config, Configuration)

        assert config.raw == {
            "view":
            None,
            "user": {
                "effective": "acct:[email protected]"
            },
            "instructions": {
                "total": 100
            },
            "defaults": [
                ["create", "*", {
                    "on_duplicate": "continue"
                }],
                ["upsert", "*", {
                    "merge_query": True
                }],
            ],
        }
Example #9
0
    def test_from_raw(self, configuration_body):
        config = Configuration(configuration_body)

        assert isinstance(config, Configuration)
        assert config.raw == configuration_body
Example #10
0
 def test_we_apply_the_schema(self):
     with pytest.raises(SchemaValidationError):
         Configuration.create("wrong_user_format", 100)
Example #11
0
    def test_create(self, configuration_body):
        command = ConfigCommand.create(Configuration(configuration_body))

        self._check_command(command, configuration_body)