Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
0
    def _resolve_new_release(product_dataclass: ProductBase,
                             product_model: ProductModel):
        """Solution for :attr:`ReleaseInfosStatus.NEW_RELEASE`"""
        assert len(product_dataclass.release_infos) > len(
            product_model.release_infos)

        new_releases = product_dataclass.release_infos[len(product_model.
                                                           release_infos):]
        for new_release in new_releases:
            product_model.release_infos.append(
                ProductReleaseInfo(
                    price=new_release.price,
                    initial_release_date=new_release.release_date,
                    announced_at=new_release.announced_at))
Ejemplo n.º 10
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.º 11
0
def update_fake_release_created_time(session):
    prs = ProductReleaseInfo.all()
    for pr in prs:
        pr.created_at = fake.date_time_between(start_date=datetime(2015, 1, 1),
                                               end_date=datetime(2020, 12, 31))
        session.add(pr)
Ejemplo n.º 12
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.º 13
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