Exemple #1
0
    def test_test_gallery_methods(self):

        with test_database(db, (Users, UserImages)):
            Users.create_user(username = "******", password = "******")
            user1 = Users.select().get()

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)

            
            image = UserImages.select().get()
            self.assertFalse(image.gallery)
            UserImages.gallerify(image)
            self.assertTrue(image.gallery)
            UserImages.gallerify(image)
            self.assertFalse(image.gallery)

            for num in range(2, 10):
                UserImages.add_image(image_link = "test image %d" % num,\
                                    description = "test %d" % num,\
                                    owner = user1)

            self.assertEquals(9, UserImages.get_count())

            paginated = UserImages.get_gallery_images(1, 2)

            self.assertEquals(2, len(tuple(paginated)))

            self.assertIn(self.ADDRESS, str(tuple(paginated)))
            self.assertNotIn("test image 3", str(tuple(paginated)))

            paginated = UserImages.get_gallery_images(5, 2)

            self.assertIn("test image 9", str(tuple(paginated)))
            self.assertEquals(1, len(tuple(paginated)))
Exemple #2
0
    def test_test_gallery_methods(self):

        with test_database(db, (Users, UserImages)):
            Users.create_user(username="******", password="******")
            user1 = Users.select().get()

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)

            image = UserImages.select().get()
            self.assertFalse(image.gallery)
            UserImages.gallerify(image)
            self.assertTrue(image.gallery)
            UserImages.gallerify(image)
            self.assertFalse(image.gallery)

            for num in range(2, 10):
                UserImages.add_image(image_link = "test image %d" % num,\
                                    description = "test %d" % num,\
                                    owner = user1)

            self.assertEquals(9, UserImages.get_count())

            paginated = UserImages.get_gallery_images(1, 2)

            self.assertEquals(2, len(tuple(paginated)))

            self.assertIn(self.ADDRESS, str(tuple(paginated)))
            self.assertNotIn("test image 3", str(tuple(paginated)))

            paginated = UserImages.get_gallery_images(5, 2)

            self.assertIn("test image 9", str(tuple(paginated)))
            self.assertEquals(1, len(tuple(paginated)))
Exemple #3
0
    def test_creating_and_deleting_image(self):
        
        with test_database(db, (Users, UserImages)):
            Users.create_user(username = "******", password = "******")
            user1 = Users.select().get()

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)


            image = UserImages.select().get()

            self.assertEquals(self.ADDRESS ,image.image_link)
            self.assertEquals("test", image.description)
            self.assertEquals(user1, image.owner)

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)

            self.assertEquals(2, UserImages.get_count())

            self.assertTrue(UserImages.check_exists(self.ADDRESS))
            self.assertFalse(UserImages.check_exists(self.ADDRESS + "bam"))
            image = UserImages.get_image(2)
            UserImages.delete_image(image)
            self.assertEquals(1, UserImages.get_count())
            image = UserImages.get_image(1)
            UserImages.delete_image(image)
            self.assertEquals(0, UserImages.get_count())
Exemple #4
0
    def test_creating_and_deleting_image(self):

        with test_database(db, (Users, UserImages)):
            Users.create_user(username="******", password="******")
            user1 = Users.select().get()

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)

            image = UserImages.select().get()

            self.assertEquals(self.ADDRESS, image.image_link)
            self.assertEquals("test", image.description)
            self.assertEquals(user1, image.owner)

            UserImages.add_image(image_link = self.ADDRESS,\
                                description = "test",\
                                is_vertical = True, \
                                owner = user1,\
                                imgur_img = False,\
                                delete_hash = None)

            self.assertEquals(2, UserImages.get_count())

            self.assertTrue(UserImages.check_exists(self.ADDRESS))
            self.assertFalse(UserImages.check_exists(self.ADDRESS + "bam"))
            image = UserImages.get_image(2)
            UserImages.delete_image(image)
            self.assertEquals(1, UserImages.get_count())
            image = UserImages.get_image(1)
            UserImages.delete_image(image)
            self.assertEquals(0, UserImages.get_count())
