示例#1
0
    def test_person_name_can_be_in_non_latic_characters(self):
        '''
        Tests that a users name can be written in non-latin characters
        '''

        #Traditional Chinese
        person = Person(name='實驗',
                        gender='M',
                        email='*****@*****.**',
                        family_id=self.family.id)
        person.save()

        #Simplified Chinese
        person = Person(name='实验',
                        gender='M',
                        email='*****@*****.**',
                        family_id=self.family.id)
        person.save()

        #Polish
        person = Person(name='kiełbasa',
                        gender='M',
                        email='*****@*****.**',
                        family_id=self.family.id)
        person.save()
示例#2
0
    def setUp(self):

        self.family = Family()
        self.family.save()

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******',
                                             name='Phil Collins',
                                             family=self.family)

        self.person = Person(name='Phil Collins',
                             gender='M',
                             email='*****@*****.**',
                             family_id=self.family.id,
                             language='en',
                             user_id=self.user.id)
        self.person.save()

        self.gallery = Gallery.objects.create(title="test_gallery",
                                              family_id=self.family.id)

        self.gallery2 = Gallery.objects.create(title="test_gallery2",
                                               family_id=self.family.id)

        self.family2 = Family()
        self.family2.save()

        self.user2 = User.objects.create_user(
            email='*****@*****.**',
            password='******',
            name='Phillip Bailey',
            family=self.family2)

        self.person2 = Person(name='Phillip Bailey',
                              gender='M',
                              email='*****@*****.**',
                              family_id=self.family2.id,
                              language='en',
                              user_id=self.user2.id)
        self.person2.save()

        self.test_image = os.path.join(settings.BASE_DIR,
                                       'gallery/tests/test_image.jpg')
        self.test_image_destination = ''.join([
            settings.MEDIA_ROOT, 'galleries/',
            str(self.family.id), '/',
            str(self.gallery.id), '/test_image.jpg'
        ])

        directory = ''.join([
            settings.MEDIA_ROOT, 'galleries/',
            str(self.family.id), '/',
            str(self.gallery.id)
        ])
        if not os.path.exists(directory):
            os.makedirs(directory)

        #Copy test image to media area
        shutil.copy2(self.test_image, self.test_image_destination)
示例#3
0
    def setUp(self):

        self.family = Family()
        self.family.save()

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******',
                                             name='Matt Tong',
                                             family=self.family)

        self.person = Person(name='Matt Tong',
                             gender='M',
                             email='*****@*****.**',
                             family_id=self.family.id,
                             language='en',
                             user_id=self.user.id)
        self.person.save()

        self.new_person = Person(name='Taka Hirose',
                                 gender='M',
                                 email='*****@*****.**',
                                 family_id=self.family.id,
                                 language='en')

        self.new_person.save()

        self.family2 = Family()
        self.family2.save()

        self.user2 = User.objects.create_user(email='*****@*****.**',
                                              password='******',
                                              name='Herman Li',
                                              family=self.family2)

        self.person2 = Person(name='Herman Li',
                              gender='M',
                              email='*****@*****.**',
                              family_id=self.family2.id,
                              language='en',
                              user_id=self.user2.id)
        self.person2.save()

        super(InviteEmailApiTestCase, self).setUp()

        self.invite = EmailConfirmation(
            email_address='*****@*****.**',
            person_id=self.person.id,
            user_who_invited_person_id=self.user.id,
            sent=timezone.now())

        self.invite.save()
示例#4
0
    def test_partnered_other_to_female_resolves_to_female_to_other(self):
        '''
        Tests when an other gender partners a female, it resolves to females partners an other gender
        '''
        other = Person(name="other", gender="O", family_id=self.family.id)
        other.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = other.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)
        self.assertEqual(other.id, relation.to_person_id)
