def testLexicalEntriesPublishedCount(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_lexical_entries_published_count.json")

        test_name = "test_empty"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published_count' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        to_be_approved = self._load_entities()
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved:
            x.update({"type": 'leveloneentity'})
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved})
        test_name = "test_full"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published_count' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
    def testLexicalEntriesPublishedCount(self):
        correct_answers = load_correct_answers("lexical_entries/answers_lexical_entries_published_count.json")

        test_name = "test_empty"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published_count' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        to_be_approved = self._load_entities()
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved: x.update({"type": 'leveloneentity'})
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved}
        )
        test_name = "test_full"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published_count' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
    def testApproveEntityAll(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_approve_entity_all.json")
        test_name = "approve_empty_persp"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve_all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_filled_persp"
        to_be_approved = self._load_entities(4)
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve_all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('correct:', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 4
0
    def testPerspectives(self):
        correct_answers = load_correct_answers(
            "perspective/answers_perspectives.json")
        id_tester = self.signup_common()
        id_u1 = self.signup_common('user1', 'user1')
        id_l1 = self.create_language('language1')
        dict_1 = self.create_dictionary('user1_dict1', id_l1)
        dict_2 = self.create_dictionary('user1_dict2', id_l1)
        unexisting_dict = {"object_id": 4, "client_id": 4}
        persp_1 = self.create_perspective('translation_string1', dict_1,
                                          "Published", False)
        persp_2 = self.create_perspective('translation_string1', dict_1,
                                          "Marked", True)

        test_name = "filled_perspective"
        response = self.app.get(
            '/dictionary/%(client_id)s/%(object_id)s/perspectives' % dict_1)
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "empty_perspective"
        response = self.app.get(
            '/dictionary/%(client_id)s/%(object_id)s/perspectives' % dict_2)
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
    def testLexicalEntriesAll(self):
        correct_answers = load_correct_answers("lexical_entries/answers_lexical_entries_all.json")

        test_name = "test_empty"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
        # check that the order is correct
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        self._load_entities()
        test_name = "test_full"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_0_count"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "0", "start_from": "0"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_from"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "20", "start_from": "18"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_over_size"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "2", "start_from": "30"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])
Esempio n. 6
0
    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 testLexicalEntriesAllCount(self):
        correct_answers = load_correct_answers("lexical_entries/answers_lexical_entries_all_count.json")

        test_name = "test_empty"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all_count' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        self._load_entities()
        test_name = "test_full"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/all_count' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
    def testLexicalEntriesAllCount(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_lexical_entries_all_count.json")

        test_name = "test_empty"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all_count' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        self._load_entities()
        test_name = "test_full"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all_count' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
    def testPerspectives(self):
        correct_answers = load_correct_answers("perspective/answers_perspectives.json")
        id_tester = self.signup_common()
        id_u1 = self.signup_common('user1', 'user1')
        id_l1 = self.create_language('language1')
        dict_1 = self.create_dictionary('user1_dict1', id_l1)
        dict_2 = self.create_dictionary('user1_dict2', id_l1)
        unexisting_dict = {"object_id": 4, "client_id": 4}
        persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False)
        persp_2 = self.create_perspective('translation_string1', dict_1, "Marked", True)

        test_name = "filled_perspective"
        response = self.app.get('/dictionary/%(client_id)s/%(object_id)s/perspectives' % dict_1)
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "empty_perspective"
        response = self.app.get('/dictionary/%(client_id)s/%(object_id)s/perspectives' % dict_2)
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
    def testApproveEntityAll(self):
        correct_answers = load_correct_answers("lexical_entries/answers_approve_entity_all.json")
        test_name = "approve_empty_persp"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve_all' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']))
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_filled_persp"
        to_be_approved = self._load_entities(4)
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve_all' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']))
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('correct:', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
    def testApproveEntity(self):
        correct_answers = load_correct_answers("lexical_entries/answers_approve_entity.json")
        to_be_approved = self._load_entities(4)
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved: x.update({"type": 'leveloneentity'})
        test_name = "approve_several"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved}
        )
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_none"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": []}
        )
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_missing"
        to_be_approved = [{'client_id': 11, 'object_id': 5, "type": 'leveloneentity'},
                          {'client_id': 13, 'object_id': 1, "type": 'leveloneentity'}]
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved}
        )
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "level_two_entities"
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved = [entities[0]]
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved.append(entities[1])
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved.extend(entities)

        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_2['client_id'], self.persp_2['object_id']),
            params={"entities": to_be_approved}
        )
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_2['client_id'], self.persp_2['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('correct:', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 12
0
    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 testLexicalEntriesPublished(self):
        correct_answers = load_correct_answers("lexical_entries/answers_lexical_entries_published.json")

        test_name = "test_empty"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_empty: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        # check that the order is correct
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        to_be_approved = self._load_entities()
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved: x.update({"type": 'leveloneentity'})
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' % (self.dict_1['client_id'], self.dict_1['object_id'],
                                                             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved}
        )

        test_name = "test_full"

        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_full: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_0_count"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "0", "start_from": "0"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_0_count: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_from"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "20", "start_from": "8"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_start_from: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_over_size"
        response = self.app.get('/dictionary/%s/%s/perspective/%s/%s/published' %
                                      (self.dict_1['client_id'], self.dict_1['object_id'],
                                       self.persp_1['client_id'], self.persp_1['object_id']),
                                      params={'sort_by': 'Word', "count": "2", "start_from": "30"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_start_over_size: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual([(i['client_id'], i['object_id']) for i in response.json['lexical_entries']],
                         [(i['client_id'], i['object_id']) for i in correct_answers[test_name]['lexical_entries']])
    def testAllPerspectives(self):
        correct_answers = load_correct_answers("perspective/answers_all_perspectives.json")

        id_tester = self.signup_common()
        id_u1 = self.signup_common('user1', 'user1')
        id_l1 = self.create_language('language1')
        dict_1 = self.create_dictionary('user1_dict1', id_l1)
        default_persp = [
            {"object_id": 1, "client_id": 1},
            {"object_id": 2, "client_id": 1},
            {"object_id": 3, "client_id": 1}
        ]

        test_name = "empty_perspective"
        response = self.app.get('/perspectives',
                                params = {'is_template': False})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        persp_1 = self.create_perspective('translation_string1', dict_1, "Published", False)
        persp_2 = self.create_perspective('translation_string2', dict_1, "Published", True)
        persp_3 = self.create_perspective('translation_string3', dict_1, "Marked", False)
        persp_4 = self.create_perspective('translation_string4', dict_1, "Marked", True)

        test_name = "template_true"
        response = self.app.get('/perspectives',
                                params = {'is_template': True})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "template_false"
        response = self.app.get('/perspectives',
                                params = {'is_template': False})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "combined_condition_1"
        response = self.app.get('/perspectives',
                                params = {'state': "Published"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "combined_condition_2"
        response = self.app.get('/perspectives',
                                params = {'state': "Marked", 'is_template': False})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "missing_state"
        response = self.app.get('/perspectives',
                                params = {'state': "NoState"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "all"
        response = self.app.get('/perspectives')
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 15
0
    def testLexicalEntriesPublished(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_lexical_entries_published.json")

        test_name = "test_empty"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_empty: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        # check that the order is correct
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        to_be_approved = self._load_entities()
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved:
            x.update({"type": 'leveloneentity'})
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved})

        test_name = "test_full"

        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_full: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_0_count"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "0",
                "start_from": "0"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_0_count: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_from"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "20",
                "start_from": "8"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_start_from: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_over_size"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "2",
                "start_from": "30"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('test_start_over_size: ', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])
Esempio n. 16
0
    def testLexicalEntriesAll(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_lexical_entries_all.json")

        test_name = "test_empty"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
        # check that the order is correct
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        self._load_entities()
        test_name = "test_full"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={'sort_by': 'Word'})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_0_count"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "0",
                "start_from": "0"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_from"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "20",
                "start_from": "18"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])

        test_name = "test_start_over_size"
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/all' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={
                'sort_by': 'Word',
                "count": "2",
                "start_from": "30"
            })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
        self.assertEqual(
            [(i['client_id'], i['object_id'])
             for i in response.json['lexical_entries']],
            [(i['client_id'], i['object_id'])
             for i in correct_answers[test_name]['lexical_entries']])
