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
def test_prepare_for_execute_merges_queries(self, user_command, group_command): # You don't get mixed command types, but it's helpful here as one has # a query and the other doesn't assert "groupid" in group_command.body.meta["query"] assert "groupid" not in group_command.body.attributes UpsertCommand.prepare_for_execute( [user_command, group_command], {"merge_query": True} ) assert "groupid" in group_command.body.meta["query"] assert "groupid" in group_command.body.attributes
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 :rtype: UpsertCommand """ return UpsertCommand.create( CommandType.UPSERT, UpsertGroup.create(attributes, id_reference) )
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 :rtype: UpsertCommand """ return UpsertCommand.create( CommandType.UPSERT, UpsertUser.create(attributes, id_reference) )
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` """ command = Command(raw) if command.type is CommandType.CONFIGURE: return ConfigCommand(raw) if command.type is CommandType.CREATE: return CreateCommand(raw) elif command.type is CommandType.UPSERT: return UpsertCommand(raw)
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}