mirror of https://github.com/zulip/zulip.git
parent
66f016edbb
commit
6f0410774c
|
@ -6,7 +6,7 @@ from __future__ import print_function
|
|||
from django.db import connection
|
||||
from django.test import override_settings
|
||||
from sqlalchemy.sql import (
|
||||
and_, select, column,
|
||||
and_, select, column, table,
|
||||
)
|
||||
from sqlalchemy.sql import compiler # type: ignore
|
||||
|
||||
|
@ -47,7 +47,6 @@ def get_sqlalchemy_query_params(query):
|
|||
# type: (Text) -> Dict[Text, Text]
|
||||
dialect = get_sqlalchemy_connection().dialect # type: ignore
|
||||
comp = compiler.SQLCompiler(dialect, query)
|
||||
comp.compile()
|
||||
return comp.params
|
||||
|
||||
def fix_ws(s):
|
||||
|
@ -73,7 +72,7 @@ class NarrowBuilderTest(ZulipTestCase):
|
|||
self.realm = get_realm('zulip')
|
||||
self.user_profile = get_user_profile_by_email("hamlet@zulip.com")
|
||||
self.builder = NarrowBuilder(self.user_profile, column('id'))
|
||||
self.raw_query = select([column("id")], None, "zerver_message")
|
||||
self.raw_query = select([column("id")], None, table("zerver_message"))
|
||||
|
||||
def test_add_term_using_not_defined_operator(self):
|
||||
# type: () -> None
|
||||
|
@ -1140,7 +1139,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
]
|
||||
|
||||
muting_conditions = exclude_muting_conditions(user_profile, narrow)
|
||||
query = select([column("id").label("message_id")], None, "zerver_message")
|
||||
query = select([column("id").label("message_id")], None, table("zerver_message"))
|
||||
query = query.where(*muting_conditions)
|
||||
expected_query = '''
|
||||
SELECT id AS message_id
|
||||
|
@ -1156,7 +1155,7 @@ class GetOldMessagesTest(ZulipTestCase):
|
|||
mute_stream(realm, user_profile, 'Verona')
|
||||
narrow = []
|
||||
muting_conditions = exclude_muting_conditions(user_profile, narrow)
|
||||
query = select([column("id")], None, "zerver_message")
|
||||
query = select([column("id")], None, table("zerver_message"))
|
||||
query = query.where(and_(*muting_conditions))
|
||||
|
||||
expected_query = '''
|
||||
|
|
|
@ -49,7 +49,7 @@ from zerver.models import Message, UserProfile, Stream, Subscription, \
|
|||
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.sql import select, join, column, literal_column, literal, and_, \
|
||||
or_, not_, union_all, alias, Selectable, Select, ColumnElement
|
||||
or_, not_, union_all, alias, Selectable, Select, ColumnElement, table
|
||||
|
||||
import re
|
||||
import ujson
|
||||
|
@ -122,7 +122,7 @@ class NarrowBuilder(object):
|
|||
def by_is(self, query, operand, maybe_negate):
|
||||
# type: (Query, str, ConditionTransform) -> Query
|
||||
if operand == 'private':
|
||||
query = query.select_from(join(query.froms[0], "zerver_recipient",
|
||||
query = query.select_from(join(query.froms[0], table("zerver_recipient"),
|
||||
column("recipient_id") ==
|
||||
literal_column("zerver_recipient.id")))
|
||||
cond = or_(column("type") == Recipient.PERSONAL,
|
||||
|
@ -535,18 +535,18 @@ def get_old_messages_backend(request, user_profile,
|
|||
include_history = ok_to_include_history(narrow, user_profile.realm)
|
||||
|
||||
if include_history and not use_first_unread_anchor:
|
||||
query = select([column("id").label("message_id")], None, "zerver_message")
|
||||
query = select([column("id").label("message_id")], None, table("zerver_message"))
|
||||
inner_msg_id_col = literal_column("zerver_message.id")
|
||||
elif narrow is None:
|
||||
query = select([column("message_id"), column("flags")],
|
||||
column("user_profile_id") == literal(user_profile.id),
|
||||
"zerver_usermessage")
|
||||
table("zerver_usermessage"))
|
||||
inner_msg_id_col = column("message_id")
|
||||
else:
|
||||
# TODO: Don't do this join if we're not doing a search
|
||||
query = select([column("message_id"), column("flags")],
|
||||
column("user_profile_id") == literal(user_profile.id),
|
||||
join("zerver_usermessage", "zerver_message",
|
||||
join(table("zerver_usermessage"), table("zerver_message"),
|
||||
literal_column("zerver_usermessage.message_id") ==
|
||||
literal_column("zerver_message.id")))
|
||||
inner_msg_id_col = column("message_id")
|
||||
|
@ -572,7 +572,7 @@ def get_old_messages_backend(request, user_profile,
|
|||
if term['operator'] == 'search':
|
||||
if not is_search:
|
||||
search_term = term
|
||||
query = query.column("subject").column("rendered_content")
|
||||
query = query.column(column("subject")).column(column("rendered_content"))
|
||||
is_search = True
|
||||
else:
|
||||
# Join the search operators if there are multiple of them
|
||||
|
@ -1081,7 +1081,7 @@ def messages_in_narrow_backend(request, user_profile,
|
|||
query = select([column("message_id"), column("subject"), column("rendered_content")],
|
||||
and_(column("user_profile_id") == literal(user_profile.id),
|
||||
column("message_id").in_(msg_ids)),
|
||||
join("zerver_usermessage", "zerver_message",
|
||||
join(table("zerver_usermessage"), table("zerver_message"),
|
||||
literal_column("zerver_usermessage.message_id") ==
|
||||
literal_column("zerver_message.id")))
|
||||
|
||||
|
|
Loading…
Reference in New Issue