Example #1
0
    def test_thumbnails_are_generated_on_server(self):
        product = models.Product(
            name='The cathedral and the bazaar',
            price=Decimal('10.00'),
        )
        product.save()

        with open('main/fixtures/the-cathedral-the-bazaar.jpg', 'rb') as f:
            image = models.ProductImage(
                product=product,
                image=ImageFile(f, name='tctb.jpg'),
            )
            with self.assertLogs("main", level='INFO') as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open('main/fixtures/the-cathedral-the-bazaar.thumb.jpg',
                  'rb') as f:
            expected_content = f.read()
            assert image.thumbnail.read() == expected_content

            image.thumbnail.delete(save=False)
            image.image.delete(save=False)
Example #2
0
    def test_thumbnails_are_created_on_save(self):
        product = models.Product(
            name="The cathedral and the bazaar",
            price=Decimal("20.00")
        )
        product.save()

        with open("main/fixtures/the-cathedral-the-bazaar.jpg", "rb") as f:
            image = models.ProductImage(
                product=product,
                image=ImageFile(f, name="tctb.jpg"),
            )
            logger = logging.getLogger("main")
            with self.assertLogs(logger, level="INFO") as cm:
                image.save()

            self.assertGreaterEqual(len(cm.output), 1)
            image.refresh_from_db()

            with open("main/fixtures/the-cathedral-the-bazaar.thumb.jpg", "rb") as tn:
                expected_content = tn.read()
                thumbnail = image.thumbnail.read()
                assert thumbnail == expected_content

            image.thumbnail.delete(save=False)
            image.image.delete(save=False)
    def test_thumbnails_are_generated_on_save(self):
        """
        Overview
        1. product init inst & save
        2. product image (original)
        3. product image (thumbnail)

        The 'signals.py' lies between "models" & "views",
        you don't actually can see it 
        """

        product = models.Product(name="The Cathedral and the bazaar",
                                 price=Decimal("3.00"))

        product.save()

        with open("main/fixtures/the-cathedral-the-bazaar.jpg", "rb") as fi:
            image = models.ProductImage(product=product,
                                        image=ImageFile(fi, name="tctb.jpg"))

            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open("main/fixtures/the-cathedral-the-bazaar.thumb.jpg",
                  "rb") as fi:
            expected_content = fi.read()
            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
Example #4
0
    def test_thumbnails_are_generated_on_save(self):
        product = models.Product(
            name="The cathedral the bazaar",
            price=Decimal("10.00"),
        )
        product.save()

        with open("main/fixtures/the-catheral-the-bazaar.thumb.jpg" "rb") as f:
            image = models.ProductImage(product=product,
                                        image=ImageFile(f, name="tctb.jpg"))
            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open(
                "main/fixtures/the-cathederal-the-bazaar.thumb.jpg",
                "rb",
        ) as f:
            expected_content = f.read()
            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
Example #5
0
    def test_thumbnails_are_generated_on_save(self):
        product = models.Product(
            name='Learning Python 3.8',
            price=Decimal("20.00"),
        )
        product.save()

        # input("press any key to continue")

        with open("main/fixtures/learning-python-38.jpg", "rb") as f:
            image = models.ProductImage(
                product=product,
                image=ImageFile(f, name="lp38.jpg"),
            )
            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open(
                "main/fixtures/learning-python-38-thumb.jpg",
                "rb",
        ) as f:
            expected_content = f.read()
            print(type(expected_content))
            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
