def test_register_serialized_flow(self, already_exists, is_new_version,
                                      force, exp_version):
        client = MagicMock()
        client.graphql.side_effect = responses = []
        if already_exists:
            responses.append(
                GraphQLResult(
                    {"data": {
                        "flow": [{
                            "id": "old-id",
                            "version": 1
                        }]
                    }}))
        else:
            responses.append(GraphQLResult({"data": {"flow": []}}))

        exp_id = "new-id" if is_new_version else "old-id"
        responses.append(
            GraphQLResult({
                "data": {
                    "create_flow_from_compressed_string": {
                        "id": exp_id
                    }
                }
            }))

        serialized_flow = Flow("testing").serialize(build=False)

        flow_id, flow_version, is_new = register_serialized_flow(
            client, serialized_flow, "my-project-id", force)

        assert flow_id == exp_id
        assert flow_version == exp_version
        assert is_new == is_new_version
    def test_register_serialized_flow_toggle_schedule(self, schedule):
        client = MagicMock()
        client.graphql.side_effect = [
            GraphQLResult({"data": {
                "flow": []
            }}),
            GraphQLResult(
                {"data": {
                    "create_flow_from_compressed_string": {
                        "id": "id"
                    }
                }}),
        ]

        serialized_flow = Flow("testing").serialize(build=False)

        register_serialized_flow(client,
                                 serialized_flow,
                                 "my-project-id",
                                 schedule=schedule)

        assert (client.graphql.call_args[1]["variables"]["input"]
                ["set_schedule_active"] == schedule)