def test_delete_used_alternative_substitut(self):
     """test SavePack.delete_alternative method with used alternative"""
     db_alternative = Alternative.objects.create(
         user=self.usertest,
         type_alternative='Su',
         substitut='ECIG',
         nicotine=2.0,
     )
     ConsoAlternative.objects.create(
         user=self.usertest,
         datetime_alter=datetime.datetime(2020,
                                          5,
                                          13,
                                          13,
                                          55,
                                          tzinfo=pytz.utc),
         alternative=db_alternative,
     )
     data = {'id_alternative': db_alternative.id}
     alternative = AlternativeManager(self.usertest, data)
     alternative.delete_alternative()
     filter_alternative = Alternative.objects.filter(
         user=self.usertest,
         type_alternative='Su',
         substitut='ECIG',
         nicotine=2.0,
     )
     self.assertTrue(filter_alternative.exists())
     self.assertEqual(filter_alternative[0].display, False)
 def test_delete_used_alternative_activity(self):
     """test SavePack.delete_alternative method with used alternative"""
     db_alternative = Alternative.objects.create(
         user=self.usertest,
         type_alternative='Ac',
         type_activity='So',
         activity='PSYCHOLOGUE',
     )
     ConsoAlternative.objects.create(
         user=self.usertest,
         datetime_alter=datetime.datetime(2020,
                                          5,
                                          13,
                                          13,
                                          55,
                                          tzinfo=pytz.utc),
         alternative=db_alternative,
     )
     data = {'id_alternative': db_alternative.id}
     alternative = AlternativeManager(self.usertest, data)
     alternative.delete_alternative()
     filter_alternative = Alternative.objects.filter(
         user=self.usertest,
         type_alternative='Ac',
         type_activity='So',
         activity='PSYCHOLOGUE',
     )
     self.assertTrue(filter_alternative.exists())
     self.assertEqual(filter_alternative[0].display, False)
Пример #3
0
def delete_alternative(request, id_alternative):
    """
    Used when user click on the trash of one of the alternative
    Don't delete it but change display attribute into False if already used in ConsoAlternative
    """
    if Alternative.objects.filter(user=request.user,
                                  id=id_alternative).exists():
        data = {'id_alternative': id_alternative}
        new_alternative = AlternativeManager(request.user, data)
        new_alternative.delete_alternative()
        return redirect('QuitSoonApp:alternatives')
    raise Http404()
 def test_delete_unused_alternative_substitut(self):
     """test AlternativeManager.delete_alternative method with unused alternative"""
     db_alternative = Alternative.objects.create(
         user=self.usertest,
         type_alternative='Su',
         substitut='ECIG',
         nicotine=2.0,
     )
     data = {'id_alternative': db_alternative.id}
     alternative = AlternativeManager(self.usertest, data)
     alternative.delete_alternative()
     filter_alternative = Alternative.objects.filter(
         user=self.usertest,
         type_alternative='Su',
         substitut='ECIG',
         nicotine=2.0,
     )
     self.assertFalse(filter_alternative.exists())
 def test_delete_unused_alternative_activity(self):
     """test AlternativeManager.delete_alternative method with unused alternative"""
     db_alternative = Alternative.objects.create(
         user=self.usertest,
         type_alternative='Ac',
         type_activity='So',
         activity='PSYCHOLOGUE',
     )
     data = {'id_alternative': db_alternative.id}
     alternative = AlternativeManager(self.usertest, data)
     alternative.delete_alternative()
     filter_alternative = Alternative.objects.filter(
         user=self.usertest,
         type_alternative='Ac',
         type_activity='So',
         activity='PSYCHOLOGUE',
     )
     self.assertFalse(filter_alternative.exists())