Example #6
0
    def test_thumbnails_are_generated_on_save(self):
        """
        This test has a small problem: the test pic won't be deleted if the
        test fails to pass.
        """
        product = models.Product(
            name=self.TEST_PROD_NAME, price=self.TEST_PROD_PRICE
        )
        product.save()

        with open(
            file=f"main/fixtures/{self.TEST_PROD_FILENAME}.jpg", mode="rb"
        ) as f:
            image = models.ProductImage(
                product=product,
                image=ImageFile(f, name="testpic_testsignal.jpg"),
            )

            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open(
            file=f"main/fixtures/{self.TEST_PROD_FILENAME}.thumb.jpg",
            mode="rb",
        ) as f:
            expected_content = f.read()

            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
 def test_thumbnails_are_generated_on_save(self):
     product = models.Product(name="The cathedral and the bazaar", price = Decimal("10.00"))
     product.save()
     with open("main/fixtures/the-cathedral-the-bazaar.jpg", "rb") as f:
         image = models.ProductImage(product=product),
                                     image=ImageFile(f, name="tctb.jpg"),
                                     )
    def test_thumbnails_generated_on_save(self):
        product = models.Product(
            name='Test product',
            price=Decimal('10.0'),
        )
        product.save()

        with open('main/fixtures/test_image.jpg', 'rb') as f:
            image = models.ProductImage(
                product=product,
                image=ImageFile(f, name='test_image.jpg'),
            )
            with self.assertLogs('main', level='INFO') as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open('main/fixtures/test_image.thumb.jpg', 'rb') as f:
            expected_content = f.read()

            self.assertEqual(image.thumbnail.read(), expected_content)

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
    def test_thumbnails_are_generated_on_product_save(self):
        product = models.Product(name="Harry Potter", price=Decimal("10.00"))
        product.save()

        with open("main/fixtures/sample-images/harry-potter.jpg", "rb") as f:
            image = models.ProductImage(product=product,
                                        image=ImageFile(f, name="hp.jpg"))
            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
Example #10
0
def test_product_creation():
    category = models.Category(name='Test cat')
    category.save()
    product = models.Product(name='Test product',
                             price=100,
                             tablet_count=1,
                             description='Test descr',
                             art=1,
                             in_stock=True,
                             category=category,
                             country='UA',
                             form='tablets',
                             count_per_day=1)
    product.save()
    return product
Example #11
0
    def test_thumbnail_are_generated_on_save(self):
        product = models.Product(name='Laptop',price=Decimal('150.00'),)
        product.save()

        with open('main/fixtures/jacket.jpg',"rb") as f:
            image = models.ProductImage(product=product,image=ImageFile(f,name="tctb.jpg"),)
            with self.assertLogs("main",level="INFO") as cm:
                image.save()
        self.assertGreaterEqual(len(cm.output),1)
        image.refresh_from_db()
        with open("main/fixtures/jacket.thumb.jpg","rb",) as f:
            expected_content = f.read()
            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)
Example #12
0
    def setUp(self):
        self.user1 = models.User.objects.create_user("user1",
                                                     "*****@*****.**",
                                                     "pw432kwjow")
        self.user2 = models.User.objects.create_user(
            "user2", "*****@*****.**", "12kiwajow")
        self.product = models.Product(
            user=self.user1,
            name="pythonのプログラミングで簡単なwebページ作成を教えます",
            description=
            "webサイトを作成したことがない人に向けて、昨今、機械学習分野でhotなプログラミング言語であるpythonを使用して、webサイトを公開するまで教えます。",
            price=4000,
        )

        self.user1.save()
        self.user2.save()
        self.product.save()
def create_product(
    seller,
    **kwargs,
):
    """
        Given the attributes of a product and a Profile(seller) instance, create a new product and save it to the database. Utility for the CreateProduct mutation. 
    """

    p = models.Product()
    p.seller = seller
    p.name = kwargs.get('name')
    p.expected_price = kwargs.get('expected_price')
    p.is_negotiable = kwargs.get('is_negotiable')
    p.description = kwargs.get('description')
    p.category_id = kwargs.get('category_id')
    p.save()

    return p
Example #14
0
def admin_products_add(request):
    if request.POST:
        code = request.POST.get('code', '')
        description = request.POST.get('description', '')
        price = request.POST.get('price', 0)

        product = models.Product()
        product.code = code
        product.description = description
        product.category_id = 1  # temp
        product.price = price
        product.save()

        messages.success(request, 'New product created.')
        return redirect('/admin/products/add/')

    return render(request, 'admin/products_add.html',
                  {'code': order_id_generator()})
Example #15
0
    def test_thumbnails_are_generated_on_save(self):
        product = models.Product(name="Breguet-Classique-Automatic-40mm", price=Decimal("10000.00"),)
        product.save()

        with open("main/fixtures/Breguet-Classique-Automatic-40mm.jpg", "rb") as f:
            image = models.ProductImage(product=product, image=ImageFile(f, name="xxx.jpg"),)
            with self.assertLogs("main", level="INFO") as cm:
                image.save()

        self.assertGreaterEqual(len(cm.output), 1)
        image.refresh_from_db()

        with open("main/fixtures/Breguet-Classique-Automatic-40mm.jpg", "rb",) as f:
            expected_content = f.read()
            assert image.thumbnail.read() == expected_content

        image.thumbnail.delete(save=False)
        image.image.delete(save=False)