Example #1
0
    def test_prepare_for_execute_does_not_merge_when_told_not_to(self, upsert_command):
        query = deepcopy(upsert_command.body.meta["query"])

        UpsertCommand.prepare_for_execute([upsert_command], {"merge_query": False})

        assert upsert_command.body.query == query

        for key in query.keys():
            assert key not in upsert_command.body.attributes
Example #2
0
    def test_prepare_for_execute_merges_queries(self, upsert_command):
        query = deepcopy(upsert_command.body.meta["query"])
        assert query

        for key in query.keys():
            assert key not in upsert_command.body.attributes

        UpsertCommand.prepare_for_execute([upsert_command], {"merge_query": True})

        for key in query.keys():
            assert key in upsert_command.body.meta["query"]
            assert key in upsert_command.body.attributes
Example #3
0
        def upsert(cls, attributes, id_reference):
            """Create a group upsert command.

            :param attributes: Dict of group fields and values
            :param id_reference: Custom reference to this group
            :return: An UpsertCommand object configured with a group body
            :rtype: UpsertCommand
            """
            return UpsertCommand.create(
                CommandType.UPSERT, UpsertGroup.create(attributes,
                                                       id_reference))
Example #4
0
        def upsert(cls, attributes, id_reference):
            """Create a user upsert command.

            :param attributes: Dict of user fields and values
            :param id_reference: Custom reference to this user
            :return: An UpsertCommand object configured with a user body
            :rtype: UpsertCommand
            """
            return UpsertCommand.create(
                CommandType.UPSERT, UpsertUser.create(attributes,
                                                      id_reference))
Example #5
0
    def from_data(cls, raw):
        """Create a command from a raw data structure.

        :param raw: The data to decode
        :returns: An appropriate child of `Command`
        :raise ValueError: If the command type is unknown
        """

        command = Command(raw)

        if command.type is CommandType.CONFIGURE:
            return ConfigCommand(raw)

        if command.type is CommandType.CREATE:
            return CreateCommand(raw)

        assert (command.type is
                CommandType.UPSERT), "Last remaining acceptable value found"

        return UpsertCommand(raw)
Example #6
0
    def test_prepare_for_execute_pops_merge_query_from_config(self, user_command):
        config = {"merge_query": True, "another": True}

        UpsertCommand.prepare_for_execute([user_command], config)

        assert config == {"another": True}