Exemple #5
0
def upload_image():
    error = None
    if request.method == "POST":
        description = request.form.get('description', None)
        if request.form.get("imgur-img"):
            image = request.files["image"]
            if not image:
                error = "No image chosen"
                return render_template("upload_image.html", error=error)

            user_id = get_config().imgur_id
            extension = split_filename(image.filename, True)
            if extension not in app.config["ALLOWED_FILENAMES"]:
                error = "Allowed extensions are %r"\
                        % (", ".join(app.config["ALLOWED_FILENAMES"]))
                return render_template("upload_image.html", error=error)

            filename = secure_filename(image.filename.strip())
            user = Users.get_user_by_username(session["user"])
            config = dict(
                image=image,
                name=filename,
                description=description)
            response = ImgurHandler(user_id, config).send_image()
            if not response["success"]:
                error = "Error uploading to imgur"
                return render_template("upload_image.html", error=error)

            response_data = response["data"]
            image_link = response_data["link"]
            is_vertical = response_data["width"] + 10 < response_data["height"]
            delete_hash = response_data["deletehash"]
            try:
                UserImages.add_image(image_link=image_link,
                                     description=description,
                                     delete_hash=delete_hash,
                                     is_vertical=is_vertical,
                                     imgur_img=True,
                                     owner=user)

                return redirect(url_for("user_images", username=user.username))
            except:
                error = "Error writing to database"
                return render_template("upload_image.html", error=error)

            return render_template("upload_image.html", error=response)

        elif request.form.get('save-link'):
            link = request.form.get('image-link', None)
            if not link:
                error = "No link given"
                return render_template("upload_image.html", error=error)

            user = Users.get_user_by_username(session["user"])
            try:
                UserImages.add_image(image_link=link,
                                     description=description,
                                     is_vertical=True,
                                     imgur_img=False,
                                     owner=user)
                return redirect(url_for("user_images", username=user.username))

            except Exception as e:
                error = "Error writing to database"
                return render_template("upload_image.html", error=error)
    else:
        return render_template("upload_image.html")
Exemple #6
0
def upload_image():
    error = None
    if request.method == "POST":
        description = request.form.get('description', None)
        if request.form.get("imgur-img"):
            image = request.files["image"]
            if not image:
                error = "No image chosen"
                return render_template("upload_image.html", error=error)

            user_id = get_config().imgur_id
            extension = split_filename(image.filename, True)
            if extension not in app.config["ALLOWED_FILENAMES"]:
                error = "Allowed extensions are %r"\
                        % (", ".join(app.config["ALLOWED_FILENAMES"]))
                return render_template("upload_image.html", error=error)

            filename = secure_filename(image.filename.strip())
            user = Users.get_user_by_username(session["user"])
            config = dict(image=image, name=filename, description=description)
            response = ImgurHandler(user_id, config).send_image()
            if not response["success"]:
                error = "Error uploading to imgur"
                return render_template("upload_image.html", error=error)

            response_data = response["data"]
            image_link = response_data["link"]
            is_vertical = response_data["width"] + 10 < response_data["height"]
            delete_hash = response_data["deletehash"]
            try:
                UserImages.add_image(image_link=image_link,
                                     description=description,
                                     delete_hash=delete_hash,
                                     is_vertical=is_vertical,
                                     imgur_img=True,
                                     owner=user)

                return redirect(url_for("user_images", username=user.username))
            except:
                error = "Error writing to database"
                return render_template("upload_image.html", error=error)

            return render_template("upload_image.html", error=response)

        elif request.form.get('save-link'):
            link = request.form.get('image-link', None)
            if not link:
                error = "No link given"
                return render_template("upload_image.html", error=error)

            user = Users.get_user_by_username(session["user"])
            try:
                UserImages.add_image(image_link=link,
                                     description=description,
                                     is_vertical=True,
                                     imgur_img=False,
                                     owner=user)
                return redirect(url_for("user_images", username=user.username))

            except Exception as e:
                error = "Error writing to database"
                return render_template("upload_image.html", error=error)
    else:
        return render_template("upload_image.html")