예제 #1
0
    def handle(self, *args, **options):
        KHARKOV = [50.040156499999995, 36.3003934]
        SMELA = [49.2391097, 31.859249100000003]
        CITIES = [KHARKOV, SMELA]

        print("COMMAND STARTED")
        unique_categories = list()
        while len(unique_categories) < 5:
            unique_categories.append(fake.word())
            unique_categories = list(set(unique_categories))

        unique_emails = list()
        while len(unique_emails) < 100:
            unique_emails.append(fake.email())
            unique_emails = list(set(unique_emails))

        print("CREATING OF CATEGORIES")
        categories = [
            CategoryFactory(name=category) for category in unique_categories
        ]

        print("CREATING OF USERS-PROFILES-POSTS")
        iteration = 0
        for email in unique_emails:
            coords = random.choice(CITIES)
            try:
                user = UserFactory(email=email,
                                   latitude=coords[0],
                                   longitude=coords[1],
                                   full_name=fake.name())
                user.set_password('qweqweqwe')
                user.save()
            except IntegrityError:
                print('EMAIL SKIPPED')
                continue

            try:
                image_url = fake.image_url()
                while "lorempixel" in image_url:
                    image_url = fake.image_url()
                image_path = load_image_by_url(image_url)
                image = Image.objects.create(user=user, image=image_path)
            except Exception as e:
                print(e)
                continue

            profile = ProfileFactory(user=user,
                                     avatar=image,
                                     age=random.randint(18, 55))

            post = PostFactory(profile=profile,
                               category=random.choice(categories),
                               looking_for=random.choice(GENDERS))
            post.photos.add(image)
            post.save()

            print('{}/{}'.format(iteration, len(unique_emails)))
            iteration += 1

        print("COMMAND FINISHED")
    def test_change_account_password_failure_cases(self):
        # Should reject the password change request if old password is incorrect
        user = UserFactory()
        old_password = '******'
        new_password = '******'
        user.set_password(old_password)
        user.save()
        self.client.force_login(user)
        url = reverse('api_accounts:current_user_detail')

        # Test old password is incorrect
        response = self.client.put(url, {
            'old_password': '******',
            'new_password1': new_password,
            'new_password2': new_password,
        },
                                   format='json')

        self.assertEqual(response.status_code, 400)
        execpted = {u'old_password': [u'Old password is incorrect']}
        self.assertDictContainsSubset(execpted, response.json())

        # Test two passwords mismatch
        response = self.client.put(url, {
            'old_password': old_password,
            'new_password1': new_password,
            'new_password2': new_password + '1',
        },
                                   format='json')

        self.assertEqual(response.status_code, 400)
        execpted = {u'new_password1': [u'Password1 and Password2 mismatch']}
        self.assertDictContainsSubset(execpted, response.json())
 def test_change_account_password(self):
     user = UserFactory()
     old_password = '******'
     new_password = '******'
     user.set_password(old_password)
     user.save()
     self.client.force_login(user)
     url = reverse('api_accounts:current_user_detail')
     response = self.client.put(url, {
         'old_password': old_password,
         'new_password1': new_password,
         'new_password2': new_password,
     },
                                format='json')
     self.assertEqual(response.status_code, 200)
     updated_user = User.objects.get(pk=user.pk)
     self.assertTrue(updated_user.check_password(new_password))
예제 #4
0
def fake_db_for_tester(user):
    EXAMPLE_PIC_PATH = 'server/media/gallery/example_pic.jpg'
    first_image = shutil.copy(
        EXAMPLE_PIC_PATH, 'server/media/gallery/example_pic_%d.jpg' % user.id)
    source = shutil.copy(EXAMPLE_PIC_PATH,
                         'server/media/source/example_pic_%d.jpg' % user.id)
    source_image = SourceImage.objects.create(user=user, image=source[13:])
    image = Image.objects.create(user=user,
                                 image=first_image[12:],
                                 source=source_image)
    emails = generate_fake_emails(50)
    if Category.objects.all().count() < 3:
        Category.objects.create(name='Sport')
        Category.objects.create(name='Dating')
        Category.objects.create(name='Food')
    categories = Category.objects.all()

    for email in emails:
        try:
            user = UserFactory(
                email=email,
                latitude=user.latitude,
                longitude=user.longitude,
                full_name=fake.name(),
            )
            user.set_password('qweqweqwe')
            user.save()
        except IntegrityError:
            print('EMAIL SKIPPED')
            continue
        new_image = shutil.copy(
            EXAMPLE_PIC_PATH,
            'server/media/gallery/example_pic_%d.jpg' % user.id)
        try:
            image = Image.objects.create(user=user, image=new_image[12:])
            avatar = Avatar.objects.create(user=user,
                                           image=new_image[12:],
                                           source=source_image)
        except Exception as e:
            print(e)
            continue

        profile = ProfileFactory(user=user,
                                 avatar=avatar,
                                 age=random.randint(18, 55),
                                 name=fake.name())

        post = PostFactory(profile=profile,
                           category=random.choice(categories),
                           looking_for=random.choice(GENDERS),
                           text=fake.text()[:random.randint(0, 500)])
        post = PostFactory(profile=profile,
                           category=random.choice(categories),
                           looking_for=random.choice(GENDERS),
                           text=fake.text()[:random.randint(0, 500)],
                           is_matches=True)

        images = Image.objects.all()
        asd = "1.jpeg"  # str(uuid.uuid1())
        post_image_path = copy_image(
            "server/media/gallery/%s" % image.file_name,
            "server/media/gallery_edited/%s" % asd)

        post_image_1 = PostImage.objects.create(image='gallery_edited/1.jpeg',
                                                source=source_image)
        post_image_2 = PostImage.objects.create(image='gallery_edited/1.jpeg',
                                                source=source_image)
        post_image_3 = PostImage.objects.create(image='gallery_edited/1.jpeg',
                                                source=source_image)
        post.photos.add(post_image_1)
        post.photos.add(post_image_2)
        post.photos.add(post_image_3)

        post.save()