def test_validDataPassedfromOrg_formIsValid(self, mock_get, mock_post, mock_add_message): form_data = { 'short_code': 'col', 'name': 'col', 'full_name': 'collection', 'collection_type': 'Dictionary', 'public_access': 'Edit', 'default_locale': 'en', 'supported_locales': 'en' } form = CollectionCreateForm(data=form_data) form.full_clean() colResponse = FakeResponse() colResponse.status_code = 201 mock_post.return_value = colResponse collectionCreateView = views.CollectionCreateView() collectionCreateView.request = FakeRequest() collectionCreateView.kwargs = { 'org': 'testOrgId', } abc = collectionCreateView.form_valid(form) mock_add_message.assert_called_once_with(collectionCreateView.request, messages.INFO, ('Collection created'))
def test_getInitialViewOfUserCol_initialViewWithDataSet(self): collectionCreateView = views.CollectionCreateView() collectionCreateView.request = FakeRequest() collectionCreateView.kwargs = { 'user': '******', } data = collectionCreateView.get_initial(); self.assertIsNone(data['org_id'], "for user col , org should be none") self.assertEquals(data['user_id'], 'testUserId') self.assertFalse(data['from_org']) self.assertTrue(data['from_user']) self.assertEquals(data['request'], collectionCreateView.request)
def test_getContextForOrgUser_contextForUserReceived(self, mock_get): colResponse = MagicMock(spec=Response) colResponse.json.return_value = "testUser" mock_get.return_value = colResponse collectionCreateView = views.CollectionCreateView() collectionCreateView.request = FakeRequest() collectionCreateView.kwargs = { 'user': '******', } context = collectionCreateView.get_context_data(); self.assertIsNone(context['org']) self.assertEquals(context['ocl_user'], "testUser") self.assertTrue(context['from_user']) self.assertFalse(context['from_org'])