def testWorkflowListView(self): # Anonymous users can't get workflow list response = self.client.get('/ws/workflows.json') self.assertEqual(response.status_code, 302) self.client.login(username='******', password='******') response = self.client.get('/ws/workflows.json') json_response = json.loads(response.content) self.assertEqual(json_response['success'], True) self.assertEqual(json_response['total'], 2) wf = Workflow(name='Guess the number') wf.save() response = self.client.get('/ws/workflows.json') json_response = json.loads(response.content) self.assertEqual(json_response['success'], True) self.assertEqual(json_response['total'], 3) self.assertEqual(len(json_response['rows']), json_response['total']) workflow_names = [a['name'] for a in json_response['rows']] self.assertIn('Two plus two', workflow_names) self.assertIn('computer trivial', workflow_names) self.assertIn('Guess the number', workflow_names)
def testModelChoiceField(self): from ws.models import Workflow wf1 = Workflow(name='wf1') wf1.save() wf2 = Workflow(name='wf2') wf2.save() wf3 = Workflow(name='wf3') wf3.save() field = forms.ModelChoiceField(queryset=Workflow.objects.all(), empty_label=None) ext_dict = field.to_ext_dict('field') self.assertIn('defaultType', ext_dict) self.assertIn('items', ext_dict) self.assertEqual(ext_dict['xtype'], 'fieldcontainer') self.assertEqual(len(ext_dict['items']), 3) item1 = ext_dict['items'][0] self.assertIn('boxLabel', item1) self.assertIn('name', item1) self.assertIn('inputValue', item1) self.assertEqual(item1['boxLabel'], 'wf1') self.assertEqual(item1['name'], 'field') self.assertEqual(item1['inputValue'], 1)