Skip to content

Commit

Permalink
Merge pull request #7749 from ckan/create-alias-twice-fix
Browse files Browse the repository at this point in the history
fix tests: test_create_alias_twice relied on unstable ordering
  • Loading branch information
smotornyuk committed Aug 29, 2023
2 parents 3c36800 + aa0174a commit 6dc1696
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions changes/7749.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't rely on stable ordering from unstable model.Package.resources list
2 changes: 1 addition & 1 deletion ckan/migration/revision_legacy_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def make_revisioned_table(base_table, frozen=False):
for col in base_table.c:
if col.primary_key:
pkcols.append(col)
assert len(pkcols) <= 1,\
assert len(pkcols) <= 1, \
u'Do not support versioning objects with multiple primary keys'
fk_name = base_table.name + u'.' + pkcols[0].name
revision_table.append_column(
Expand Down
6 changes: 3 additions & 3 deletions ckan/tests/cli/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def test_revoke(self, cli):
call_action(u"api_token_create", user=user[u"id"], name=u"first token")
tid = model.Session.query(model.ApiToken).first().id

# tid must be escaped. When it starts with a hyphen it treated as a
# flag otherwise.
args = f'user token revoke "{tid}"'
# tid must be prefixed by --. When it starts with a hyphen it treated
# as a flag otherwise.
args = f'user token revoke -- "{tid}"'
result = cli.invoke(ckan, args)
assert not result.exit_code, result.output
assert u"API Token has been revoked" in result.output
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/lib/dictization/test_model_dictize.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_group_dictize_for_org_with_package_list(self):

org = model_dictize.group_dictize(group_obj, context)

assert type(org["packages"]) == list
assert isinstance(org["packages"], list)
assert len(org["packages"]) == 1
assert org["packages"][0]["name"] == package["name"]

Expand Down
6 changes: 3 additions & 3 deletions ckan/tests/logic/action/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,7 @@ def test_status_show(self):
assert status["site_description"] == ""
assert status["locale_default"] == "en"

assert type(status["extensions"]) == list
assert isinstance(status["extensions"], list)
assert status["extensions"] == ["stats"]

@pytest.mark.ckan_config("ckan.plugins", "stats")
Expand All @@ -2968,7 +2968,7 @@ def test_status_show_hiding_version(self):
assert status["site_description"] == ""
assert status["locale_default"] == "en"

assert type(status["extensions"]) == list
assert isinstance(status["extensions"], list)
assert status["extensions"] == ["stats"]

@pytest.mark.ckan_config("ckan.plugins", "stats")
Expand All @@ -2984,7 +2984,7 @@ def test_status_show_version_to_sysadmins(self):
assert status["site_description"] == ""
assert status["locale_default"] == "en"

assert type(status["extensions"]) == list
assert isinstance(status["extensions"], list)
assert status["extensions"] == ["stats"]


Expand Down
3 changes: 2 additions & 1 deletion ckan/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def purge_all(self):

def purge_entity(self, ent_type: str):
entities = self.deleted_entities[ent_type]
number = len(entities) if type(entities) == list else entities.count()
number = len(entities) if isinstance(entities, list) \
else entities.count()

for ent in entities:
entity_id = ent.id if hasattr(ent, 'id') else ent['id']
Expand Down
7 changes: 3 additions & 4 deletions ckanext/datastore/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,9 @@ def test_create_invalid_unique_index(self, app):
@pytest.mark.ckan_config("ckan.plugins", "datastore")
@pytest.mark.usefixtures("with_plugins")
def test_create_alias_twice(self, app):
resource = model.Package.get("annakarenina").resources[1]
res1, res2 = model.Package.get("annakarenina").resources[:2]
data = {
"resource_id": resource.id,
"resource_id": res1.id,
"aliases": "new_alias",
"fields": [
{"id": "book", "type": "text"},
Expand All @@ -656,9 +656,8 @@ def test_create_alias_twice(self, app):
res_dict = json.loads(res.data)
assert res_dict["success"] is True, res_dict

resource = model.Package.get("annakarenina").resources[0]
data = {
"resource_id": resource.id,
"resource_id": res2.id,
"aliases": "new_alias",
"fields": [{"id": "more books", "type": "text"}],
}
Expand Down

0 comments on commit 6dc1696

Please sign in to comment.