Пример #1
0
    def test3_profile_interest_in_company(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should link an interest(Company)')

        self.user.profile.add_interest(self.company)
        interests = self.user.profile.get_interests()

        self.assertGreater(len(interests), 0, Colorizer.Red('No Company linked'))
def add_location_to_user(user):
    try:
        if user.profile.place:
            place = json.loads(user.profile.place)

            location = Location.create(
                lat=repr(place['lat']),
                lng=repr(place['long']),
                city=place['city'],
                state=place['state'] if 'state' in place else '',
                country=place['country'],
                country_short=place['country_short'],
                post_code=place['post_code'] if 'post_code' in place else '',
                city_alias=place['city'] + ',')
            user.profile.location = location
            user.profile.latlong = ','.join(
                [format(place['lat'], '.6f'),
                 format(place['long'], '.6f')])
            user.profile.save()

    except Exception as e:
        print(Colorizer.Red('###############################'))
        print(Colorizer.Red('[ERROR Add location error]'))
        print(Logger.error(e))
        print(Colorizer.Red('###############################'))
    else:
        print(Colorizer.Green('LOCATION OK: ' + user.email))
Пример #3
0
    def test8_delete_profile(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] deleting profile should delete related interest')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)
        self.user.profile.delete()

        self.assertEqual(len(Interest.objects.all()), 0, Colorizer.Red('Deleting profile does not remove related interest objects'))
Пример #4
0
    def test2_profile_interest_in_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should link an interest(Challenge)')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')

        self.user.profile.add_interest(challenge)
        interests = self.user.profile.get_interests()

        self.assertGreater(len(interests), 0, Colorizer.Red('No Challenge linked'))
def add_place_to_profile(profile):
    try:
        profile.sanitize_place(force=True)
    except Exception as e:
        print(Colorizer.Red('###############################'))
        print(Colorizer.Red('sanitize place error'))
        print(Colorizer.Red(e))
        print(Colorizer.Red('###############################'))
    else:
        print(Colorizer.Green('PLACE OK: ' + profile.user.email))
Пример #6
0
 def test1_create_project(self):
     print Colorizer.LightPurple('\n[TEST project] should create a project')
     project = Project(
         title='Prova project',
         picture='images/profile/default_user_icon.png',
         details='Prova description'
     )
     project.profile = self.user.profile
     project.save()
     self.assertTrue(Project.objects.get(title='Prova project'), Colorizer.Red('Create project Error'))
Пример #7
0
    def test5_get_interested_from_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return a list of profile interested in a challenge')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        profiles = challenge.interested()

        self.assertTrue(all(isinstance(x, Profile) for x in profiles), Colorizer.Red('Challenge related interest are not a porofile list'))
Пример #8
0
    def test2_get_alternate_city_names(self):
        print Colorizer.LightPurple('\n[TEST PROFILE LOCATION] assert should respond')

        latlng = self.user.profile.location.lat+','+self.user.profile.location.lng
        response = OpenDataConnector.get_city_alternate_name_by_latlng(latlng)

        self.assertIsNotNone(
            response,
            Colorizer.Red('City alternate names is not present on response')
        )
