@pytest.mark.django_db
@pytest.mark.parametrize('view,model,service_provider_attr,get_provider', [(PaymentMethodEditView, PaymentMethod, 'payment_processor', get_custom_payment_processor), (ShippingMethodEditView, ShippingMethod, 'carrier', get_custom_carrier)])
def test_method_creation(rf, admin_user, view, model, service_provider_attr, get_provider):
 with override_settings(LANGUAGES=[('en', 'en')]):
  view = view.as_view()
  service_provider_field = ('base-%s' % service_provider_attr)
  data = {service_provider_field: get_provider().id, 'base-choice_identifier': 'manual', 'base-name__en': 'Custom method', 'base-shop': get_default_shop().id, 'base-tax_class': get_default_tax_class().id, 'base-enabled': True}
  methods_before = model.objects.count()
  url = ('/?provider=%s' % get_provider().id)
  request = apply_request_middleware(rf.post(url, data=data), user=admin_user)
  response = view(request, pk=None)
  if hasattr(response, 'render'):
   response.render()
  assert (response.status_code in [200, 302])
  assert (model.objects.count() == (methods_before + 1))

@ pytest . mark . django_db @ pytest . mark . parametrize ( 'view,model,service_provider_attr,get_provider' , [ ( PaymentMethodEditView , PaymentMethod , 'payment_processor' , get_custom_payment_processor ) , ( ShippingMethodEditView , ShippingMethod , 'carrier' , get_custom_carrier ) ] ) def test_method_creation ( rf , admin_user , view , model , service_provider_attr , get_provider ) : with override_settings ( LANGUAGES = [ ( 'en' , 'en' ) ] ) : view = view . as_view ( ) service_provider_field = ( 'base-%s' % service_provider_attr ) data = { service_provider_field : get_provider ( ) . id , 'base-choice_identifier' : 'manual' , 'base-name__en' : 'Custom method' , 'base-shop' : get_default_shop ( ) . id , 'base-tax_class' : get_default_tax_class ( ) . id , 'base-enabled' : True } methods_before = model . objects . count ( ) url = ( '/?provider=%s' % get_provider ( ) . id ) request = apply_request_middleware ( rf . post ( url , data = data ) , user = admin_user ) response = view ( request , pk = None ) if hasattr ( response , 'render' ) : response . render ( ) assert ( response . status_code in [ 200 , 302 ] ) assert ( model . objects . count ( ) == ( methods_before + 1 ) )
to make things little bit more simple lets use only english as an language .