-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RHINENG-1284] Tests are failing in test_api_assignment_rules_create.py #1440
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -107,8 +107,8 @@ def _db_get_groups_for_host(host_id): | |||
|
||||
@pytest.fixture(scope="function") | ||||
def db_get_assignment_rule(flask_app): | ||||
def _db_get_assignment_rule(ar_id): | ||||
return AssignmentRule.query.get(ar_id) | ||||
def _db_get_assignment_rule(ar_id, group_id): | ||||
return AssignmentRule.query.get((ar_id, group_id)) | ||||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? Isn't the assignment rule ID unique? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It led to a issue with multiple primary keys, and was not able to fetch the data using only the ID.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah... so then my follow-up question is, why do we need the primary key to consist of both the ID and group ID, when the ID should already be unique and non-nullable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not hehe. But it was initially created this way: In this case, we can create a new migration to remove the constraint from this column. As we are already making sure Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have an insights-host-inventory/migrations/versions/1689cda89252_add_assignment_rules_table.py Line 38 in 85e95ce
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I don't think it makes sense for the table's primary key to be a combination of unique IDs. If we already have an id field, that should be the primary key; otherwise it adds unnecessary complexity because you need both the assignment rule ID and its group ID in order to fetch the record, right? |
||||
|
||||
return _db_get_assignment_rule | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
|
||
|
||
def test_basic_assignment_rule_query(db_create_assignment_rule, db_create_group, api_get): | ||
group = db_create_group("TestGroup") | ||
groups = [db_create_group(f"TestGroup_{i}") for i in range(3)] | ||
filter = {"AND": [{"fqdn": {"eq": "foo.bar.com"}}]} | ||
|
||
assignment_rule_id_list = [ | ||
str(db_create_assignment_rule(f"assignment {idx}", group.id, filter, True).id) for idx in range(3) | ||
str(db_create_assignment_rule(f"assignment {idx}", groups[idx].id, filter, True).id) for idx in range(3) | ||
] | ||
response_status, response_data = api_get(build_assignment_rules_url()) | ||
|
||
|
@@ -38,10 +38,10 @@ def test_get_assignment_rule_by_name(db_create_assignment_rule, db_create_group, | |
|
||
|
||
def test_get_assignment_rule_with_bad_name(db_create_assignment_rule, db_create_group, api_get): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not an issue with your changes, but am I missing the point of this test? It doesn't appear to be testing any scenario related to having a bad name (and both responses return 200) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, it validates that 3 rules were created, make an api call with a name that will not be in the list, and validate the return is an empty list. We do not trigger an error when fetching rules that are not in the DB @thearifismail Can you add more context here? Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from what I read, the |
||
group = db_create_group("TestGroup") | ||
groups = [db_create_group(f"TestGroup_{i}") for i in range(3)] | ||
filter = {"AND": [{"fqdn": {"eq": "foo.bar.com"}}]} | ||
|
||
_ = [db_create_assignment_rule(f"assignment {idx}", group.id, filter, True).id for idx in range(3)] | ||
_ = [db_create_assignment_rule(f"assignment {idx}", groups[idx].id, filter, True).id for idx in range(3)] | ||
|
||
response_status, response_data = api_get(build_assignment_rules_url()) | ||
assert response_status == 200 | ||
|
@@ -66,10 +66,10 @@ def test_get_assignment_rule_with_bad_name(db_create_assignment_rule, db_create_ | |
), | ||
) | ||
def test_order_by_and_order_how(db_create_assignment_rule, db_create_group, api_get, order_by, order_how): | ||
group = db_create_group("TestGroup") | ||
groups = [db_create_group(f"TestGroup_{i}") for i in range(3)] | ||
filter = {"AND": [{"fqdn": {"eq": "foo.bar.com"}}]} | ||
|
||
_ = [db_create_assignment_rule(f"assignment {idx}", group.id, filter, True) for idx in range(3)] | ||
_ = [db_create_assignment_rule(f"assignment {idx}", groups[idx].id, filter, True).id for idx in range(3)] | ||
|
||
_, response_data = api_get(build_assignment_rules_url()) | ||
assert len(response_data["results"]) == 3 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't this got removed because it broke the filtering?
https://redhat-internal.slack.com/archives/CQFKM031T/p1689276193983449?thread_ts=1689271922.019339&cid=CQFKM031T
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove it from the model.py file and create a new migration to remove this constraint from the column, or we can add it as this PR suggests and it will be aligned with the DB modeling we have today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpramos123 I was checking the migration files and since this change doesn't break the tests we can leave it as it is.