Esempio n. 1
0
 def test_delete_conso_cig(self):
     """test SmokeManager.delete_conso method"""
     smoke = SmokeManager(self.usertest, self.old_smoke_ind_data)
     smoke.delete_conso_cig()
     filter_conso = ConsoCig.objects.filter(user=self.usertest,
                                            paquet=self.db_pack_ind.id)
     self.assertFalse(filter_conso.exists())
Esempio n. 2
0
def smoke(request):
    """User smokes"""
    # check if packs are in parameters to fill fields with actual packs
    packs = Paquet.objects.filter(user=request.user, display=True)
    context = {'packs': packs}
    tz_offset = get_client_offset(request)
    update_dt_user_model_field(request.user, tz_offset)

    if packs:
        smoke_form = SmokeForm(request.user, tz_offset)
        if request.method == 'POST':
            smoke_form = SmokeForm(request.user, tz_offset, request.POST)
            if smoke_form.is_valid():
                smoky = SmokeManager(request.user, smoke_form.cleaned_data,
                                     tz_offset)
                smoky.create_conso_cig()
                return redirect('QuitSoonApp:today')
        context['smoke_form'] = smoke_form

    smoke_conso = ConsoCig.objects.filter(
        user=request.user).order_by('-datetime_cig')
    context['smoke'] = smoke_conso
    context['nb_smoke_today'] = smoke_conso.filter(
        datetime_cig__date=timezone.now().date()).count()
    if smoke_conso:
        last = smoke_conso.latest('datetime_cig').datetime_cig
        context['lastsmoke'] = get_delta_last_event(last)
    return render(request, 'QuitSoonApp/smoke.html', context)
Esempio n. 3
0
 def test_get_request_data(self):
     """test SmokeManager.get_request_data method"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     self.assertEqual(smoke.get_request_data('date_smoke'),
                      datetime.date(2020, 5, 17))
     self.assertEqual(smoke.get_request_data('time_smoke'),
                      datetime.time(13, 15))
     self.assertEqual(smoke.get_request_data('ind_pack_field'),
                      self.db_pack_ind.id)
Esempio n. 4
0
def delete_smoke(request, id_smoke):
    """
    Used when user click on the trash of one of his smocke action
    """
    if ConsoCig.objects.filter(user=request.user, id=id_smoke).exists():
        data = {'id_smoke': id_smoke}
        smoky = SmokeManager(request.user, data)
        smoky.delete_conso_cig()
        return redirect('QuitSoonApp:smoke_list')
    raise Http404()
Esempio n. 5
0
 def test_get_conso_cig_new_conso(self):
     """test SmokeManager.conso_cig method after creation object with new conso data"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     smoke.create_conso_cig()
     self.assertEqual(
         smoke.get_conso_cig,
         ConsoCig.objects.get(
             user=self.usertest,
             datetime_cig=smoke.datetime_cig,
             paquet=smoke.get_pack,
             given=smoke.given,
         ))