Esempio n. 17
0
    def testDictionaries(self):
        correct_answers = load_correct_answers("dictionary/answers_dictionaries.json")

        self.login_common('user1')
        dict_1 = self.create_dictionary('user1_dict1', self.id_l1)
        self.login_common('user2')
        dict_2 = self.create_dictionary('user2_dict1', self.id_l2)
        self.login_common('user3')
        dict_3 = self.create_dictionary('user3_dict1', self.id_l3)

        # Tests filtering by user
        test_name = "filter_by_user_1"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u1, self.id_u2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u3]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertDictEqual(response.json, correct_answers[test_name], set_like=True)

        test_name = "filter_by_user_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        # Tests filtering by languages
        test_name = "filter_by_language_1"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l1, self.id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_language_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l3]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_language_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_1"
        # Tests filtering by users and languages
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u2, self.id_u3],
                                                'languages': [self.id_l1, self.id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u3, self.id_u4],
                                                'languages': [self.id_l1,self. id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u1, self.id_u2, self.id_u3, self.id_u4],
                                                'languages': [self.id_l1, self.id_l2, self.id_l3, self.id_l4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_4"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [], 'languages': []})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 18
0
    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])
Esempio n. 19
0
    def testAllPerspectives(self):
        correct_answers = load_correct_answers(
            "perspective/answers_all_perspectives.json")

        id_tester = self.signup_common()
        id_u1 = self.signup_common('user1', 'user1')
        id_l1 = self.create_language('language1')
        dict_1 = self.create_dictionary('user1_dict1', id_l1)
        default_persp = [{
            "object_id": 1,
            "client_id": 1
        }, {
            "object_id": 2,
            "client_id": 1
        }, {
            "object_id": 3,
            "client_id": 1
        }]

        test_name = "empty_perspective"
        response = self.app.get('/perspectives', params={'is_template': False})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        persp_1 = self.create_perspective('translation_string1', dict_1,
                                          "Published", False)
        persp_2 = self.create_perspective('translation_string2', dict_1,
                                          "Published", True)
        persp_3 = self.create_perspective('translation_string3', dict_1,
                                          "Marked", False)
        persp_4 = self.create_perspective('translation_string4', dict_1,
                                          "Marked", True)

        test_name = "template_true"
        response = self.app.get('/perspectives', params={'is_template': True})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "template_false"
        response = self.app.get('/perspectives', params={'is_template': False})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "combined_condition_1"
        response = self.app.get('/perspectives', params={'state': "Published"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "combined_condition_2"
        response = self.app.get('/perspectives',
                                params={
                                    'state': "Marked",
                                    'is_template': False
                                })
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "missing_state"
        response = self.app.get('/perspectives', params={'state': "NoState"})
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "all"
        response = self.app.get('/perspectives')
        self.assertEqual(response.status_int, HTTPOk.code)
        # print(test_name, response.json)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 20
0
    def testApproveEntity(self):
        correct_answers = load_correct_answers(
            "lexical_entries/answers_approve_entity.json")
        to_be_approved = self._load_entities(4)
        # Leave half of the entities for approving
        to_be_approved = [i for i in to_be_approved[::2]]
        for x in to_be_approved:
            x.update({"type": 'leveloneentity'})
        test_name = "approve_several"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved})
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_none"
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": []})
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "approve_missing"
        to_be_approved = [{
            'client_id': 11,
            'object_id': 5,
            "type": 'leveloneentity'
        }, {
            'client_id': 13,
            'object_id': 1,
            "type": 'leveloneentity'
        }]
        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']),
            params={"entities": to_be_approved})
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_1['client_id'], self.persp_1['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "level_two_entities"
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved = [entities[0]]
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved.append(entities[1])
        entities = self._add_level_one_two_entities(self.dict_1, self.persp_2)
        to_be_approved.extend(entities)

        response = self.app.patch_json(
            '/dictionary/%s/%s/perspective/%s/%s/approve' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_2['client_id'], self.persp_2['object_id']),
            params={"entities": to_be_approved})
        response = self.app.get(
            '/dictionary/%s/%s/perspective/%s/%s/published' %
            (self.dict_1['client_id'], self.dict_1['object_id'],
             self.persp_2['client_id'], self.persp_2['object_id']))
        self.assertEqual(response.status_int, HTTPOk.code)
        # print('correct:', response.json)
        self.assertEqual(response.json, correct_answers[test_name])
