Here are the examples of the python api django.contrib.auth.models.User.objects.create taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_empty(self):
user = User.objects.create(username="a", email="[email protected]")
Workflow.create_and_init(owner=user)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(
result, {"maxFetchesPerDay": 500, "nFetchesPerDay": 0, "autofetches": []}
)
3
View Complete Implementation : test_decorators.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_auth_owner_deny_viewer(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.objects.create()
workflow.acl.create(email="[email protected]", can_edit=False)
ret = self.run_handler(handle_owner, user=user, workflow=workflow)
self.astertHandlerResponse(
ret, error=("AuthError: no owner access to workflow")
)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_get_file_upload_api_token(self):
# Currently, we don't restrict this API to just "upload" modules. We do
# restrict the actual _uploads_, so this oversight isn't a big deal.
user = User.objects.create()
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
module_id_name="x", order=0, slug="step-1", file_upload_api_token="abcd1234"
)
response = self.run_handler(
get_file_upload_api_token,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
)
self.astertResponse(response, data={"apiToken": "abcd1234"})
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_collapsed(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
order=0, slug="step-1", is_collapsed=False
)
response = self.run_handler(
set_collapsed,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
isCollapsed=True,
)
self.astertResponse(response, data=None)
wf_module.refresh_from_db()
self.astertEqual(wf_module.is_collapsed, True)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_clear_file_upload_api_token(self):
# Currently, we don't restrict this API to just "upload" modules. We do
# restrict the actual _uploads_, so this oversight isn't a big deal.
user = User.objects.create()
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
module_id_name="x", order=0, slug="step-1", file_upload_api_token="abcd1234"
)
response = self.run_handler(
clear_file_upload_api_token,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
)
wf_module.refresh_from_db()
self.astertResponse(response, data=None)
self.astertIsNone(wf_module.file_upload_api_token)
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_ignore_wrong_user(self):
user = User.objects.create(username="a", email="[email protected]")
Workflow.create_and_init(owner=user)
user2 = User.objects.create(username="b", email="[email protected]")
workflow2 = Workflow.create_and_init(owner=user2)
workflow2.tabs.first().wf_modules.create(
order=0,
slug="step-1",
module_id_name="loadurl",
auto_update_data=True,
next_update=timezone.now(),
update_interval=600,
)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(result["autofetches"], [])
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_put_entry(self):
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
response = self._put_entry(workflow, user, "[email protected]", '{"canEdit": true}')
self.astertEqual(response.status_code, 204)
entry = workflow.acl.first()
self.astertEqual(entry.email, "[email protected]")
self.astertEqual(entry.can_edit, True)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_stored_data_version_invalid_date(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
response = self.run_handler(
set_stored_data_version,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
version=["not a date"],
)
self.astertResponse(
response, error="BadRequest: version must be an ISO8601 datetime"
)
3
View Complete Implementation : test_websockets.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def setUp(self):
super().setUp()
self.user = User.objects.create(username="usual", email="[email protected]")
self.workflow = Workflow.create_and_init(name="Workflow 1", owner=self.user)
self.application = self.mock_auth_middleware(create_url_router())
self.communicators = []
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_params_invalid_wf_module(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
other_workflow = Workflow.create_and_init(owner=user)
wf_module = other_workflow.tabs.first().wf_modules.create(
order=0, slug="step-1"
)
response = self.run_handler(
set_params,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
values={"foo": "bar"},
)
self.astertResponse(response, error="DoesNotExist: WfModule not found")
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_ignore_non_auto_update(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user, name="W1")
workflow.tabs.first().wf_modules.create(
order=0,
slug="step-1",
module_id_name="loadurl",
auto_update_data=False,
update_interval=600,
)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(result["autofetches"], [])
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_delete_entry_as_non_owner(self):
# Even editors don't get to edit the user list
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
user2 = User.objects.create(
username="[email protected]", email="[email protected]"
)
workflow.acl.create(email="[email protected]", can_edit=True)
response = self._delete_entry(workflow, user2, "[email protected]")
self.astertEqual(response.status_code, 403)
self.astertEqual(len(workflow.acl.all()), 1)
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_put_entry_dup(self):
# dup overwrites the existing entry
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
dt = timezone.datetime(2018, 10, 3, 19, 28, 1, tzinfo=timezone.utc)
workflow.acl.create(email="[email protected]", can_edit=False, created_at=dt)
response = self._put_entry(workflow, user, "[email protected]", '{"canEdit": true}')
self.astertEqual(response.status_code, 204)
# No new entry added
self.astertEqual(len(workflow.acl.all()), 1)
# ... but entry was updated
entry = workflow.acl.first()
self.astertEqual(entry.email, "[email protected]") # not changed
self.astertEqual(entry.can_edit, True) # changed
self.astertEqual(entry.created_at, dt) # not changed
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_create(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
response = self.run_handler(
create, user=user, workflow=workflow, slug="tab-ab13", name="Foo"
)
self.astertResponse(response, data=None)
self.astertEqual(workflow.live_tabs.count(), 2)
self.astertEqual(workflow.live_tabs.last().name, "Foo")
self.astertEqual(workflow.live_tabs.last().slug, "tab-ab13")
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_delete_entry_missing(self):
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
# A different user
workflow.acl.create(email="[email protected]", can_edit=True)
response = self._delete_entry(workflow, user, "[email protected]")
self.astertEqual(response.status_code, 204)
# Non-requested entry not deleted
self.astertEqual(len(workflow.acl.all()), 1)
3
View Complete Implementation : test_decorators.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_auth_read_viewer(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.objects.create()
workflow.acl.create(email="[email protected]", can_edit=False)
ret = self.run_handler(handle_read, user=user, workflow=workflow)
self.astertHandlerResponse(ret, {"role": "read"})
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_get_file_upload_api_token_null(self):
user = User.objects.create()
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
module_id_name="x", order=0, slug="step-1", file_upload_api_token=None
)
response = self.run_handler(
get_file_upload_api_token,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
)
self.astertResponse(response, data={"apiToken": None})
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_name_missing_tab(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user) # tab-1
response = self.run_handler(
set_name, user=user, workflow=workflow, tabSlug="tab-2", name="B"
)
self.astertResponse(response, error="DoesNotExist: Tab not found")
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
@patch("server.rabbitmq.queue_render", async_noop)
def test_delete(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
response = self.run_handler(
delete, user=user, workflow=workflow, wfModuleId=wf_module.id
)
self.astertResponse(response, data=None)
command = DeleteModuleCommand.objects.first()
self.astertEquals(command.wf_module_id, wf_module.id)
wf_module.refresh_from_db()
self.astertEqual(wf_module.is_deleted, True)
3
View Complete Implementation : test_websockets.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
async def test_deny_other_users_workflow(self, communicate):
other_workflow = Workflow.create_and_init(
name="Workflow 2",
owner=User.objects.create(username="other", email="[email protected]"),
)
comm = communicate(self.application, f"/workflows/{other_workflow.id}/")
connected, _ = await comm.connect()
self.astertFalse(connected)
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_delete(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
tab2 = workflow.tabs.create(position=1, slug="tab-2")
response = self.run_handler(
delete, user=user, workflow=workflow, tabSlug="tab-2"
)
self.astertResponse(response, data=None)
self.astertEqual(workflow.live_tabs.count(), 1)
tab2.refresh_from_db()
self.astertTrue(tab2.is_deleted)
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_ignore_deleted_wf_module(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user, name="W1")
workflow.tabs.first().wf_modules.create(
order=0,
slug="step-1",
module_id_name="loadurl",
auto_update_data=True,
next_update=timezone.now(),
update_interval=600,
is_deleted=True,
)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(result["autofetches"], [])
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_collapsed_forces_bool(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
order=0, slug="step-1", is_collapsed=False
)
# bool('False') is true
response = self.run_handler(
set_collapsed,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
isCollapsed="False",
)
self.astertResponse(response, data=None)
wf_module.refresh_from_db()
self.astertEqual(wf_module.is_collapsed, True)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
@patch("server.websockets.queue_render_if_listening", async_noop)
def test_set_stored_data_version(self):
version = "2018-12-12T21:30:00.000Z"
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
wf_module.stored_objects.create(stored_at=isoparse(version), size=0)
response = self.run_handler(
set_stored_data_version,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
version=version,
)
self.astertResponse(response, data=None)
wf_module.refresh_from_db()
self.astertEqual(wf_module.stored_data_version, isoparse(version))
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_set_name(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user, name="A")
response = self.run_handler(set_name, user=user, workflow=workflow, name="B")
self.astertResponse(response, data=None)
command = ChangeWorkflowsatleCommand.objects.first()
self.astertEqual(command.new_value, "B")
self.astertEqual(command.old_value, "A")
workflow.refresh_from_db()
self.astertEqual(workflow.name, "B")
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_duplicate_missing_tab(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
response = self.run_handler(
duplicate,
user=user,
workflow=workflow,
tabSlug="tab-missing",
slug="tab-2",
name="Tab 2",
)
self.astertResponse(response, error="DoesNotExist: Tab not found")
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_ignore_deleted_tab(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user, name="W1")
tab = workflow.tabs.create(position=1, slug="tab-deleted", is_deleted=True)
tab.wf_modules.create(
order=0,
slug="step-1",
module_id_name="loadurl",
auto_update_data=True,
next_update=timezone.now(),
update_interval=600,
)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(result["autofetches"], [])
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_delete_entry(self):
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
workflow.acl.create(email="[email protected]", can_edit=False)
workflow.acl.create(email="[email protected]", can_edit=True)
response = self._delete_entry(workflow, user, "[email protected]")
self.astertEqual(response.status_code, 204)
# Entry deleted
self.astertEqual(len(workflow.acl.all()), 1)
self.astertEqual(len(workflow.acl.filter(email="[email protected]")), 1)
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
@patch("server.rabbitmq.queue_render", async_noop)
def test_duplicate(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
response = self.run_handler(
duplicate,
user=user,
workflow=workflow,
tabSlug="tab-1",
slug="tab-2",
name="Tab 2",
)
self.astertResponse(response, data=None)
self.astertEqual(workflow.live_tabs.count(), 2)
tab2 = workflow.live_tabs.last()
self.astertEqual(tab2.slug, "tab-2")
3
View Complete Implementation : test_upload.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_abort_upload_happy_path_after_complete(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
order=0, slug="step-1", module_id_name="x"
)
in_progress_upload = wf_module.in_progress_uploads.create(
id="147a9f5d-5b3e-41c3-a968-a84a5a9d587f"
)
key = in_progress_upload.get_upload_key()
minio.put_bytes(in_progress_upload.Bucket, key, b"1234567")
response = self.run_handler(
abort_upload, user=user, workflow=workflow, wfModuleId=wf_module.id, key=key
)
self.astertResponse(response, data=None)
wf_module.refresh_from_db()
self.astertFalse(minio.exists(in_progress_upload.Bucket, key))
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_with_deleted_user_profile(self):
# There's no good reason for UserProfile to be separate from User. But
# it is. So here we are -- sometimes it doesn't exist.
user = User.objects.create(username="a", email="[email protected]")
Workflow.create_and_init(owner=user)
user.user_profile.delete()
user.refresh_from_db()
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(
result, {"maxFetchesPerDay": 500, "nFetchesPerDay": 0, "autofetches": []}
)
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_set_name(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
tab = workflow.tabs.first() # tab-1
response = self.run_handler(
set_name, user=user, workflow=workflow, tabSlug="tab-1", name="B"
)
self.astertResponse(response, data=None)
tab.refresh_from_db()
self.astertEqual(tab.name, "B")
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_tab_order_invalid_tab_ids(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
response = self.run_handler(
set_tab_order, user=user, workflow=workflow, tabSlugs=[1, 2]
)
self.astertResponse(response, error="tabSlugs must be an Array of slugs")
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_set_name_coerce_to_str(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user, name="A")
response = self.run_handler(
set_name, user=user, workflow=workflow, name=["B", {"x": "y"}]
)
self.astertResponse(response, data=None)
workflow.refresh_from_db()
self.astertEqual(workflow.name, "['B', {'x': 'y'}]")
3
View Complete Implementation : test_autofetch.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_list_autofetches_gets_user_max_fetches_per_day(self):
user = User.objects.create(username="a", email="[email protected]")
user.user_profile.max_fetches_per_day = 6000
user.user_profile.save(update_fields=["max_fetches_per_day"])
Workflow.create_and_init(owner=user)
result = list_autofetches_json({"user": user, "session": None})
self.astertEqual(
result, {"maxFetchesPerDay": 6000, "nFetchesPerDay": 0, "autofetches": []}
)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_delete_invalid_wf_module(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
other_workflow = Workflow.create_and_init(owner=user)
wf_module = other_workflow.tabs.first().wf_modules.create(
order=0, slug="step-1"
)
response = self.run_handler(
delete, user=user, workflow=workflow, wfModuleId=wf_module.id
)
self.astertResponse(response, error="DoesNotExist: WfModule not found")
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_tab_order_wrong_tab_slugs(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user) # tab-1
workflow.tabs.create(position=1, slug="tab-2")
response = self.run_handler(
set_tab_order, user=user, workflow=workflow, tabSlugs=["tab-3", "tab-2"]
)
self.astertResponse(response, error="wrong tab slugs")
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
@patch("server.rabbitmq.queue_render", async_noop)
def test_set_params_no_module(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(
order=0, slug="step-1", module_id_name="x"
)
response = self.run_handler(
set_params,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
values={"foo": "bar"},
)
self.astertResponse(response, error="ValueError: Module x does not exist")
3
View Complete Implementation : test_decorators.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_auth_write_editor(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.objects.create()
workflow.acl.create(email="[email protected]", can_edit=True)
ret = self.run_handler(handle_write, user=user, workflow=workflow)
self.astertHandlerResponse(ret, {"role": "write"})
3
View Complete Implementation : test_acl.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_put_entry_as_non_owner(self):
# Even editors don't get to edit the user list
user = User.objects.create()
workflow = Workflow.objects.create(owner=user)
user2 = User.objects.create(
username="[email protected]", email="[email protected]"
)
workflow.acl.create(email="[email protected]", can_edit=True)
response = self._put_entry(
workflow, user2, "[email protected]", '{"canEdit": true}'
)
self.astertEqual(response.status_code, 403)
3
View Complete Implementation : test_decorators.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_auth_write_deny_viewer(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.objects.create()
workflow.acl.create(email="[email protected]", can_edit=False)
ret = self.run_handler(handle_write, user=user, workflow=workflow)
self.astertHandlerResponse(
ret, error=("AuthError: no write access to workflow")
)
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_add_module_missing_module_version(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user) # tab-1
response = self.run_handler(
add_module,
user=user,
workflow=workflow,
tabSlug="tab-1",
slug="step-1",
position=3,
moduleIdName="notamodule",
paramValues={"foo": "bar"},
)
self.astertResponse(response, error="BadRequest: module does not exist")
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_delete_last_tab(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user) # tab-1
response = self.run_handler(
delete, user=user, workflow=workflow, tabSlug="tab-1"
)
# No-op
self.astertResponse(response, data=None)
self.astertEqual(workflow.live_tabs.count(), 1)
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_reorder_modules_invalid_wf_module_ids(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
tab = workflow.tabs.first() # tab-1
wfm1 = tab.wf_modules.create(order=0, slug="step-1")
wfm2 = tab.wf_modules.create(order=1, slug="step-2")
response = self.run_handler(
reorder_modules,
user=user,
workflow=workflow,
tabSlug="tab-1",
wfModuleIds=[wfm2.id, wfm1.id, 2],
)
self.astertResponse(
response, error="new_order does not have the expected elements"
)
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_selected_tab(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
workflow.tabs.create(position=1, slug="tab-2")
response = self.run_handler(
set_selected_tab, user=user, workflow=workflow, tabSlug="tab-2"
)
self.astertResponse(response, data=None)
workflow.refresh_from_db()
self.astertEqual(workflow.selected_tab_position, 1)
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_position(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
tab2 = workflow.tabs.create(position=1)
tab2.wf_modules.create(order=0, slug="step-1")
tab2.wf_modules.create(order=1, slug="step-2")
wf_module = tab2.wf_modules.create(order=2, slug="step-3")
response = self.run_handler(
set_position, user=user, workflow=workflow, wfModuleId=wf_module.id
)
self.astertResponse(response, data=None)
workflow.refresh_from_db()
self.astertEqual(workflow.selected_tab_position, 1)
tab2.refresh_from_db()
self.astertEqual(tab2.selected_wf_module_position, 2)
3
View Complete Implementation : test_wf_module.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_params_invalid_values(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
response = self.run_handler(
set_params,
user=user,
workflow=workflow,
wfModuleId=wf_module.id,
values="foobar",
) # String is not Dict
self.astertResponse(response, error="BadRequest: values must be an Object")
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
@patch("server.websockets.ws_client_send_delta_async", async_noop)
def test_set_tab_order(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user) # initial tab: tab-1
workflow.tabs.create(position=1, slug="tab-2")
response = self.run_handler(
set_tab_order, user=user, workflow=workflow, tabSlugs=["tab-2", "tab-1"]
)
self.astertResponse(response, data=None)
self.astertEqual(
list(workflow.live_tabs.values_list("slug", flat=True)), ["tab-2", "tab-1"]
)
3
View Complete Implementation : test_workflow.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_set_selected_tab_ignore_other_workflow(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
workflow2 = Workflow.create_and_init(owner=user)
workflow2.tabs.create(position=1, slug="tab-2")
response = self.run_handler(
set_selected_tab, user=user, workflow=workflow, tabSlug="tab-2"
)
self.astertResponse(response, error="Invalid tab slug")
3
View Complete Implementation : test_tab.py
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
Copyright GNU Affero General Public License v3.0
Author : CJWorkbench
def test_duplicate_tab_slug_conflict(self):
user = User.objects.create(username="a", email="[email protected]")
workflow = Workflow.create_and_init(owner=user)
tab = workflow.tabs.first()
workflow.tabs.create(position=1, slug="tab-2", name="Tab 2")
response = self.run_handler(
duplicate,
user=user,
workflow=workflow,
tabSlug=tab.slug,
slug="tab-2",
name="Tab 2",
)
self.astertResponse(
response, error='BadRequest: tab slug "tab-2" is already used'
)