Esempio n. 6
0
 def test_create_conso_cig(self):
     """test SmokeManager.create_conso_cig method with new conso data"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     smoke.create_conso_cig()
     new_smoke = ConsoCig.objects.filter(user=self.usertest,
                                         datetime_cig=datetime.datetime(
                                             2020,
                                             5,
                                             17,
                                             13,
                                             15,
                                             tzinfo=pytz.utc),
                                         paquet=self.db_pack_ind,
                                         given=False)
     self.assertTrue(new_smoke.exists())
     self.assertEqual(smoke.get_pack.id, self.db_pack_ind.id)
Esempio n. 7
0
 def test_get_pack_rol(self):
     """
     test SmokeManager.get_pack method with new smoke data :
     given_field=False & type_cig_field='ROL'
     """
     smoke = SmokeManager(self.usertest, self.new_datas_rol)
     self.assertEqual(smoke.get_pack, self.db_pack_rol)
     self.assertEqual(smoke.get_pack, self.db_pack_rol)
Esempio n. 8
0
 def test_delete_conso_cig_given_cig(self):
     """test SmokeManager.delete_conso method with cig == given cig"""
     db_smoke_given = ConsoCig.objects.create(
         user=self.usertest,
         datetime_cig=datetime.datetime(2020,
                                        5,
                                        17,
                                        13,
                                        15,
                                        tzinfo=pytz.utc),
         paquet=None,
     )
     data = {'id_smoke': db_smoke_given.id}
     smoke = SmokeManager(self.usertest, data)
     smoke.delete_conso_cig()
     filter_conso = ConsoCig.objects.filter(user=self.usertest,
                                            id=db_smoke_given.id)
     self.assertFalse(filter_conso.exists())
Esempio n. 9
0
 def test_invalid_datetime(self):
     """test if date or time invalid in args"""
     data = {
         'date_smoke': 'invalid',
         'time_smoke': datetime.time(14, 15),
         'type_cig_field': 'ROL',
         'ind_pack_field': self.db_pack_ind.id,
         'rol_pack_field': self.db_pack_rol.id,
         'given_field': False,
     }
     smoke = SmokeManager(self.usertest, data)
     self.assertEqual(smoke.datetime_cig, None)
Esempio n. 10
0
 def test_create_conso_cig_given(self):
     """ test SmokeManager.create_conso_cig method with given=True """
     new_datas_given_cig = {
         'date_smoke': datetime.date(2020, 7, 15),
         'time_smoke': datetime.time(20, 15),
         'ind_pack_field': self.db_pack_ind.id,
         'rol_pack_field': self.db_pack_rol.id,
         'given_field': True,
     }
     smoke = SmokeManager(self.usertest, new_datas_given_cig)
     smoke.create_conso_cig()
     self.assertEqual(smoke.get_pack, None)
     new_given_smoke = ConsoCig.objects.filter(
         user=self.usertest,
         datetime_cig=datetime.datetime(2020,
                                        7,
                                        15,
                                        20,
                                        15,
                                        tzinfo=pytz.utc),
         paquet=None,
         given=True)
     self.assertTrue(new_given_smoke.exists())
Esempio n. 11
0
 def test_get_conso_cig_id_smoke(self):
     """test SmokeManager.conso_cig method with id_smoke in request"""
     smoke = SmokeManager(self.usertest, self.old_smoke_ind_data)
     self.assertEqual(smoke.get_conso_cig, self.db_smoke_ind)
Esempio n. 12
0
 def test_get_pack__given_cig(self):
     """test SmokeManager.get_pack method with new smoke data and given_field=True"""
     self.new_datas_ind['given_field'] = True
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     self.assertEqual(smoke.get_pack, None)
     self.assertEqual(smoke.get_pack, None)
Esempio n. 13
0
 def test_delete_conso_cig_fail(self):
     """test SmokeManager.delete_conso method failing cause wrong id"""
     smoke = SmokeManager(self.usertest, {'id_smoke': 17364})
     self.assertRaises(AttributeError, smoke.delete_conso_cig())
Esempio n. 14
0
 def test_get_pack_smoke_id(self):
     """test SmokeManager.get_pack method with id_smoke in data (for delete_smoke view)"""
     smoke = SmokeManager(self.usertest, self.old_smoke_ind_data)
     self.assertEqual(smoke.get_pack, self.db_pack_ind)
     self.assertEqual(smoke.get_pack, self.db_pack_ind)
Esempio n. 15
0
 def test_get_conso_cig_not_created(self):
     """test SmokeManager.conso_cig method without creating object with new conso data"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     self.assertEqual(smoke.get_conso_cig, None)
Esempio n. 16
0
 def test_get_pack_smoke_fail(self):
     """ test method get get_pack fail, exception raised cause wrong id"""
     smoke = SmokeManager(self.usertest, 10394)
     self.assertEqual(smoke.get_pack, None)
Esempio n. 17
0
 def test_create_conso_cig_datas_id_smoke(self):
     """test SmokeManager.create_conso_cig method with id_smoke in request"""
     smoke = SmokeManager(self.usertest, self.old_smoke_ind_data)
     self.assertEqual(smoke.create_conso_cig(), None)