Esempio n. 21
0
    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])
Esempio n. 22
0
    def testDictionaries(self):
        correct_answers = load_correct_answers("dictionary/answers_dictionaries.json")

        self.login_common('user1')
        dict_1 = self.create_dictionary('user1_dict1', self.id_l1)
        self.login_common('user2')
        dict_2 = self.create_dictionary('user2_dict1', self.id_l2)
        self.login_common('user3')
        dict_3 = self.create_dictionary('user3_dict1', self.id_l3)

        # Tests filtering by user
        test_name = "filter_by_user_1"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u1, self.id_u2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u3]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertDictEqual(response.json, correct_answers[test_name], set_like=True)

        test_name = "filter_by_user_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        # Tests filtering by languages
        test_name = "filter_by_language_1"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l1, self.id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_language_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l3]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_language_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'languages': [self.id_l4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_1"
        # Tests filtering by users and languages
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u2, self.id_u3],
                                                'languages': [self.id_l1, self.id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_2"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u3, self.id_u4],
                                                'languages': [self.id_l1,self. id_l2]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_3"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [self.id_u1, self.id_u2, self.id_u3, self.id_u4],
                                                'languages': [self.id_l1, self.id_l2, self.id_l3, self.id_l4]})
        self.assertEqual(response.status_int, HTTPOk.code)
        self.assertEqual(response.json, correct_answers[test_name])

        test_name = "filter_by_user_language_4"
        response = self.app.post_json('/dictionaries',
                                      params = {'user_created': [], 'languages': []})
        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])