def setUp(self): super().setUp() self.workflow = Workflow.objects.create() self.loadurl = load_module_version('loadurl') self.wfm1 = self.workflow.wf_modules.create( module_version=self.loadurl, order=0)
def test_workflow_anonymous_user(self): # Looking at an example workflow as an anonymous user should create a new workflow num_workflows = Workflow.objects.count() self.other_workflow_public.example = True self.other_workflow_public.save() # Also ensure the anonymous users can't access the Python module; first we need to load it load_module_version('pythoncode') request = self._build_get('/api/workflows/%d/' % self.other_workflow_public.id, user=AnonymousUser()) response = render_workflow(request, pk=self.other_workflow_public.id) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(Workflow.objects.count(), num_workflows + 1) # should have duplicated the wf with this API call # Ensure the anonymous users can't access the Python module self.assertNotContains(response, '"pythoncode"')
def setUp(self): super(UpdatesTests, self).setUp() # log in self.workflow = add_new_workflow('Update scan') loadurl = load_module_version('loadurl') self.wfm1 = add_new_wf_module(self.workflow, loadurl, order=0) self.wfm2 = add_new_wf_module(self.workflow, loadurl, order=1) self.wfm3 = add_new_wf_module(self.workflow, loadurl, order=2) # fake out the current time so we can run the test just-so self.nowtime = parser.parse('Aug 28 1999 2:35PM UTC')
def test_update_scan(self, mock_queue_fetch): self.workflow = Workflow.objects.create() self.loadurl = load_module_version('loadurl') self.wfm1 = self.workflow.wf_modules.create( module_version=self.loadurl, order=0) self.wfm2 = self.workflow.wf_modules.create( module_version=self.loadurl, order=1) self.wfm3 = self.workflow.wf_modules.create( module_version=self.loadurl, order=2) mock_queue_fetch.return_value = future_none # This module does not auto update self.wfm1.auto_update_data = False self.wfm1.save() # This module ready to update self.wfm2.auto_update_data = True self.wfm2.last_update_check = parser.parse('Aug 28 1999 2:24PM UTC') due_for_update = parser.parse('Aug 28 1999 2:34PM UTC') self.wfm2.next_update = due_for_update self.wfm2.update_interval = 600 self.wfm2.save() # This module still has a few more minutes before it should update self.wfm3.auto_update_data = True self.wfm3.last_update_check = parser.parse('Aug 28 1999 2:20PM UTC') not_due_for_update = parser.parse('Aug 28 1999 2:40PM UTC') self.wfm3.next_update = not_due_for_update self.wfm3.update_interval = 1200 self.wfm3.save() # eat log messages with self.assertLogs(updates.__name__, logging.DEBUG): async_to_sync(updates.update_wfm_data_scan)(SuccessfulRenderLock) self.assertEqual(mock_queue_fetch.call_count, 1) mock_queue_fetch.assert_called_with(self.wfm2) self.wfm2.refresh_from_db() self.assertTrue(self.wfm2.is_busy) # Second call shouldn't fetch again, because it's busy with self.assertLogs(updates.__name__, logging.DEBUG): async_to_sync(updates.update_wfm_data_scan)(SuccessfulRenderLock) self.assertEqual(mock_queue_fetch.call_count, 1)
def setUp(self): # Define two types of modules we are going to use self.csv = load_module_version('pastecsv') self.workflow = add_new_workflow('My Undoable Workflow')