Пример #9
0
    def test7_delete_interest_from_profile(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should should delete interest(challenge) from profile')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        self.user.profile.delete_interest(Challenge, challenge.id)
        challenges = self.user.profile.get_interests(Challenge)

        self.assertEqual(len(challenges), 0, Colorizer.Red('User interest(challenge) is not deleted'))
Пример #10
0
    def test1_api_response(self):
        print Colorizer.LightPurple('\n[TEST PROFILE LOCATION] assert should respond correctly')

        latlng = self.user.profile.location.lat+','+self.user.profile.location.lng
        response = OpenDataConnector.get_by_latlng(latlng)

        self.assertLessEqual(
            response.status_code,
            202,
            Colorizer.Red('Update Response Error: \n code: %s \n Info : %s' % (response.status_code, response))
        )
Пример #11
0
    def test4_profile_filter_interest_challenge(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return only interests that are Challenges')

        Challenge.create('test challenge')
        challenge = Challenge.objects.get(title='test challenge')
        self.user.profile.add_interest(challenge)

        self.user.profile.add_interest(self.company)
        interests = self.user.profile.get_interests(Challenge)

        self.assertTrue(all(isinstance(x, Challenge) for x in interests), Colorizer.Red('Filter interest does not return a list of challenge'))
Пример #12
0
 def __exclude_custom_fields(self):
     remote_custom_fields = self.get_custom_field_definitions()
     for field in self.fields:
         customs = filter(lambda x: x['id'] == field['definition']['id'],
                          remote_custom_fields)
         if len(customs) > 0:
             custom = customs[0]
             if custom['type'] == 'list' and not field['value'] in custom[
                     'options']:
                 print Colorizer.Yellow('Excluding field : %s ' % field)
                 self.fields.remove(field)
                 print Colorizer.Yellow('Field Excluded')
Пример #13
0
def run():
    profiles = Profile.objects.all()
    for profile in profiles:
        try:
            update_activities(profile.user)
        except Exception as e:
            print(Colorizer.Red('####################################'))
            print(Colorizer.Red('Error updating activities'))
            print(Colorizer.Red(e))
            print(Colorizer.Red('####################################'))
        else:
            print(Colorizer.Green('Acitivity updated :' + profile.user.email))
Пример #14
0
    def test1_add_country_aliases(self):
        print Colorizer.LightPurple(
            '\n[TEST PROFILE LOCATION] assert should add country aliases if doesnt exist'
        )

        # response = RestCountriesConnector.get_city_alias(self.location['country'])

        print 'country aliases'
        print self.user.profile.location.country_alias

        self.assertIsNotNone(
            None,
            Colorizer.Red('City alternate names is not present on response'))
Пример #15
0
    def test2_add_project_contributor(self):
        print Colorizer.LightPurple('\n[TEST project] should add a contributor to project')
        project = Project(
            title='Prova project',
            picture='images/profile/default_user_icon.png',
            details='Prova description'
        )
        project.profile = self.user.profile
        project.save()
        project.contributors.add(self.user.profile)
        project.save()

        new_project = Project.objects.get(title='Prova project')

        self.assertGreater(len(new_project.contributors.all()), 0, Colorizer.Red('Add contributor to project error'))
Пример #16
0
    def test6_get_interested_from_project(self):
        print Colorizer.LightPurple('\n[TEST CHALLENGE] should return a list of profile interested in a project')

        project = Project(
            title='Prova project',
            picture='images/profile/default_user_icon.png',
            details='Prova description'
        )
        project.profile = self.user.profile
        project.save()
        self.user.profile.add_interest(project)

        profiles = project.interested()

        self.assertTrue(all(isinstance(x, Profile) for x in profiles), Colorizer.Red('Challenge related interest are not a porofile list'))
Пример #17
0
 def __exclude_custom_fields(self):
     remote_custom_fields = self.get_custom_field_definitions()
     for field in self.fields:
         customs = filter(lambda x: x['id'] == field['definition']['id'],
                          remote_custom_fields)
         try:
             custom = customs[0]
             if custom['type'] == 'list' and not field['value'] in custom[
                     'options']:
                 print(
                     Colorizer.Yellow('Excluding field : {} ',
                                      format(field)))
                 self.fields.remove(field)
                 print(Colorizer.Yellow('Field Excluded'))
         except:
             pass
Пример #18
0
def print_results(errored=None, partially_updated=None):
    # PRINT RESULTS
    print '-------------'
    print 'TOTAL RESULTS'
    print '-------------'

    if len(errored):
        print Colorizer.Red('%s errored users' % len(errored))
        # logger.error('ERROR updating users : %s' % errored)
        print errored

    if len(partially_updated):
        print Colorizer.Purple('%s partially updated users : ' %
                               len(partially_updated))
        print(partially_updated)

    elif not len(errored) and not len(partially_updated):
        print Colorizer.Green('No errored users')
    print '-------------'
Пример #19
0
    def test5_add_location_to_profile(self):
        print Colorizer.LightPurple('\n[TEST PROFILE LOCATION] add location')

        location = Location.create(**self.location)

        self.user.profile.location = location
        self.user.profile.save()

        user = User.objects.filter(email=self.user.email)[0]

        self.assertIsNotNone(user.profile.location)
Пример #20
0
    def test_6_FindNotExisting(self):
        print(Colorizer.LightPurple('\n[ CRM Test : Find non existent party by email]'))

        # Deepcopy user
        user = copy.deepcopy(self.user)
        user.email = '*****@*****.**'
        party = Party(user)

        party.emailAddresses[0]['address'] = '*****@*****.**'
        results = party.get()

        self.assertIsNone(results, '\n[CRM-CONNECTOR ERROR] Response should be empty')
Пример #21
0
def run():
    profiles = Profile.objects.all()
    users = User.objects.all()
    for profile in profiles:
        try:
            profile.user
        except User.DoesNotExist:
            print(
                Colorizer.Red('User doesnt exist for profile with ID : ' +
                              str(profile.id)))
            profile.delete()
            print(Colorizer.Cyan('Removing profile'))
    for user in users:
        try:
            user.profile
        except Profile.DoesNotExist:
            print(
                Colorizer.Red('Profile doesnt exist for user ID: ' +
                              str(user.id) + ', EMAIL: ' + user.email))
            user.delete()
            print(Colorizer.Cyan('Removing user with EMAIL: ' + user.email))
Пример #22
0
def update_default_profile_image(users):
    errored = []
    sanititized = []
    for user in users:
        try:
            if user.profile.picture == 'images/profile/default_user_icon.png':
                print('--------------------')
                print('UPDATING USER : %s' % user)
                print('--------------------')
                print(' ')
                if user.profile.gender == 'male':
                    user.profile.picture = 'images/profile/male.svg'
                if user.profile.gender == 'female':
                    user.profile.picture = 'images/profile/female.svg'
                if user.profile.gender == 'other':
                    user.profile.picture = 'images/profile/other.svg'
                sanititized.append(user.email)
                user.profile.save()
        except Profile.DoesNotExist as e:
            errored.append(user.email)
            print(
                Colorizer.custom('[ERROR USER MALFORMED] : %s ' % e, 'white',
                                 'purple'))
            print(' ')
    # PRINT RESULTS
    print('-------------')
    print('TOTAL RESULTS')
    print('-------------')

    if len(errored):
        print(Colorizer.Red('%s errored users' % len(errored)))
        print(errored)

    if len(sanititized):
        print(Colorizer.Purple('%s updated users : ' % len(sanititized)))
        print(sanititized)

    elif not len(errored) and not len(sanititized):
        print(Colorizer.Green('no updates or errors'))
    print('-------------')
Пример #23
0
def update_crm(user=None):
    errored = []
    partially_updated = []
    party = None

    users = user or User.objects.all()

    for user in users:
        try:
            print('--------------------')
            print('UPDATING USER : %s' % user)
            print('--------------------')
            print(' ')
            party = Party(user)
            party.create_or_update()
            print Colorizer.Green('UPDATED %s' % user)
            print(' ')

        except Profile.DoesNotExist as e:
            print Colorizer.custom('[ERROR USER MALFORMED] : %s ' % e, 'white',
                                   'purple')
            print(' ')

        except CRMValidationException as e:
            try:
                print Colorizer.Red(
                    'Try to exclude incompatible custom fields for user: %s' %
                    user)
                party.safe_create_or_update()
                partially_updated.append(user.email)
                print Colorizer.Yellow('UPDATED partially: %s' % user)
                print(' ')

            except Exception as safe_exc:
                print Colorizer.Red('[ ERROR IN SAFE UPDATE ] : %s' % safe_exc)
                print json.dumps(party.as_dict(), indent=1)
                print(' ')

                print Colorizer.Red('ERROR UPDATING USER : %s' % user)
                print('ERROR: %s' % e)
                print(' ')
                errored.append(user.email)

        except Exception as e:
            print Colorizer.Red('ERROR UPDATING USER : %s' % user)
            print('ERROR: %s' % e)
            print(' ')

    return errored, partially_updated
Пример #24
0
    def test7_save_existing_location_add_country(self):
        print Colorizer.LightPurple(
            '\n[TEST PROFILE LOCATION] assert should add country aliases')

        Location.create(**self.location)

        location = Location.objects.filter(lat=self.location['lat'],
                                           lng=self.location['lng'])

        print location[0].country_alias

        self.assertEqual(
            len(location), 1,
            'Save Location with same lat an lng and different name, should update existing location'
        )
Пример #25
0
def run(*args):
    errored = []
    profiles = Profile.objects.filter(user__email=args[0]) \
        if len(args) > 0 \
        else Profile.objects.all()

    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('############### RESULTS ###############'))
    print('')
    print(
        Colorizer.Green(
            str(len(profiles) - len(errored)) +
            ' USERS WAS SUCCESFULLY UPDATED'))
    print(' ')
    print(Colorizer.Red(str(len(errored)) + ' USERS WITH ERRORS :'))
    for error in errored:
        print('    ')
        print('    ' + Colorizer.Red(error['user'].email + ' UUID: ' +
                                     str(error['user'].id)))
        print('      | EXCEPTION: ')
        [print('      | ' + line) for line in str(error['error']).split('\n')]
    print(Colorizer.Yellow(' '))
    print(Colorizer.Yellow('#######################################'))
Пример #26
0
 def test_7_findExisting(self):
     print(Colorizer.LightPurple('\n[ CRM Test : Find existing party]'))
     results = self.party.get()
     self.assertIsInstance(results, dict, '\n[CRM-CONNECTOR ERROR] Get Response should contain a dictionary')
Пример #27
0
def get_test_user(user_email):
    user = User.objects.filter(email=user_email)
    return user if len(user) > 0 else User.objects.filter(
        email='*****@*****.**')


def pair_crm_ids():
    users = User.objects.all()
    for u in users:
        try:
            party = Party(u)
            party_crm_id = party.get()['id']
            profile = Profile.get_by_email(u)
            profile.set_crm_id(party_crm_id)
        except Exception as e:
            print 'PAIR CRM IDs %s' % u
            print 'PAIR CRM IDs %s' % e

    sys.exit("Paring finished")


if __name__ == "__main__":
    pair_crm_ids() if len(
        sys.argv) > 1 and sys.argv[1] == 'pair_crm_ids' else None
    user = get_test_user(sys.argv[1]) if len(sys.argv) > 1 else None
    if len(user) > 0:
        errored, partially_updated = update_crm(user)
        print_results(errored, partially_updated)
    else:
        print Colorizer.Red('No user found')
Пример #28
0
 def test_5_Update(self):
     print(Colorizer.LightPurple('[ CRM Test : Update test ]'))
     results = self.party.create_or_update()
     self.assertTrue(True, '[CRM-CONNECTOR ERROR] Response is not a valid Party object :\n %s ')
Пример #29
0
 def test_2_creation(self):
     print(Colorizer.LightPurple('[ CRM Test : Create ]'))
     results = self.party.create_or_update()
     self.assertIsInstance(results, dict, '[CRM-CONNECTOR ERROR] Creation Response should be a dictionary ')
Пример #30
0
 def test_1_connection(self):
     print(Colorizer.LightPurple('\n[ CRM Test : Connection test ]'))
     response = self.party.all()
     self.assertEqual(response.status_code, 200, '[CRM-CONNECTOR ERROR] Response error :\n %s ' % response)