Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: TT-225 Add test_add_sql_not_in_condition test and remove build_w…
…ith_order_by method
  • Loading branch information
VanessaIniguezG committed Apr 24, 2021
commit 5bdfcbf03b0efd5130a4844d571894a63968d6f1
27 changes: 27 additions & 0 deletions tests/utils/query_builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,30 @@ def test__build_order_by(
orderBy_condition = query_builder._CosmosDBQueryBuilder__build_order_by()

assert orderBy_condition == expected_order_by_condition

@pytest.mark.parametrize(
"attribute,ids_list,expected_not_in_list",
[
("id", [], []),
(None, None, []),
("id", None, []),
(None, ["id"], []),
("id", ["id"], ["c.id NOT IN ('id')"]),
("id", ["id1", "id2"], ["c.id NOT IN ('id1', 'id2')"]),
("owner_id", ["id1", "id2"], ["c.owner_id NOT IN ('id1', 'id2')"]),
("customer_id", ["id1", "id2"], [
"c.customer_id NOT IN ('id1', 'id2')"]),
],
)
def test_add_sql_not_in_condition(
attribute,
ids_list,
expected_not_in_list,
):
query_builder = CosmosDBQueryBuilder().add_sql_not_in_condition(
attribute, ids_list
)
assert len(query_builder.where_conditions) == len(
expected_not_in_list
)
assert query_builder.where_conditions == expected_not_in_list
2 changes: 1 addition & 1 deletion time_tracker_api/time_entries/time_entries_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def get_last_entry(
.add_sql_where_equal_condition({'owner_id': owner_id})
.add_sql_order_by_condition('end_date', Order.DESC)
.add_sql_not_in_condition('id', [id_running_entry])
.build_with_order_by()
.build()
)
query_str = query_builder.get_query()
params = query_builder.get_parameters()
Expand Down
13 changes: 0 additions & 13 deletions utils/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self):
self.limit = None
self.offset = None
self.order_by = None
self.not_in = []

def add_select_conditions(self, columns: List[str] = None):
columns = columns if columns else ["*"]
Expand Down Expand Up @@ -117,18 +116,6 @@ def build(self):
)
return self

def build_with_order_by(self):
self.query = """
SELECT {select_conditions} FROM c
{where_conditions}
{order_by_condition}
""".format(
select_conditions=self.__build_select(),
where_conditions=self.__build_where(),
order_by_condition=self.__build_order_by(),
)
return self

def get_query(self):
return self.query

Expand Down