示例#5
0
    def test_rotate_photo(self):
        '''
        Tests that the function correctly rotates a photo
        '''
        from django.conf import settings

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'),
            settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')

        person = Person(name='譚詠麟', gender='M', family_id=self.family.id)
        person.photo = 'profile_photos/large_test_image.jpg'

        person.rotate_photo(90)

        #Check rotated photo is valid
        rotated_photo = Image.open(settings.MEDIA_ROOT + str(person.photo))
        rotated_photo.verify()

        #Clear up mess afterwards
        os.remove(settings.MEDIA_ROOT + str(person.photo))
示例#6
0
    def test_set_hires_photo(self):
        '''
        Tests that the function correctly sets sets the photo field on a person and converts an image.
        '''
        from django.conf import settings

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'),
            settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')

        person = Person(name='陳港生', gender='M', family_id=self.family.id)
        person.set_hires_photo('large_test_image.jpg')

        self.assertEqual('profile_photos/large_test_image.jpg', person.photo)

        #Check this image is valid
        image = Image.open(settings.MEDIA_ROOT +
                           'profile_photos/large_test_image.jpg')
        image.verify()
        width, height = image.size

        self.assertEqual(500, width)
        self.assertEqual(343, height)  #maintains aspect ratio

        self.assertEqual('profile_photos/large_test_image.jpg', person.photo)

        #Clear up mess afterwards
        os.remove(settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')
示例#7
0
    def test_partnered_male_to_female_resolves_to_female_to_male(self):
        '''
        Tests when a male partners a female, it resolves to females partners a male
        '''
        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = male.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
示例#8
0
    def test_hierachy_score_set_for_adding_child_with_relation_as_param(self):
        '''
        Ensure that hierachy score is set when adding the child of a parent
        the relation is passed to the function
        '''

        parent = Person(name='parent', gender='M', hierarchy_score = 100, family_id=self.family.id)
        parent.save()

        child = Person(name='child', gender='M', family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = parent.id, to_person_id = child.id, relation_type = RAISED)

        child.set_hierarchy_score(relation)
        self.assertEqual(101, child.hierarchy_score)
示例#9
0
    def test_crop_and_resize_photo(self):
        '''
        Tests that the function correctly sets two thumbnails of correct size
        '''
        from django.conf import settings

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(os.path.join(settings.BASE_DIR, 'family_tree/tests/large_test_image.jpg'), settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')

        person = Person(name='譚詠麟', gender='M', family_id=self.family.id)
        person.photo = 'profile_photos/large_test_image.jpg'

        person.crop_and_resize_photo(50, 50, 20, 20)

        #Check small thumbnail is valid
        small = Image.open(settings.MEDIA_ROOT + str(person.small_thumbnail))
        small.verify()
        width, height = small.size

        self.assertEqual(80, width)
        self.assertEqual(80, height)

        #Check large thumbnail is valid
        large = Image.open(settings.MEDIA_ROOT + str(person.large_thumbnail))
        large.verify()
        width, height = large.size

        self.assertEqual(200, width)
        self.assertEqual(200, height)


        #Clear up mess afterwards
        os.remove(settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg')
示例#10
0
    def test_update_user_when_email_changed(self):
        '''
        Tests that a user is updated when a person's email is modified
        '''

        user = User.objects.create(email='*****@*****.**',
                                   password='******',
                                   name='John Wong')
        person = Person(name='John Wong',
                        gender='M',
                        email='*****@*****.**',
                        family_id=self.family.id,
                        language='pl',
                        user_id=user.id)
        person.save()

        person.email = '*****@*****.**'
        person.create_update_user()

        self.assertEqual(
            1,
            User.objects.filter(email='*****@*****.**').count())
        self.assertEqual(
            0,
            User.objects.filter(email='*****@*****.**').count())
        self.assertEqual(
            person.user_id,
            User.objects.get(email='*****@*****.**').id)
        self.assertEqual(
            person.family_id,
            User.objects.get(email='*****@*****.**').family_id)
        self.assertEqual(
            'pl',
            User.objects.get(email='*****@*****.**').language)
示例#11
0
    def test_hierachy_score_set_for_adding_partner(self):
        '''
        Ensure that hierachy score is set when adding a partner
        '''

        husband = Person(name='husband', gender='M', family_id=self.family.id)
        husband.save()

        wife = Person(name='wife', gender='F', hierarchy_score = 75, family_id=self.family.id)
        wife.save()

        relation = Relation(from_person_id = husband.id, to_person_id = wife.id, relation_type = PARTNERED)
        relation.save()

        husband.set_hierarchy_score()

        self.assertEqual(75, husband.hierarchy_score)
示例#12
0
    def test_partnered_female_to_male_stays_the_same(self):
        '''
        Tests when a female partners a male, the relationship does not change
        '''

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        relation = Relation(from_person_id = female.id, to_person_id = male.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
示例#13
0
    def test_raised_by_relation_resolves_to_raised(self):
        '''
        Tests when a relation that a child is raised by parent, it resolves to parent raised child
        '''
        parent = Person(name="parent", gender="F", family_id=self.family.id)
        parent.save()

        child = Person(name="child", gender="O", family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = child.id, to_person_id = parent.id, relation_type = RAISED_BY)
        relation.normalise()


        self.assertEqual(RAISED, relation.relation_type)
        self.assertEqual(parent.id, relation.from_person_id)
        self.assertEqual(child.id, relation.to_person_id)
示例#14
0
    def test_create_inverted_relation(self):
        '''
        Tests an inverted relationship is correctly created when using manager function
        '''
        from_person = Person(name="from_person", gender="F", family_id=self.family.id)
        from_person.save()

        to_person = Person(name="to_person", gender="F", family_id=self.family.id)
        to_person.save()

        relation = Relation(from_person_id = from_person.id, to_person_id = to_person.id, relation_type = RAISED)

        inverted = Relation.objects._create_inverted_relation(relation)

        self.assertEqual(from_person.id, inverted.to_person_id)
        self.assertEqual(to_person.id, inverted.from_person_id)
        self.assertEqual(RAISED_BY, inverted.relation_type)
示例#15
0
    def test_existing_relations_get_replaced(self):
        '''
        Tests that when a relations is added between two people, it replaces any existing relations between them
        '''
        existing1 = Person(name="existing1", gender="F", family_id=self.family.id)
        existing1.save()

        existing2 = Person(name="existing2", gender="F", family_id=self.family.id)
        existing2.save()

        relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = RAISED)
        relation.save()

        new_relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = PARTNERED)
        new_relation.save()

        self.assertEqual(1, Relation.objects.filter(from_person_id = existing1.id, to_person_id = existing2.id).count())
        self.assertEqual(PARTNERED, Relation.objects.get(from_person_id = existing1.id, to_person_id = existing2.id).relation_type)
示例#16
0
    def test_hierachy_score_set_for_adding_parent(self):
        '''
        Ensure that hierachy score is set when adding the parent of a child
        the relation is not passed to the function
        '''

        parent = Person(name='parent', gender='M', family_id=self.family.id)
        parent.save()

        child = Person(name='child', gender='M', hierarchy_score = 100, family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = parent.id, to_person_id = child.id, relation_type = RAISED)
        relation.save()

        parent.set_hierarchy_score()

        self.assertEqual(99, parent.hierarchy_score)
示例#17
0
    def test_set_profile_image_crop_rotate_resize_replaces_existing(self):
        '''
        Tests that the function correctly sets sets the photo field on a person and converts an image.
        '''
        from django.conf import settings

        path = settings.MEDIA_ROOT + 'profile_photos/large_test_image1.jpg'
        path2 = settings.MEDIA_ROOT + 'profile_photos/large_test_image2.jpg'

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'), path)
        person = Person(name='陳港生', gender='M', family_id=self.family.id)
        person.set_profile_image_crop_rotate_resize(path, 10, 20, 200, 200, 90)

        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'), path2)
        person = Person(name='陳港生', gender='M', family_id=self.family.id)
        person.set_profile_image_crop_rotate_resize(path2, 10, 20, 200, 200,
                                                    90)
示例#18
0
    def test_account_locks_out_on_multiple_invalid_login_attempts(self):

        self.signal_was_called = False

        def handler(sender, **kwargs):
            self.signal_was_called = True

        user_locked_out.connect(handler)

        user = User.objects.create_user(email='*****@*****.**',
                                password='******',
                                name='Adele Goldberg',
                                family_id = self.family.id)

        person = Person(name='Adele Goldberg',
                        gender='F',
                        email='*****@*****.**',
                        family_id=self.family.id,
                        language='en',
                        user_id=user.id)
        person.save()

        # 127.0.0.1 is whitelisted
        client = APIClient(HTTP_X_REAL_IP='127.0.0.2')

        wrong_auth_details = {
            'email': '*****@*****.**',
            'password': '******'
        }

        for x in range(0, 6):
            client.post('/api/auth/obtain_token/', wrong_auth_details, format='json')

        correct_auth_details = {
            'email': '*****@*****.**',
            'password': '******'
        }

        final_response = client.post('/api/auth/obtain_token/', correct_auth_details, format='json')

        self.assertNotEqual(final_response.status_code, status.HTTP_200_OK)
        self.assertTrue(self.signal_was_called)

        # Check ip locked
        locked_response = client.get('/api/auth/is_locked/', format='json')
        self.assertEqual(b'true', locked_response.content)

        user_locked_out.disconnect(handler)
示例#19
0
    def test_biography_can_be_written_in_non_latic_characters(self):
        """
        Tests that a biography name can be written in non-latin characters
        """

        #Traditional Chinese
        person = Person(name='nonlatin', gender='M', email='*****@*****.**', family_id=self.family.id, biography='傳記')
        person.save()

        #Simplified Chinese
        person.biography = '传记'
        person.save()

        #Polish
        person.biography = 'zabójstwo'
        person.save()
    def test_set_profile_image_crop_rotate_resize(self):
        '''
        Tests that the function correctly sets sets the photo field on a person and converts an image.
        '''
        from django.conf import settings

        path = settings.MEDIA_ROOT + 'profile_photos/large_test_image.jpg'

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'), path)
        person = Person(name='陳港生', gender='M', family_id=self.family.id)
        person.save()
        person.set_profile_image_crop_rotate_resize(path,
                                                    10,
                                                    20,
                                                    200,
                                                    200,
                                                    90,
                                                    test=True)

        #Check small image is valid
        small_image = Image.open(settings.MEDIA_ROOT +
                                 str(person.small_thumbnail))
        small_image.verify()
        width, height = small_image.size

        self.assertEqual(80, width)
        self.assertEqual(80, height)

        #Check large image is valid
        large_thumbnail = Image.open(settings.MEDIA_ROOT +
                                     str(person.large_thumbnail))
        large_thumbnail.verify()
        width, height = large_thumbnail.size

        self.assertEqual(200, width)
        self.assertEqual(200, height)

        #Clear up mess afterwards
        if os.path.exists(path):
            os.remove(path)
        person.remove_local_images()
        person.remove_remote_images()
示例#21
0
    def setUp(self):

        self.family = Family()
        self.family.save()

        self.user = User.objects.create_user(email='*****@*****.**',
                                        password='******',
                                        name='Grace Hopper',
                                        family_id = self.family.id)

        self.person = Person(name='Grace Hopper',
                        gender='F',
                        email='*****@*****.**',
                        family_id=self.family.id,
                        language='en',
                        user_id=self.user.id)
        self.person.save()
示例#22
0
    def test_invalid_login_followed_by_valid_logon(self):
        user = User.objects.create_user(email='*****@*****.**',
                                        password='******',
                                        name='Margaret Hamilton',
                                        family_id=self.family.id)

        person = Person(name='Margaret Hamilton',
                        gender='F',
                        email='*****@*****.**',
                        family_id=self.family.id,
                        language='en',
                        user_id=user.id)
        person.save()

        # 127.0.0.1 is whitelisted
        client = APIClient(HTTP_X_REAL_IP='127.0.0.2')

        wrong_auth_details = {
            'email': '*****@*****.**',
            'password': '******'
        }

        response = client.post('/api/auth/obtain_token/',
                               wrong_auth_details,
                               format='json')
        self.assertNotEqual(response.status_code, status.HTTP_200_OK)

        # Check ip is not locked
        locked_response = client.get('/api/auth/is_locked/', format='json')
        self.assertEqual(b'false', locked_response.content)

        correct_auth_details = {
            'email': '*****@*****.**',
            'password': '******'
        }

        response = client.post('/api/auth/obtain_token/',
                               correct_auth_details,
                               format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check ip is not locked
        locked_response = client.get('/api/auth/is_locked/', format='json')
        self.assertEqual(b'false', locked_response.content)
    def test_set_profile_image_crop_rotate_resize_replaces_existing(self):
        '''
        Tests that the function correctly sets sets the photo field on a person and converts an image.
        '''
        from django.conf import settings

        path = settings.MEDIA_ROOT + 'profile_photos/large_test_image1.jpg'
        path2 = settings.MEDIA_ROOT + 'profile_photos/large_test_image2.jpg'

        #Copy test image to media area
        import shutil
        import os
        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'), path)
        person = Person(name='陳港生', gender='M', family_id=self.family.id)
        person.set_profile_image_crop_rotate_resize(path, 10, 20, 200, 200, 90)
        person.save()
        photo = settings.MEDIA_URL + str(person.photo)

        shutil.copy2(
            os.path.join(settings.BASE_DIR,
                         'family_tree/tests/large_test_image.jpg'), path2)
        person.set_profile_image_crop_rotate_resize(path2, 10, 20, 200, 200,
                                                    90)
        person.save()

        # Check original photo has been removed
        request = requests.get(photo)
        self.assertNotEqual(200, request.status_code)

        if os.path.exists(path):
            os.remove(path)
        if os.path.exists(path2):
            os.remove(path2)

        #Clear up mess afterwards
        person.remove_local_images()
        person.remove_remote_images()
示例#24
0
    def setUp(self):
        self.family = Family()
        self.family.save()

        self.family2 = Family()
        self.family2.save()

        self.user = User.objects.create_user(email='*****@*****.**',
                                             password='******',
                                             name='Edith Clarke',
                                             family=self.family)

        self.person1 = Person(name='Edith Clarke',
                              gender='F',
                              email='*****@*****.**',
                              family_id=self.family.id,
                              language='en',
                              user_id=self.user.id)
        self.person1.save()

        self.person2 = Person(name='someone else',
                              gender='O',
                              email='*****@*****.**',
                              family_id=self.family.id,
                              language='en',
                              user_id=self.user.id)
        self.person2.save()

        self.person3 = Person(name='another person',
                              gender='O',
                              email='*****@*****.**',
                              family_id=self.family.id,
                              language='en',
                              user_id=self.user.id)
        self.person3.save()

        self.relation1 = Relation.objects.create(from_person=self.person1,
                                                 to_person=self.person2,
                                                 relation_type=PARTNERED)
        self.relation1.save()

        self.relation2 = Relation.objects.create(from_person=self.person1,
                                                 to_person=self.person3,
                                                 relation_type=RAISED)
        self.relation2.save()

        self.otherFamilyUser = User.objects.create_user(
            email='*****@*****.**',
            password='******',
            name='Another Family',
            family=self.family2)

        self.otherFamilyPerson = Person(name='another family',
                                        gender='O',
                                        email='*****@*****.**',
                                        family_id=self.family2.id,
                                        language='en',
                                        user_id=self.user.id)
        self.otherFamilyPerson.save()

        self.otherFamilyPerson2 = Person(name='another family 2',
                                         gender='O',
                                         email='*****@*****.**',
                                         family_id=self.family2.id,
                                         language='en',
                                         user_id=self.user.id)
        self.otherFamilyPerson2.save()

        self.relation3 = Relation.objects.create(
            from_person=self.otherFamilyPerson,
            to_person=self.otherFamilyPerson2,
            relation_type=PARTNERED)
        self.relation3.save()

        super(RelationApiTestCase, self).setUp()