Beispiel #1
0
    def test_command_serialisation_ok(self, commands):
        """A sanity check that hits most of the behavior of creation.

        This is a happy path check. We expect this to work."""

        ndjson = BulkAPI.to_string(commands)
        lines = ndjson.strip().split("\n")
        command_data = [json.loads(line) for line in lines]

        assert len(command_data) == 4

        assert command_data == [
            ["configure", Any.dict()],
            ["upsert", {
                "data": Any.dict.containing({"type": "user"})
            }],
            ["upsert", {
                "data": Any.dict.containing({"type": "group"})
            }],
            [
                "create", {
                    "data": Any.dict.containing({"type": "group_membership"})
                }
            ],
        ]
Beispiel #2
0
    def test_round_tripping(self, commands, collecting_observer):
        """Check that sending and decoding results in the same data."""

        original_raw = [command.raw for command in commands]

        BulkAPI.from_byte_stream(
            BytesIO(BulkAPI.to_string(commands).encode("utf-8")),
            executor=AutomaticReportExecutor(),
            observer=collecting_observer,
        )

        final_raw = [command.raw for command in collecting_observer.commands]

        assert original_raw == final_raw
Beispiel #3
0
    def test_to_string(self, commands):
        nd_json = BulkAPI.to_string(commands)

        self._assert_nd_json_matches_commands(nd_json, commands)
Beispiel #4
0
    def test_to_string(self, commands):
        expected = deepcopy([command.raw for command in commands])

        nd_json = BulkAPI.to_string(commands)

        assert self._decode_ndjson(nd_json) == expected