def test_update_pack_g_per_cig(self): """test PackManager.update_pack_g_per_cig method""" paquet = Paquet.objects.create( user=self.usertest, type_cig='ROL', brand='TABACO', qt_paquet=40, price=15, g_per_cig=0.8, price_per_cig=0.3 ) self.assertEqual(paquet.g_per_cig, 0.8) self.assertEqual(paquet.price_per_cig, 0.3) datas ={ 'type_cig':'ROL', 'brand':'TABACO', 'qt_paquet':40, 'price':15, 'g_per_cig':0.6 } pack = PackManager(self.usertest, datas) pack.update_pack_g_per_cig() find_pack = Paquet.objects.get( id=paquet.id, ) self.assertEqual(find_pack.g_per_cig, Decimal('0.6')) self.assertEqual(find_pack.price_per_cig, Decimal('0.22'))
def change_g_per_cig(request): """ User can change the number of gr per cigarette and so chane the price of each cigarette """ if request.method == 'POST': form = PaquetFormCustomGInCig(request.user, request.POST) if form.is_valid(): change_pack = PackManager(request.user, form.cleaned_data) change_pack.update_pack_g_per_cig() return redirect('QuitSoonApp:paquets')