def setUp(self): super(LexicalEntriesTest, self).setUp() self.id_tester = self.signup_common() self.id_u1 = self.signup_common('user1') self.id_u2 = self.signup_common('user2') self.id_l1 = self.create_language('language1') self.dict_1 = self.create_dictionary('user1_dict1', self.id_l1) self.persp_1 = self.create_perspective('translation_string1', self.dict_1, "Published", False) self.persp_2 = self.create_perspective('translation_string2', self.dict_1, "Published", False) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/fields' % (1, 6, 1, 7)) # 1 1 1 1 with old fields = response.json response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/fields' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_1['client_id'], self.persp_1['object_id']), params=fields) response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/fields' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_2['client_id'], self.persp_2['object_id']), params=fields) self.strings = ["uyzrljiirs", "kxmzpclrns", "kgrrdjafqz", "jdavwdmuqe", "zlswwsfjrc", "bkrmwpshnh", "cpnltteyzj", "iyornljisb", "ozidqyatiz", "hxjzmtthxp", "jlsodufkah", "wiymxkmzhs", "hjwsojizle", "ylbrqdpzzp", "zeomhyqhwl", "ficbqfhrzv", "upmedjsbli", "ylbrqdpzzp", "dgjomjdnhy", "wajysnmtvb"] params = initValuesFactory.get_role_params([self.id_u1, self.id_u2]) response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_1['client_id'], self.persp_1['object_id']), params=params) response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_2['client_id'], self.persp_2['object_id']), params=params)
def testPerspectiveInfo(self): correct_answers = load_correct_answers("perspective/answers_perspective_info.json") id_tester = self.signup_common() id_u1 = self.signup_common('user1', 'user1') id_u2 = self.signup_common('user2', 'user1') id_l1 = self.create_language('language1') dict_1 = self.create_dictionary('user1_dict1', id_l1) persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/fields' % (1, 6, 1, 7)) # 1 1 1 1 with old fields = response.json response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/fields' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=fields) test_name = "empty_perspective" response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/info' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) self.assertEqual(response.json, correct_answers[test_name]) params = initValuesFactory.get_role_params([id_u1, id_u2]) response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/lexical_entries' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params={'count': 3}) to_be_approved = list() to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'text1', 'Word')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'text2', 'Word')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'translation1', 'Translation')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[1], 'translation2', 'Translation')) self.login_common(username='******') # We don't want to approve this entity self.add_l1e(dict_1, persp_1, response.json[1], 'text3', 'Word') to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[1], 'translation3', 'Translation')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[2], 'transcription1', 'Transcription')) for x in to_be_approved: x.update({"type": 'leveloneentity'}) response = self.app.patch_json( '/dictionary/%s/%s/perspective/%s/%s/approve' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params={"entities": to_be_approved} ) test_name = "filled_perspective" response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/info' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) self.assertEqual(response.json, correct_answers[test_name])
def setUp(self): super(LexicalEntriesTest, self).setUp() self.id_tester = self.signup_common() self.id_u1 = self.signup_common('user1') self.id_u2 = self.signup_common('user2') self.id_l1 = self.create_language('language1') self.dict_1 = self.create_dictionary('user1_dict1', self.id_l1) self.persp_1 = self.create_perspective('translation_string1', self.dict_1, "Published", False) self.persp_2 = self.create_perspective('translation_string2', self.dict_1, "Published", False) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/fields' % (1, 6, 1, 7)) # 1 1 1 1 with old fields = response.json response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/fields' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_1['client_id'], self.persp_1['object_id']), params=fields) response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/fields' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_2['client_id'], self.persp_2['object_id']), params=fields) self.strings = [ "uyzrljiirs", "kxmzpclrns", "kgrrdjafqz", "jdavwdmuqe", "zlswwsfjrc", "bkrmwpshnh", "cpnltteyzj", "iyornljisb", "ozidqyatiz", "hxjzmtthxp", "jlsodufkah", "wiymxkmzhs", "hjwsojizle", "ylbrqdpzzp", "zeomhyqhwl", "ficbqfhrzv", "upmedjsbli", "ylbrqdpzzp", "dgjomjdnhy", "wajysnmtvb" ] params = initValuesFactory.get_role_params([self.id_u1, self.id_u2]) response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_1['client_id'], self.persp_1['object_id']), params=params) response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (self.dict_1['client_id'], self.dict_1['object_id'], self.persp_2['client_id'], self.persp_2['object_id']), params=params)
def testDictionaryInfo(self): correct_answers = load_correct_answers("dictionary/answers_dictionary_info.json") self.login_common('user1') dict_1 = self.create_dictionary('user1_dict1', self.id_l1) persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False) persp_2 = self.create_perspective('translation_string2', dict_1, "Published", False) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/fields' % (1, 6, 1, 7)) # 1 1 1 1 with old fields = response.json response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/fields' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=fields) test_name = "empty_dict" response = self.app.get('/dictionary/%s/%s/info' % (dict_1['client_id'], dict_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) self.assertEqual(response.json, correct_answers[test_name]) dictionary_roles = initValuesFactory.get_role_params() for k in dictionary_roles["roles_users"]: dictionary_roles["roles_users"][k] += [self.id_u1, self.id_u2] response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=dictionary_roles) response = self.app.get('/dictionary/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'])) to_be_approved = list() response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/lexical_entries' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params={'count': 3}) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'translation1', 'Translation')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[1], 'translation2', 'Translation')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'text1', 'Word')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[0], 'text2', 'Word')) self.login_common(username='******') # We don't want to approve this entity self.add_l1e(dict_1, persp_1, response.json[1], 'text3', 'Word') to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[1], 'translation3', 'Translation')) to_be_approved.append(self.add_l1e(dict_1, persp_1, response.json[2], 'transcription1', 'Transcription')) self.login_common(username='******') response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/lexical_entries' % (dict_1['client_id'], dict_1['object_id'], persp_2['client_id'], persp_2['object_id']), params={'count': 2}) self.add_l1e(dict_1, persp_2, response.json[0], 'text1', 'Word') to_be_approved.append(self.add_l1e(dict_1, persp_2, response.json[1], 'translation1', 'Translation')) list(map(lambda x: x.update({"type": 'leveloneentity'}), to_be_approved)) response = self.app.patch_json( '/dictionary/%s/%s/perspective/%s/%s/approve' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params={"entities": to_be_approved} ) test_name = "filled_dict" response = self.app.get('/dictionary/%s/%s/info' % (dict_1['client_id'], dict_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) self.assertEqual(response.json, correct_answers[test_name])
def testViewPerspectiveRoles(self): correct_answers = load_correct_answers( "perspective/answers_view_perspective_roles.json") id_tester = self.signup_common() id_u1 = self.signup_common('user1', 'user1') id_u2 = self.signup_common('user2', 'user1') id_u3 = self.signup_common('user3', 'user1') id_l1 = self.create_language('language1') dict_1 = self.create_dictionary('user1_dict1', id_l1) persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False) params = initValuesFactory.get_role_params([id_u2]) params['roles_users']['Can create lexical entries'] = [] params['roles_users']['Can get perspective role list'] = [id_u1] params['roles_users']['Can approve lexical entries and publish'] = [ id_u3 ] params['roles_users'][ 'Can create perspective roles and assign collaborators'] = [ id_u2, id_u3 ] # Testing get and post test_name = "change_several_roles" response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = { 'roles_users': { "Can view unpublished lexical entries": [id_u3] } } test_name = "add_single_role" response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {}} test_name = "empty_test_1" response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {} test_name = "empty_test_2" response = self.app.post_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) # Testing get and delete params = { 'roles_users': { "Can view unpublished lexical entries": [id_u3] } } test_name = "delete_one_user" response = self.app.delete_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = { 'roles_users': { "Can resign users from perspective editors": [id_u3] } } test_name = "delete_missing_user" response = self.app.delete_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = { 'roles_users': { "Can create perspective roles and assign collaborators": [id_u2, id_u3] } } test_name = "delete_several_users" response = self.app.delete_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {}} test_name = "empty_delete_test_1" response = self.app.delete_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {} test_name = "empty_delete_test_2" response = self.app.delete_json( '/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name])
def testViewPerspectiveRoles(self): correct_answers = load_correct_answers("perspective/answers_view_perspective_roles.json") id_tester = self.signup_common() id_u1 = self.signup_common('user1', 'user1') id_u2 = self.signup_common('user2', 'user1') id_u3 = self.signup_common('user3', 'user1') id_l1 = self.create_language('language1') dict_1 = self.create_dictionary('user1_dict1', id_l1) persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False) params = initValuesFactory.get_role_params([id_u2]) params['roles_users']['Can create lexical entries'] = [] params['roles_users']['Can get perspective role list'] = [id_u1] params['roles_users']['Can approve lexical entries and publish'] = [id_u3] params['roles_users']['Can create perspective roles and assign collaborators'] = [id_u2, id_u3] # Testing get and post test_name = "change_several_roles" response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {"Can view unpublished lexical entries": [id_u3]}} test_name = "add_single_role" response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {}} test_name = "empty_test_1" response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {} test_name = "empty_test_2" response = self.app.post_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) # Testing get and delete params = {'roles_users': {"Can view unpublished lexical entries": [id_u3]}} test_name = "delete_one_user" response = self.app.delete_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {"Can resign users from perspective editors": [id_u3]}} test_name = "delete_missing_user" response = self.app.delete_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {"Can create perspective roles and assign collaborators": [id_u2, id_u3]}} test_name = "delete_several_users" response = self.app.delete_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {'roles_users': {}} test_name = "empty_delete_test_1" response = self.app.delete_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name]) params = {} test_name = "empty_delete_test_2" response = self.app.delete_json('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id']), params=params) response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/roles' % (dict_1['client_id'], dict_1['object_id'], persp_1['client_id'], persp_1['object_id'])) self.assertEqual(response.status_int, HTTPOk.code) # print(test_name, response.json) self.assertEqual(response.json, correct_answers[test_name])