Beispiel #1
0
 def test_delete_used_pack_ind(self):
     """test PackManager.delete_pack method with used pack"""
     db_pack = Paquet.objects.create(
         user=self.usertest,
         type_cig='IND',
         brand='ELPASO',
         qt_paquet=5,
         price=10,
         )
     ConsoCig.objects.create(
         user=self.usertest,
         date_cig=datetime.date(2020, 5, 13),
         time_cig=datetime.time(13, 55),
         paquet=db_pack,
     )
     datas ={'id_pack': db_pack.id}
     pack = PackManager(self.usertest, datas)
     pack.delete_pack()
     filter_pack = Paquet.objects.filter(
         user=self.usertest,
         type_cig='IND',
         brand='ELPASO',
         qt_paquet=5,
         price=10,
         )
     self.assertTrue(filter_pack.exists())
     self.assertEqual(filter_pack[0].display, False)
Beispiel #2
0
def delete_pack(request, id_pack):
    """
    Used when user click on the trash of one of the paquet
    Don't delete it but change display attribute into False if already used
    """
    if Paquet.objects.filter(user=request.user, id=id_pack).exists():
        data = {'id_pack': id_pack}
        new_pack = PackManager(request.user, data)
        new_pack.delete_pack()
        return redirect('QuitSoonApp:paquets')
    # asked out of form so not expected request from user
    raise Http404()
 def test_delete_unused_pack_ind(self):
     """test PackManager.delete_pack method with unused pack"""
     db_pack = Paquet.objects.create(
         user=self.usertest,
         type_cig='IND',
         brand='CAMEL',
         qt_paquet=20,
         price=10,
     )
     data = {'id_pack': db_pack.id}
     pack = PackManager(self.usertest, data)
     pack.delete_pack()
     self.assertFalse(Paquet.objects.filter(id=db_pack.id).exists())