コード例 #1
0
ファイル: command_builder_test.py プロジェクト: banek/h
    def test_configure(self):
        command = CommandBuilder.configure("acct:[email protected]", 2)

        assert isinstance(command, ConfigCommand)
        assert isinstance(command.body, Configuration)
        assert command.body.effective_user == "acct:[email protected]"
        assert command.body.total_instructions == 2
コード例 #2
0
ファイル: entry_point.py プロジェクト: banek/h
    def _commands_from_ndjson(lines):
        """Turn multiple lines of JSON into Command objects.

        :param lines: An iterable of JSON strings
        :return: A generator of `Command` objects
        """
        for line_number, line in enumerate(lines):
            if not line:
                continue

            try:
                data = json.loads(line)
            except JSONDecodeError as e:
                raise InvalidJSONError(
                    f"Invalid JSON on line {line_number}: {e.args[0]}")

            # Try catch JSON errors here
            yield CommandBuilder.from_data(data)
コード例 #3
0
ファイル: command_processor_test.py プロジェクト: banek/h
    def test_all_items_are_flushed_to_executor(self, command_processor,
                                               executor, user_command,
                                               group_command):
        config = CommandBuilder.configure(
            effective_user="******", total_instructions=5)

        command_processor.process(
            [config, user_command, user_command, group_command, group_command])

        executor.execute_batch.assert_has_calls([
            call(
                batch=[user_command, user_command],
                command_type=CommandType.UPSERT,
                data_type=DataType.USER,
                default_config=Any.dict(),
            ),
            call(
                batch=[group_command, group_command],
                command_type=CommandType.UPSERT,
                data_type=DataType.GROUP,
                default_config=Any.dict(),
            ),
        ])
コード例 #4
0
ファイル: conftest.py プロジェクト: banek/h
def config_command():
    return CommandBuilder.configure(
        effective_user="******", total_instructions=2
    )
コード例 #5
0
 def test_we_get_schema_errors_with_malformed_commands(self, data):
     with pytest.raises(SchemaValidationError):
         CommandBuilder.from_data(data)
コード例 #6
0
    def test_deserialise_configure_can_fail(self, configuration_body):
        configuration_body["random"] = "new_value"

        with pytest.raises(SchemaValidationError):
            CommandBuilder.from_data([CONFIGURE, configuration_body])
コード例 #7
0
    def test_deserialise_configure_ok(self, configuration_body):
        command = CommandBuilder.from_data([CONFIGURE, configuration_body])

        assert isinstance(command.body, Configuration)
コード例 #8
0
    def test_deserialise_group_membership_can_fail(
            self, create_group_membership_body):
        del create_group_membership_body["data"]["relationships"]["group"]

        with pytest.raises(SchemaValidationError):
            CommandBuilder.from_data([CREATE, create_group_membership_body])
コード例 #9
0
    def test_deserialise_group_membership_ok(self,
                                             create_group_membership_body):
        command = CommandBuilder.from_data(
            [CREATE, create_group_membership_body])

        assert isinstance(command.body, CreateGroupMembership)
コード例 #10
0
    def test_deserialise_group_can_fail(self, upsert_group_body):
        del upsert_group_body["data"]["attributes"]["name"]

        with pytest.raises(SchemaValidationError):
            CommandBuilder.from_data([UPSERT, upsert_group_body])
コード例 #11
0
    def test_deserialise_group_ok(self, upsert_group_body):
        command = CommandBuilder.from_data([UPSERT, upsert_group_body])

        assert isinstance(command.body, UpsertGroup)
コード例 #12
0
ファイル: command_builder_test.py プロジェクト: banek/h
    def test_deserialise_user_can_fail(self, upsert_user_body):
        del upsert_user_body["data"]["id"]

        with pytest.raises(SchemaValidationError):
            CommandBuilder.from_data([UPSERT, upsert_user_body])