Skip to content
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

Add tests #4

Open
reedv opened this issue Apr 1, 2021 · 1 comment
Open

Add tests #4

reedv opened this issue Apr 1, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@reedv
Copy link
Owner

reedv commented Apr 1, 2021

Here is an example I already use

import ckanapi
import pprint
import datetime


API_KEY = "xxxxxxxxxxxxxxxxxxxx" # some non-sysadmin's API token
demo = ckanapi.RemoteCKAN('http://myserver.myorg.local', apikey=API_KEY)
res = demo.action.package_list()
pprint.pprint(res)
res = demo.action.organization_list_for_user()
pprint.pprint(res)

TESTPKG_NAME = f"publicrestrictiondatasets_test{datetime.date.today().strftime('%Y%m%d')}"
TESTPKG_ORG = "xxxxxxxxxx-b9fb-4c77-8bbe-xxxxxxxxxx"
# attempt to create public dataset
print("\n==========\ntest creating public pkg\n==========")
try:
    res = demo.action.package_create(**{
        "name": TESTPKG_NAME,
        "private": False,
        "owner_org": TESTPKG_ORG
    })
    # pprint.pprint(res)
except Exception as e:
    pprint.pprint(e)
    errd = e.error_dict
    assert 'private' in errd
    assert errd['private'][0] == 'Only sysadmin users may set datasets as public'
    print("SUCCESS\n\n")

# attempt to create private dataset
print("\n==========\ntest creating private pkg\n==========")
res = demo.action.package_create(**{
    "name": TESTPKG_NAME,
    "private": True,
    "owner_org": TESTPKG_ORG
})
# pprint.pprint(res)
print("SUCCESS\n\n")

# attempt to convert private dataset public
print("\n==========\ntest convert private to public pkg\n==========")
try:
    res = demo.action.package_update(**{
        "name": TESTPKG_NAME,
        "private": False,
    })
    # pprint.pprint(res)
except Exception as e:
    pprint.pprint(e.error_dict)
    errd = e.error_dict
    assert 'private' in errd
    assert errd['private'][0] == 'Only sysadmin users may set datasets as public'
    print("SUCCESS\n\n")

# attempt to modify an existing public dataset in any other way
print("\n==========\ntest modify existing public pkg\n==========")
res = demo.action.package_update(**{
    "name": "another-public-test-dataset",
    "author": TESTPKG_NAME,
})
# pprint.pprint(res)
print("SUCCESS\n\n")

# delete dataset create for testing here
print("\n==========\n deleting test pkg\n==========")
res = demo.action.package_delete(**{
    "id": TESTPKG_NAME
})
pprint.pprint(res)
@reedv reedv added the enhancement New feature or request label Apr 1, 2021
@reedv
Copy link
Owner Author

reedv commented Apr 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant