Ejemplo n.º 1
0
    def test_category_has_many_products(self):
        series = Category(name="figure")
        series.products.extend([Product(name="a"), Product(name="b")])
        series.save()

        assert isinstance(series.products, list)
        assert len(series.products) == 2
Ejemplo n.º 2
0
    def test_series_has_many_products(self):
        series = Series(name="foo")
        series.products.extend([Product(name="a"), Product(name="b")])
        series.save()

        products = series.products
        assert isinstance(products, list)
        assert len(products) == 2
Ejemplo n.º 3
0
    def update_product(product_dataclass: ProductBase,
                       product_model: ProductModel) -> ProductModel:
        """Should be called in database session.
        :raise ReleaseInfosConflictError: Unable to sync the release_infos
        """
        release_info_solution = ReleaseInfosSolution()

        status = ReleaseInfoHelper.compare_infos(
            product_dataclass.release_infos, product_model.release_infos)
        while status is not ReleaseInfosStatus.SAME and status is not ReleaseInfosStatus.CONFLICT:
            release_info_solution.set_situation(status).execute(
                product_dataclass=product_dataclass,
                product_model=product_model)
            status = ReleaseInfoHelper.compare_infos(
                product_dataclass.release_infos, product_model.release_infos)

        if status is ReleaseInfosStatus.CONFLICT:
            raise ReleaseInfosConflictError(product_dataclass.url)

        # unique attribute
        series = Series.as_unique(name=product_dataclass.series)
        manufacturer = Company.as_unique(name=product_dataclass.manufacturer)
        category = Category.as_unique(name=product_dataclass.category)
        releaser = Company.as_unique(name=product_dataclass.releaser)
        distributer = Company.as_unique(name=product_dataclass.distributer)

        # unique in list attribute
        paintworks = Paintwork.multiple_as_unique(product_dataclass.paintworks)
        sculptors = Sculptor.multiple_as_unique(product_dataclass.sculptors)

        product_model.update(
            url=product_dataclass.url,
            name=product_dataclass.name,
            size=product_dataclass.size,
            scale=product_dataclass.scale,
            rerelease=product_model.rerelease or product_dataclass.rerelease,
            adult=product_dataclass.adult,
            copyright=product_dataclass.copyright,
            series=series,
            manufacturer=manufacturer,
            releaser=releaser,
            distributer=distributer,
            category=category,
            id_by_official=product_dataclass.maker_id,
            checksum=product_dataclass.checksum,
            order_period_start=product_dataclass.order_period.start,
            order_period_end=product_dataclass.order_period.end,
            thumbnail=product_dataclass.thumbnail,
            og_image=product_dataclass.og_image,
            jan=product_dataclass.jan,
            # relationship
            sculptors=sculptors,
            paintworks=paintworks,
        )

        return product_model
Ejemplo n.º 4
0
    def test_product_release_infos_is_nullsfirst(self, session):
        product = Product(name="figure")
        initial_info = ProductReleaseInfo(price=12960, initial_release_date=date(2020, 2, 12))
        resale_info = ProductReleaseInfo(price=15800, initial_release_date=date(2021, 2, 12))
        stall_info = ProductReleaseInfo(price=16000)

        product.release_infos.extend([initial_info, resale_info, stall_info])
        product.save()
        session.commit()

        p = Product.get_by_id(product.id)
        assert p
        assert p.release_infos[0] == stall_info
Ejemplo n.º 5
0
    def test_worker_has_many_products(self):
        paintwork = Paintwork(name="someone")
        sculptor = Sculptor(name="somebody")
        products = [Product(name="a"), Product(name="b")]

        paintwork.products.extend(products)
        sculptor.products.extend(products)
        paintwork.save()
        sculptor.save()
        assert isinstance(paintwork.products, list)
        assert len(paintwork.products) == 2
        assert isinstance(sculptor.products, list)
        assert len(sculptor.products) == 2
Ejemplo n.º 6
0
    def test_product_has_many_product_release_infos(self, session):
        product = Product(name="figure")
        initial_info = ProductReleaseInfo(price=12960, initial_release_date=date(2020, 2, 12))
        resale_info = ProductReleaseInfo(price=15800, initial_release_date=date(2021, 2, 12))

        product.release_infos.extend([initial_info, resale_info])
        product.save()
        session.commit()

        fetched_product = Product.get_by_id(product.id)
        assert fetched_product
        assert isinstance(fetched_product.release_infos, list)
        assert len(fetched_product.release_infos) == 2
        assert fetched_product.release_infos[-1] == resale_info
Ejemplo n.º 7
0
    def test_release_info_would_be_deleted_when_product_was_deleted(self, session):
        product = Product(name="foo")

        release_1 = ProductReleaseInfo(price=100)
        release_2 = ProductReleaseInfo(price=200)

        product.release_infos.append(release_1)
        product.release_infos.append(release_2)
        product.save()
        session.commit()

        Product.destroy([product.id])
        session.commit()

        assert not ProductReleaseInfo.all()
Ejemplo n.º 8
0
    def test_images_would_be_deleted_when_product_was_deleted(self, session):
        product = Product(name="foo")

        image_1 = ProductOfficialImage(url="http://foo.com/img1.jpg")
        image_2 = ProductOfficialImage(url="http://foo.com/img2.jpg")

        product.official_images.append(image_1)
        product.official_images.append(image_2)
        product.save()
        session.commit()

        Product.destroy([product.id])
        session.commit()

        assert not ProductOfficialImage.all()
Ejemplo n.º 9
0
    def test_change_solution(self, product: Product):
        solution = ReleaseInfosSolution()

        product.release_infos = HistoricalReleases([
            Release(date(2020, 1, 2), Price(12000)),
            Release(date(2023, 2, 2), Price(12000)),
            Release(date(2028, 1, 2), Price(12000)),
        ])
        product.release_infos.sort()

        p_m = ProductModel.create(
            name="foo",
            release_infos=[
                ProductReleaseInfo(initial_release_date=date(2020, 1, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2023, 2, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2028, 2, 2),
                                   price=12000),
            ])

        solution.set_situation(ReleaseInfosStatus.CHANGE).execute(
            product_dataclass=product, product_model=p_m)

        assert ReleaseInfoHelper.compare_infos(
            product.release_infos,
            p_m.release_infos) is ReleaseInfosStatus.SAME
Ejemplo n.º 10
0
    def test_stall_info_adjust_release_date(self):
        p = Product.create(name="foo")
        stall_info = ProductReleaseInfo.create(price=12960, product_id=p.id)
        delay_date = date(2021, 1, 1)

        stall_info.adjust_release_date_to(delay_date)
        assert stall_info.initial_release_date == delay_date
Ejemplo n.º 11
0
    def test_company_has_many_products(self):
        company = Company(name="GSC")
        products = [Product(name="a"), Product(name="b")]
        company.released_products.extend(products)
        company.distributed_products.extend(products)
        company.made_products.extend(products)
        company.save()

        r_products = company.released_products
        m_products = company.made_products
        d_products = company.distributed_products

        assert isinstance(r_products, list)
        assert len(r_products) == 2

        assert isinstance(m_products, list)
        assert len(m_products) == 2

        assert isinstance(d_products, list)
        assert len(d_products) == 2
Ejemplo n.º 12
0
    def test_get_release_date(self):
        p = Product.create(name="foo")
        info_1 = ProductReleaseInfo(price=12960, initial_release_date=date(2020, 1, 1), product_id=p.id)
        assert info_1.release_date == date(2020, 1, 1)

        info_2 = ProductReleaseInfo(price=12960, initial_release_date=date(2020, 1, 1),
                                    adjusted_release_date=date(2020, 5, 1), product_id=p.id)
        assert info_2.release_date == date(2020, 5, 1)

        info_3 = ProductReleaseInfo(price=12960, product_id=p.id)
        assert info_3.release_date == None
Ejemplo n.º 13
0
    def test_release_date_could_be_brought_forward(self):
        p = Product.create(name="foo")
        init_date = ProductReleaseInfo.create(
            price=12960, initial_release_date=date(2020, 1, 1), product_id=p.id
        )

        early_date = date(2019, 12, 1)
        init_date.adjust_release_date_to(early_date)

        assert init_date.initial_release_date == date(2020, 1, 1)
        assert init_date.adjusted_release_date == early_date
Ejemplo n.º 14
0
    def test_delay(self):
        release_infos = HistoricalReleases(
            [Release(date(2020, 2, 2), Price(12000))])

        p_m = ProductModel.create(
            name="foo",
            release_infos=[
                ProductReleaseInfo(initial_release_date=date(2020, 1, 2),
                                   price=12000)
            ])
        assert ReleaseInfoHelper.compare_infos(
            release_infos, p_m.release_infos) == ReleaseInfosStatus.CHANGE
Ejemplo n.º 15
0
    def test_delete_paintwork_and_association_but_not_effect_product(self, session):
        from figure_hook.Models.relation_table import (product_paintwork_table,
                                                       product_sculptor_table)
        p = Product(name="foo")
        master = Sculptor(name="master")
        newbie = Paintwork(name="newbie")

        p.paintworks.append(newbie)
        p.sculptors.append(master)
        p.save()
        session.commit()

        Paintwork.destroy([newbie.id])
        session.commit()

        s_asso = session.query(product_sculptor_table).all()
        p_asso = session.query(product_paintwork_table).all()
        assert s_asso
        assert not p_asso
        f_p = Product.first()
        assert f_p
        assert f_p.sculptors
Ejemplo n.º 16
0
    def test_fetech_product_last_product_release_infos(self, session):
        product = Product(name="figure")
        initial_info = ProductReleaseInfo(price=12960, initial_release_date=date(2020, 2, 12))
        resale_info = ProductReleaseInfo(price=15800, initial_release_date=date(2021, 2, 12))

        product.release_infos.extend([initial_info, resale_info])
        product.save()
        session.commit()

        f_p = product.first()
        assert f_p
        last_release = f_p.last_release()
        assert last_release is resale_info
Ejemplo n.º 17
0
    def create_product(product_dataclass: ProductBase) -> ProductModel:
        series = Series.as_unique(name=product_dataclass.series)
        manufacturer = Company.as_unique(name=product_dataclass.manufacturer)
        category = Category.as_unique(name=product_dataclass.category)
        releaser = Company.as_unique(name=product_dataclass.releaser)
        distributer = Company.as_unique(name=product_dataclass.distributer)

        paintworks = Paintwork.multiple_as_unique(product_dataclass.paintworks)
        sculptors = Sculptor.multiple_as_unique(product_dataclass.sculptors)

        images = ProductOfficialImage.create_image_list(
            product_dataclass.images)

        release_infos: List[ProductReleaseInfo] = []
        for release in product_dataclass.release_infos:
            release_info = ProductReleaseInfo(
                price=release.price,
                initial_release_date=release.release_date,
                announced_at=release.announced_at)
            if release.price:
                release_info.tax_including = release.price.tax_including
            release_infos.append(release_info)

        product = ProductModel.create(
            url=product_dataclass.url,
            name=product_dataclass.name,
            size=product_dataclass.size,
            scale=product_dataclass.scale,
            rerelease=product_dataclass.rerelease,
            adult=product_dataclass.adult,
            copyright=product_dataclass.copyright,
            series=series,
            manufacturer=manufacturer,
            releaser=releaser,
            distributer=distributer,
            category=category,
            id_by_official=product_dataclass.maker_id,
            checksum=product_dataclass.checksum,
            jan=product_dataclass.jan,
            order_period_start=product_dataclass.order_period.start,
            order_period_end=product_dataclass.order_period.end,
            thumbnail=product_dataclass.thumbnail,
            og_image=product_dataclass.og_image,
            # relationship
            release_infos=release_infos,
            sculptors=sculptors,
            paintworks=paintworks,
            official_images=images)

        return product
Ejemplo n.º 18
0
    def test_product_has_many_official_images(self):
        product = Product(name="foo")

        image_1 = ProductOfficialImage(url="http://foo.com/img1.jpg")
        image_2 = ProductOfficialImage(url="http://foo.com/img2.jpg")

        product.official_images.append(image_1)
        product.official_images.append(image_2)
        product.save()

        assert isinstance(product.official_images, list)
        assert len(product.official_images) == 2
        assert image_1.order == 1
        assert image_2.order == 2
Ejemplo n.º 19
0
    def test_basic_info_adjust_release_date(self):
        p = Product.create(name="foo")
        info_has_init_date = ProductReleaseInfo.create(
            price=12960, initial_release_date=date(2020, 1, 1), product_id=p.id
        )
        delay_date = date(2021, 1, 1)

        info_has_init_date.adjust_release_date_to(delay_date)
        assert info_has_init_date.adjusted_release_date == delay_date

        delay_datetime = datetime(2022, 2, 2, 12)

        info_has_init_date.adjust_release_date_to(delay_datetime)
        assert info_has_init_date.adjusted_release_date == delay_datetime.date()

        with pytest.raises(AssertionError):
            info_has_init_date.adjust_release_date_to(1)
Ejemplo n.º 20
0
    def test_product_belongs_to_many_worker(self):
        product = Product(name="foo")

        p1 = Paintwork(name="p1")
        p2 = Paintwork(name="p2")

        s1 = Sculptor(name="s1")
        s2 = Sculptor(name="s2")

        product.sculptors.append(s1)
        product.sculptors.append(s2)
        product.paintworks.append(p1)
        product.paintworks.append(p2)

        product.save()
        assert isinstance(product.sculptors, list)
        assert len(product.sculptors) == 2
        assert isinstance(product.paintworks, list)
        assert len(product.paintworks) == 2
Ejemplo n.º 21
0
    def test_last_release_date_was_brought_forward(self):
        release_infos = HistoricalReleases([
            Release(date(2020, 1, 2), Price(12000)),
            Release(date(2023, 2, 2), Price(12000)),
            Release(date(2028, 1, 2), Price(12000)),
        ])

        p_m = ProductModel.create(
            name="foo",
            release_infos=[
                ProductReleaseInfo(initial_release_date=date(2020, 1, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2023, 2, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2028, 2, 2),
                                   price=12000),
            ])

        assert ReleaseInfoHelper.compare_infos(
            release_infos, p_m.release_infos) == ReleaseInfosStatus.CHANGE
Ejemplo n.º 22
0
    def test_delay_has_been_confirmed(self):
        release_infos = HistoricalReleases([
            Release(date(2019, 1, 2), Price(12000)),
            Release(date(2020, 5, 2), Price(12000)),
            Release(date(2023, 2, 2), Price(12000)),
        ])

        p_m = ProductModel.create(
            name="foo",
            release_infos=[
                ProductReleaseInfo(initial_release_date=date(2019, 1, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2020, 2, 2),
                                   adjusted_release_date=date(2020, 5, 2),
                                   price=12000),
                ProductReleaseInfo(initial_release_date=date(2023, 2, 2),
                                   price=12000),
            ])

        assert ReleaseInfoHelper.compare_infos(
            release_infos, p_m.release_infos) == ReleaseInfosStatus.SAME
Ejemplo n.º 23
0
    def test_get_by_id(self):
        product = Product.create(name="foo figure", url="www.foo.com")

        fetched_product = Product.get_by_id(product.id)  # type: ignore
        assert fetched_product is product
Ejemplo n.º 24
0
    def test_created_at_default_is_datetime(self):
        product = Product.create(name="foo")

        assert bool(product.created_at)
        assert isinstance(product.created_at, datetime)
Ejemplo n.º 25
0
 def test_stall_release(self):
     p = Product.create(name="foo")
     info = ProductReleaseInfo.create(price=12960, initial_release_date=date(2020, 1, 1), product_id=p.id)
     info.stall()
     assert not info.initial_release_date
Ejemplo n.º 26
0
    def test_checksum_comparison(self):
        checksum = "111"
        product = Product.create(name="foo figure", url="www.foo.com", checksum="111")

        assert product.check_checksum(checksum)
Ejemplo n.º 27
0
    def test_get_by_id(self):
        p = Product(name="foo")
        info = ProductReleaseInfo.create(price=12960, product=p, initial_release_date=date.today())

        fetched_info = ProductReleaseInfo.get_by_id(info.id)  # type: ignore
        assert fetched_info is info