def test_campaign_end_date(rf, admin_user): """ To make things little bit more simple let's use only english as a language. """ with override_settings(LANGUAGES=[("en", "en")]): shop = get_default_shop() old_name = "test_campaign" object = CatalogCampaign.objects.create(name=old_name, active=True, shop=shop) object.save() view = CatalogCampaignEditView.as_view() new_name = "Test Campaign" assert object.name != new_name data = { "base-name": new_name, "base-public_name__en": "Test Campaign", "base-shop": get_default_shop().id, "base-active": True, "base-basket_line_text": "Test campaign activated!", "base-start_datetime": datetime.datetime(year=2016, month=6, day=19), "base-end_datetime": datetime.datetime(year=2016, month=6, day=10) } methods_before = CatalogCampaign.objects.count() # Conditions, effects and effects is tested separately with override_provides("campaign_context_condition", []): with override_provides("campaign_catalog_filter", []): with override_provides("campaign_product_discount_effect_form", []): request = apply_request_middleware(rf.post("/", data=data), user=admin_user) response = view(request, pk=object.pk) assert response.status_code in [200, 302] content = response.render().content.decode("utf-8") assert "Campaign end date can't be before start date." in content assert CatalogCampaign.objects.count() == methods_before assert CatalogCampaign.objects.get(pk=object.pk).name == old_name
def test_admin_campaign_edit_view_works(rf, admin_user): shop = get_default_shop() view_func = CatalogCampaignEditView.as_view() request = apply_request_middleware(rf.get("/"), user=admin_user) campaign = CatalogCampaign.objects.create(name="test campaign", active=True, shop=shop) response = view_func(request, pk=campaign.pk) assert campaign.name in response.rendered_content response = view_func(request, pk=None) assert response.rendered_content
def test_campaign_edit_save(rf, admin_user): """ To make things little bit more simple let's use only english as a language. """ with override_settings(LANGUAGES=[("en", "en")]): shop = get_default_shop() object = CatalogCampaign.objects.create(name="test campaign", active=True, shop=shop) object.save() view = CatalogCampaignEditView.as_view() new_name = "Test Campaign" new_end_datetime = datetime.datetime(year=2016, month=6, day=20) assert object.name != new_name assert object.end_datetime is None print(new_end_datetime) data = { "base-name": new_name, "base-public_name__en": "Test Campaign", "base-shop": get_default_shop().id, "base-active": True, "base-basket_line_text": "Test campaign activated!", "base-start_datetime": datetime.datetime(year=2016, month=6, day=19), "base-end_datetime": new_end_datetime } methods_before = CatalogCampaign.objects.count() # Conditions, effects and effects is tested separately with override_provides("campaign_context_condition", []): with override_provides("campaign_catalog_filter", []): with override_provides("campaign_product_discount_effect_form", []): request = apply_request_middleware(rf.post("/", data=data), user=admin_user) response = view(request, pk=object.pk) assert response.status_code in [200, 302] assert CatalogCampaign.objects.count() == methods_before updated_object = CatalogCampaign.objects.get(pk=object.pk) assert updated_object.name == new_name assert updated_object.end_datetime == new_end_datetime.replace( tzinfo=pytz.UTC)
def test_campaign_creation(rf, admin_user): """ To make things little bit more simple let's use only english as a language. """ with override_settings(LANGUAGES=[("en", "en")]): view = CatalogCampaignEditView.as_view() data = { "base-name": "Test Campaign", "base-public_name__en": "Test Campaign", "base-shop": get_default_shop().id, "base-active": True, "base-basket_line_text": "Test campaign activated!" } campaigns_before = CatalogCampaign.objects.count() request = apply_request_middleware(rf.post("/", data=data), user=admin_user) response = view(request, pk=None) assert response.status_code in [200, 302] assert CatalogCampaign.objects.count() == (campaigns_before + 1)