Skip to content
Snippets Groups Projects
Verified Commit d8ccda3d authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Fix tests

parent c98e4866
No related branches found
No related tags found
No related merge requests found
...@@ -547,8 +547,6 @@ class CmpOp(_Op): ...@@ -547,8 +547,6 @@ class CmpOp(_Op):
ref = self._identifier.table ref = self._identifier.table
field = self._identifier.column field = self._identifier.column
if field.endswith("_id"):
field = field[:-3]
result = {"type": "pov", result = {"type": "pov",
"negation": self.is_negated, "negation": self.is_negated,
"p": field, "p": field,
......
...@@ -99,7 +99,6 @@ def test_merge_joins_and_where_no_where_one_join(): ...@@ -99,7 +99,6 @@ def test_merge_joins_and_where_no_where_one_join():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
}] }]
where = None where = None
...@@ -110,7 +109,6 @@ def test_merge_joins_and_where_no_where_one_join(): ...@@ -110,7 +109,6 @@ def test_merge_joins_and_where_no_where_one_join():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
} }
def test_merge_joins_and_where_no_where_two_join(): def test_merge_joins_and_where_no_where_two_join():
...@@ -119,13 +117,11 @@ def test_merge_joins_and_where_no_where_two_join(): ...@@ -119,13 +117,11 @@ def test_merge_joins_and_where_no_where_two_join():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
},{ },{
"type": "reference", "type": "reference",
"p": "p2", "p": "p2",
"v": "rt2", "v": "rt2",
"negation": False, "negation": False,
"str": "REFERENCES rt2 AS p2",
}] }]
where = None where = None
...@@ -139,13 +135,11 @@ def test_merge_joins_and_where_no_where_two_join(): ...@@ -139,13 +135,11 @@ def test_merge_joins_and_where_no_where_two_join():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
},{ },{
"type": "reference", "type": "reference",
"p": "p2", "p": "p2",
"v": "rt2", "v": "rt2",
"negation": False, "negation": False,
"str": "REFERENCES rt2 AS p2",
} }
] ]
} }
...@@ -156,7 +150,6 @@ def test_merge_joins_and_where_independent_where(): ...@@ -156,7 +150,6 @@ def test_merge_joins_and_where_independent_where():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
}] }]
where = { where = {
"type": "pov", "type": "pov",
...@@ -182,7 +175,6 @@ def test_merge_joins_and_where_independent_where(): ...@@ -182,7 +175,6 @@ def test_merge_joins_and_where_independent_where():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
} }
] ]
} }
...@@ -193,7 +185,6 @@ def test_merge_joins_and_where_backref_sub_query_id(): ...@@ -193,7 +185,6 @@ def test_merge_joins_and_where_backref_sub_query_id():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "IS REFERENCED BY rt1 AS p1",
}] }]
where = { where = {
"type": "pov", "type": "pov",
...@@ -212,7 +203,6 @@ def test_merge_joins_and_where_backref_sub_query_id(): ...@@ -212,7 +203,6 @@ def test_merge_joins_and_where_backref_sub_query_id():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "IS REFERENCED BY rt1 AS p1",
"sub": { "sub": {
"type": "pov", "type": "pov",
"ref": "rt1", "ref": "rt1",
...@@ -231,7 +221,6 @@ def test_merge_joins_and_where_ref_sub_query_id(): ...@@ -231,7 +221,6 @@ def test_merge_joins_and_where_ref_sub_query_id():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
}] }]
where = { where = {
"type": "in", "type": "in",
...@@ -246,7 +235,6 @@ def test_merge_joins_and_where_ref_sub_query_id(): ...@@ -246,7 +235,6 @@ def test_merge_joins_and_where_ref_sub_query_id():
"p": "p1", "p": "p1",
"v": "rt1", "v": "rt1",
"negation": False, "negation": False,
"str": "REFERENCES rt1 AS p1",
"sub": { "sub": {
"type": "in", "type": "in",
"p": "ID", "p": "ID",
...@@ -281,7 +269,6 @@ def test_parse_select_join(): ...@@ -281,7 +269,6 @@ def test_parse_select_join():
"p": "content_type_id", "p": "content_type_id",
"v": "django_content_type", "v": "django_content_type",
"negation": False, "negation": False,
"str": "REFERENCES django_content_type AS content_type_id",
} }
assert select_query._needs_aggregation() is True assert select_query._needs_aggregation() is True
...@@ -292,7 +279,6 @@ def test_parse_select_join(): ...@@ -292,7 +279,6 @@ def test_parse_select_join():
"type": "reference", "type": "reference",
"p": "content_type_id", "p": "content_type_id",
"v": "django_content_type", "v": "django_content_type",
"str": "REFERENCES django_content_type AS content_type_id",
"negation": False, "negation": False,
"sub": {"type": "in", "sub": {"type": "in",
"p": "ID", "p": "ID",
...@@ -413,7 +399,6 @@ def test_inner_and_outer_join(): ...@@ -413,7 +399,6 @@ def test_inner_and_outer_join():
assert inner_join.to_mongo() == { assert inner_join.to_mongo() == {
"type": "reference", "type": "reference",
'negation': False, 'p': 'b_id', 'negation': False, 'p': 'b_id',
'str': 'REFERENCES B AS b_id',
'v': 'B'} 'v': 'B'}
assert left_outer_join.to_mongo() == {} assert left_outer_join.to_mongo() == {}
...@@ -421,11 +406,11 @@ def test_inner_and_outer_join(): ...@@ -421,11 +406,11 @@ def test_inner_and_outer_join():
callback, pipeline = select_query._to_caosdb() callback, pipeline = select_query._to_caosdb()
assert callback == connection.aggregate assert callback == connection.aggregate
assert "joins" not in pipeline assert "joins" not in pipeline
print(pipeline["filter"])
assert pipeline["filter"] == { assert pipeline["filter"] == {
"type": "reference", "type": "reference",
'negation': False, 'negation': False,
'p': 'b_id', 'p': 'b_id',
'str': 'REFERENCES B AS b_id',
'v': 'B', 'v': 'B',
"sub": { "sub": {
"type": "pov", "type": "pov",
...@@ -455,21 +440,19 @@ def test_query_generation_conjuction(): ...@@ -455,21 +440,19 @@ def test_query_generation_conjuction():
'p': 'auth_group_permissions.group_id', 'p': 'auth_group_permissions.group_id',
'o': '=', 'v': 226 'o': '=', 'v': 226
}, {'type': 'reference', 'p': 'content_type_id', }, {'type': 'reference', 'p': 'content_type_id',
'v': 'django_content_type', 'negation': False, 'v': 'django_content_type', 'negation': False, }]},
'str': 'REFERENCES django_content_type AS content_type_id'}]},
count=False) count=False)
assert query == ('SELECT id, django_content_type.app_label, ' assert query == ('SELECT id, django_content_type.app_label, '
'django_content_type.model, codename FROM RECORD ' 'django_content_type.model, codename FROM RECORD '
'"auth_permission" WITH auth_group_permissions.' '"auth_permission" WITH auth_group_permissions.'
'group_id="226" AND REFERENCES django_content_type ' 'group_id="226" AND REFERENCES django_content_type')
'AS content_type_id')
def test_parse_select_join_with_reverse_on_clause(): def test_parse_select_join_with_reverse_on_clause():
sql = """ sql = """
SELECT "A"."id", "A"."p1" SELECT "A"."id", "A"."p1"
FROM "A" FROM "A"
INNER JOIN "B" INNER JOIN "B"
ON ("A"."id" = "B"."a_id") ON ("A"."id" = "B"."a")
WHERE "B"."p2" = %(0)s WHERE "B"."p2" = %(0)s
""" """
cached_record_types = [ cached_record_types = [
...@@ -499,8 +482,7 @@ def test_parse_select_join_with_reverse_on_clause(): ...@@ -499,8 +482,7 @@ def test_parse_select_join_with_reverse_on_clause():
assert inner_join.to_mongo() == { assert inner_join.to_mongo() == {
"type": "back_reference", "type": "back_reference",
'negation': False, 'p': 'a_id', 'negation': False, 'p': 'a',
'str': 'IS REFERENCED BY B AS a_id',
'v': 'B'} 'v': 'B'}
callback, pipeline = select_query._to_caosdb() callback, pipeline = select_query._to_caosdb()
...@@ -510,8 +492,7 @@ def test_parse_select_join_with_reverse_on_clause(): ...@@ -510,8 +492,7 @@ def test_parse_select_join_with_reverse_on_clause():
assert pipeline["filter"] == { assert pipeline["filter"] == {
"type": "back_reference", "type": "back_reference",
'negation': False, 'negation': False,
'p': 'a_id', 'p': 'a',
'str': 'IS REFERENCED BY B AS a_id',
'v': 'B', 'v': 'B',
"sub": { "sub": {
"type": "pov", "type": "pov",
...@@ -528,3 +509,69 @@ def test_parse_select_join_with_reverse_on_clause(): ...@@ -528,3 +509,69 @@ def test_parse_select_join_with_reverse_on_clause():
# excute # excute
select_query._get_cursor() select_query._get_cursor()
def test_inner_join_with_bad_names():
sql = """SELECT "A"."id", "A"."p1", "A"."p2" FROM
"A" INNER JOIN "B" ON ("A"."id" =
"B"."language_id") WHERE
"B"."material_id" = %(0)s"""
cached_record_types = [
"A",
"B",
]
params = ["227"]
connection = _MockConnection(cached_record_types=cached_record_types)
q = Query(connection=connection, sql=sql, params=params)
assert isinstance(q._query, SelectQuery)
select_query = q._query
assert select_query.left_table == "A"
assert select_query.where is not None
assert select_query.where.to_mongo() == {
"type": "pov", 'negation': False,
# TODO
'o': '=', 'p': 'material_id', 'ref': "B", 'v': '227'}
assert select_query._needs_aggregation() is True
assert len(select_query.joins) == 1
inner_join = select_query.joins[0]
assert isinstance(inner_join, InnerJoinConverter)
assert inner_join.to_mongo() == {
"type": "back_reference",
# TODO
'negation': False, 'p': 'language_id',
# TODO
'v': 'B'}
callback, pipeline = select_query._to_caosdb()
assert callback == connection.aggregate
assert "joins" not in pipeline
print(pipeline["filter"])
assert pipeline["filter"] == {
"type": "back_reference",
'negation': False,
# TODO
'p': 'language_id',
# TODO
'v': 'B',
"sub": {
"type": "pov",
'negation': False,
'ref': "B",
# TODO
'p': 'material_id',
'o': '=',
'v': '227'
},
}
assert "sort" not in pipeline
assert pipeline["projection"] == ["id", "p1", "p2"]
# excute
select_query._get_cursor()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment