def setUp(self):
     """setup tests"""
     self.user = User.objects.create_user(
         'NewUserTest', '*****@*****.**', 'testpassword')
     self.profile = UserProfile.objects.create(
         user=self.user,
         date_start="2019-09-28",
         starting_nb_cig=20
     )
     self.packs = Create_test_packs(self.user, row_paquet_data)
     self.packs.populate_test_db()
     self.smoke = Create_test_smoke(self.user, row_conso_cig_data)
     self.smoke.populate_test_db()
     self.stat = SmokeStats(self.user, datetime.date(2019, 11, 28))
예제 #2
0
 def setUp(self):
     """setup tests"""
     self.usertest = User.objects.create_user('NewUserTest',
                                              '*****@*****.**',
                                              'testpassword')
     self.profile = UserProfile.objects.create(user=self.usertest,
                                               date_start="2020-06-19",
                                               starting_nb_cig=20)
     self.packs = CreatePacks(self.usertest, row_paquet_data)
     self.packs.populate_db()
     self.smoke = CreateSmoke(self.usertest, fake_smoke)
     self.smoke.populate_db()
     self.stats = SmokeStats(
         self.usertest,
         make_aware(datetime.datetime(2020, 6, 20, 12, 0), pytz.utc), -120)
예제 #3
0
 def test_get_datetime_start_no_profile(self):
     """test get datetime while user didn't create a profile but saved a conso"""
     user = User.objects.create_user('testuser', '*****@*****.**',
                                     'testpassword')
     db_pack = Paquet.objects.create(
         user=self.usertest,
         type_cig='IND',
         brand='CAMEL',
         qt_paquet=20,
         price=10,
     )
     ConsoCig.objects.create(
         user=user,
         datetime_cig=datetime.datetime(2019,
                                        9,
                                        16,
                                        10,
                                        15,
                                        tzinfo=pytz.utc),
         paquet=db_pack,
     )
     stats = SmokeStats(
         user, make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc),
         -120)
     self.assertEqual(
         stats.datetime_start,
         make_aware(datetime.datetime(2019, 9, 16, 12, 15), pytz.utc))
예제 #4
0
 def setUp(self):
     """setup tests"""
     self.usertest = User.objects.create_user(username="******",
                                              email="*****@*****.**",
                                              password="******")
     self.profile = UserProfile.objects.create(
         user=self.usertest,
         date_start="2019-09-28",
         starting_nb_cig=20,
     )
     self.packs = CreatePacks(self.usertest, row_paquet_data)
     self.packs.populate_db()
     self.smoke = CreateSmoke(self.usertest, row_conso_cig_data)
     self.smoke.populate_db()
     self.stats = SmokeStats(
         self.usertest,
         make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc), -120)
예제 #5
0
 def test_get_aware_last_day(self):
     """test get last day including client tz_offset"""
     stats_no_tz = SmokeStats(
         self.usertest,
         make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc), 0)
     self.assertEqual(stats_no_tz.tz_offset, 0)
     self.assertEqual(stats_no_tz.lastday,
                      make_aware(datetime.datetime(2019, 11, 28, 12, 0)))
예제 #6
0
 def test_user_no_profile(self):
     """test create stats while user didn't create a profile"""
     user = User.objects.create_user('testuser', '*****@*****.**',
                                     'testpassword')
     stats = SmokeStats(
         user, make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc),
         -120)
     self.assertEqual(stats.starting_nb_cig, 0)
예제 #7
0
def today(request):
    """Welcome page if user.is_authenticated. Actions for the day"""
    context = {}
    tz_offset = get_client_offset(request)
    smoke_conso = ConsoCig.objects.filter(user=request.user)
    # update user_dt field
    update_dt_user_model_field(request.user, tz_offset)

    if UserProfile.objects.filter(user=request.user).exists():
        context['profile'] = True
        smoke_stats = SmokeStats(request.user, timezone.now(), tz_offset)
        user_now = timezone.now() - timedelta(minutes=tz_offset)
        if smoke_conso:
            context['smoke_today'] = smoke_stats.nb_per_day(user_now.date())
            last = smoke_conso.latest('datetime_cig').datetime_cig
            context['lastsmoke'] = get_delta_last_event(last)[0]
            context['average_number'] = round(smoke_stats.average_per_day)
    return render(request, 'QuitSoonApp/today.html', context)
예제 #8
0
def objectifs(request):
    """Page with user trophies and goals"""
    context = {}
    tz_offset = get_client_offset(request)
    stats = SmokeStats(request.user, timezone.now(), tz_offset)
    trophy = TrophyManager(stats)
    trophy.create_trophies()
    context['challenges'] = trophy.user_trophies
    return render(request, 'QuitSoonApp/objectifs.html', context)
예제 #9
0
 def test_nb_full_period_for_average_dates_first_and_last_day_of_month(
         self):
     """test method nb_full_period_for_average with complex dates"""
     user = User.objects.create_user('OtherUser', '*****@*****.**',
                                     'testpassword')
     UserProfile.objects.create(
         user=user,
         date_start="2019-12-01",
         starting_nb_cig=20,
     )
     stats = SmokeStats(
         user, make_aware(datetime.datetime(2019, 2, 1, 12, 0), pytz.utc),
         -120)
     self.assertEqual(
         stats.nb_full_period_for_average(datetime.date(2020, 2, 1), 'day'),
         62)
     self.assertEqual(
         stats.nb_full_period_for_average(datetime.date(2020, 2, 1),
                                          'week'), 8)
     self.assertEqual(
         stats.nb_full_period_for_average(datetime.date(2020, 2, 1),
                                          'month'), 2)
class SmokeStatsTestCase(TestCase):
    """class testing Create_test_smoke """

    def setUp(self):
        """setup tests"""
        self.user = User.objects.create_user(
            'NewUserTest', '*****@*****.**', 'testpassword')
        self.profile = UserProfile.objects.create(
            user=self.user,
            date_start="2019-09-28",
            starting_nb_cig=20
        )
        self.packs = Create_test_packs(self.user, row_paquet_data)
        self.packs.populate_test_db()
        self.smoke = Create_test_smoke(self.user, row_conso_cig_data)
        self.smoke.populate_test_db()
        self.stat = SmokeStats(self.user, datetime.date(2019, 11, 28))

    def test_get_missing_datas_smoke(self):
        self.assertEqual(self.stat.nb_per_day("2019-09-28"), 12)
        self.assertEqual(self.stat.nb_per_day("2019-09-22"), 0)

    def test_total_smoke(self):
        self.assertEqual(self.stat.total_smoke, 329)

    def test_average_per_day(self):
        self.assertEqual(self.stat.average_per_day, 5.306451612903226)

    def test_nb_jour_since_start(self):
        self.assertEqual(self.stat.nb_jour_since_start, 62)

    def test_count_smoking_day(self):
        self.assertEqual(self.stat.count_smoking_day, 57)

    def test_count_no_smoking_day(self):
        self.assertEqual(self.stat.count_no_smoking_day, 5)

    def test_no_smoking_day(self):
        self.assertEqual(
            self.stat.no_smoking_day,
            [datetime.date(2019, 11, 22),
             datetime.date(2019, 11, 24),
             datetime.date(2019, 11, 26),
             datetime.date(2019, 11, 27),
             datetime.date(2019, 11, 28)]
             )
        print(self.stat.total_money_smoked)
        print(self.stat.total_money_with_starting_nb_cig)
        print(self.stat.money_saved)
예제 #11
0
def report(request):
    """Page with user results, graphs..."""
    context = {}
    tz_offset = get_client_offset(request)
    update_dt_user_model_field(request.user, tz_offset)
    smoke_stats = SmokeStats(request.user, timezone.now(), tz_offset)
    healthy_stats = HealthyStats(request.user, timezone.now(), tz_offset)
    # graphs with smoke and health activities
    if smoke_stats.user_conso_all_days or healthy_stats.user_conso_all_days:
        # generate context
        context['smoky_report'] = smoky_report(smoke_stats)
        context['healthy_report'] = healthy_report(healthy_stats)
        return render(request, 'QuitSoonApp/report.html', context)
    context['no_data'] = True
    return render(request, 'QuitSoonApp/report.html', context)
예제 #12
0
 def setUp(self):
     """setup tests"""
     self.usertest = User.objects.create_user(username="******",
                                              email="*****@*****.**",
                                              password="******")
     self.profile = UserProfile.objects.create(user=self.usertest,
                                               date_start="2020-06-19",
                                               starting_nb_cig=20)
     self.packs = CreatePacks(self.usertest, row_paquet_data)
     self.packs.populate_db()
     self.smoke = CreateSmoke(self.usertest, fake_smoke_for_trophies)
     self.smoke.populate_db()
     stats = SmokeStats(
         self.usertest,
         make_aware(datetime.datetime(2020, 12, 31, 12, 0), pytz.utc), -120)
     self.check_trophy = TrophyManager(stats)
예제 #13
0
 def test_check_days_trophies(self):
     """
     test method check_days_trophies
     for element in occurence, check if >= element in trophy to succeed list
     return list of trophies to create
     """
     ConsoCig.objects.filter(
         user=self.usertest,
         datetime_cig__gte=dt(2020, 7, 5, 23, 59,
                              tzinfo=pytz.utc)).delete()
     stats = SmokeStats(self.usertest,
                        make_aware(dt(2020, 6, 26, 12, 0), pytz.utc), -120)
     check_trophy = TrophyManager(stats)
     self.assertTrue(check_trophy.check_days_trophies(challenge=(15, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(15, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(10, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(10, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(5, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(5, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(4, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(4, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(3, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(3, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(2, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(2, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(1, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(1, 7)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(0, 1)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(0, 2)))
     self.assertTrue(check_trophy.check_days_trophies(challenge=(0, 3)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 4)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 7)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 10)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 15)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 20)))
     self.assertFalse(check_trophy.check_days_trophies(challenge=(0, 25)))
예제 #14
0
    def test_trophies_accomplished(self):
        """test method trophies_accomplished"""
        self.check_trophy.trophies_accomplished()
        self.assertEqual(
            self.check_trophy.user_trophies, {
                (15, 3): True,
                (15, 7): True,
                (10, 3): True,
                (10, 7): True,
                (5, 3): True,
                (5, 7): True,
                (4, 3): True,
                (4, 7): True,
                (3, 3): True,
                (3, 7): True,
                (2, 3): True,
                (2, 7): True,
                (1, 3): True,
                (1, 7): True,
                (0, 1): True,
                (0, 2): True,
                (0, 3): True,
                (0, 4): True,
                (0, 7): True,
                (0, 10): True,
                (0, 15): True,
                (0, 20): True,
                (0, 25): True,
                (0, 30): True,
                (0, 60): True,
                (0, 90): False,
                (0, 120): False,
                (0, 150): False,
                (0, 180): False,
                (0, 210): False,
                (0, 240): False,
                (0, 270): False,
                (0, 300): False,
                (0, 330): False
            })
        # test with less days non smoked
        Trophy.objects.filter(user=self.usertest).delete()
        ConsoCig.objects.filter(
            user=self.usertest,
            datetime_cig__gte=dt(2020, 7, 5, 23, 59,
                                 tzinfo=pytz.utc)).delete()
        stats = SmokeStats(self.usertest,
                           make_aware(dt(2020, 6, 26, 12, 0), pytz.utc), -120)

        check_trophy = TrophyManager(stats)
        check_trophy.trophies_accomplished()
        self.assertEqual(
            check_trophy.user_trophies, {
                (15, 3): True,
                (15, 7): False,
                (10, 3): True,
                (10, 7): False,
                (5, 3): True,
                (5, 7): False,
                (4, 3): True,
                (4, 7): False,
                (3, 3): True,
                (3, 7): False,
                (2, 3): True,
                (2, 7): False,
                (1, 3): True,
                (1, 7): False,
                (0, 1): True,
                (0, 2): True,
                (0, 3): True,
                (0, 4): False,
                (0, 7): False,
                (0, 10): False,
                (0, 15): False,
                (0, 20): False,
                (0, 25): False,
                (0, 30): False,
                (0, 60): False,
                (0, 90): False,
                (0, 120): False,
                (0, 150): False,
                (0, 180): False,
                (0, 210): False,
                (0, 240): False,
                (0, 270): False,
                (0, 300): False,
                (0, 330): False
            })
        # test first day
        ConsoCig.objects.filter(user=self.usertest).delete()
        Trophy.objects.filter(user=self.usertest).delete()
        stats = SmokeStats(
            self.usertest,
            make_aware(datetime.datetime(2020, 6, 19, 12, 0), pytz.utc), -120)
        check_trophy = TrophyManager(stats)
        check_trophy.trophies_accomplished()
        self.assertEqual(
            check_trophy.user_trophies, {
                (15, 3): False,
                (15, 7): False,
                (10, 3): False,
                (10, 7): False,
                (5, 3): False,
                (5, 7): False,
                (4, 3): False,
                (4, 7): False,
                (3, 3): False,
                (3, 7): False,
                (2, 3): False,
                (2, 7): False,
                (1, 3): False,
                (1, 7): False,
                (0, 1): False,
                (0, 2): False,
                (0, 3): False,
                (0, 4): False,
                (0, 7): False,
                (0, 10): False,
                (0, 15): False,
                (0, 20): False,
                (0, 25): False,
                (0, 30): False,
                (0, 60): False,
                (0, 90): False,
                (0, 120): False,
                (0, 150): False,
                (0, 180): False,
                (0, 210): False,
                (0, 240): False,
                (0, 270): False,
                (0, 300): False,
                (0, 330): False
            })
예제 #15
0
class SmokeStatsTestCaseBigData(TestCase):
    """class testing CreateSmoke """
    def setUp(self):
        """setup tests"""
        self.usertest = User.objects.create_user(username="******",
                                                 email="*****@*****.**",
                                                 password="******")
        self.profile = UserProfile.objects.create(
            user=self.usertest,
            date_start="2019-09-28",
            starting_nb_cig=20,
        )
        self.packs = CreatePacks(self.usertest, row_paquet_data)
        self.packs.populate_db()
        self.smoke = CreateSmoke(self.usertest, row_conso_cig_data)
        self.smoke.populate_db()
        self.stats = SmokeStats(
            self.usertest,
            make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc), -120)

    def test_user_no_profile(self):
        """test create stats while user didn't create a profile"""
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpassword')
        stats = SmokeStats(
            user, make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc),
            -120)
        self.assertEqual(stats.starting_nb_cig, 0)

    def test_get_aware_last_day(self):
        """test get last day including client tz_offset"""
        stats_no_tz = SmokeStats(
            self.usertest,
            make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc), 0)
        self.assertEqual(stats_no_tz.tz_offset, 0)
        self.assertEqual(stats_no_tz.lastday,
                         make_aware(datetime.datetime(2019, 11, 28, 12, 0)))

    def test_get_datetime_start_with_profile(self):
        """test get sarting app datetime including tz_offset"""
        self.assertEqual(
            self.stats.datetime_start,
            make_aware(datetime.datetime(2019, 9, 28, 11, 0), pytz.utc))

    def test_get_datetime_start_no_profile(self):
        """test get datetime while user didn't create a profile but saved a conso"""
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpassword')
        db_pack = Paquet.objects.create(
            user=self.usertest,
            type_cig='IND',
            brand='CAMEL',
            qt_paquet=20,
            price=10,
        )
        ConsoCig.objects.create(
            user=user,
            datetime_cig=datetime.datetime(2019,
                                           9,
                                           16,
                                           10,
                                           15,
                                           tzinfo=pytz.utc),
            paquet=db_pack,
        )
        stats = SmokeStats(
            user, make_aware(datetime.datetime(2019, 11, 28, 12, 0), pytz.utc),
            -120)
        self.assertEqual(
            stats.datetime_start,
            make_aware(datetime.datetime(2019, 9, 16, 12, 15), pytz.utc))

    def test_nb_full_period_for_average(self):
        """test method calculating nb_full periods in order to calculate average"""
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2019, 11, 28),
                                                  'day'), 61)
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2019, 11, 28),
                                                  'week'), 8)
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2019, 11, 28),
                                                  'month'), 1)
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2020, 8, 5),
                                                  'day'), 312)
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2020, 8, 5),
                                                  'week'), 44)
        self.assertEqual(
            self.stats.nb_full_period_for_average(datetime.date(2020, 8, 5),
                                                  'month'), 10)

    def test_nb_full_period_for_average_dates_first_and_last_day_of_month(
            self):
        """test method nb_full_period_for_average with complex dates"""
        user = User.objects.create_user('OtherUser', '*****@*****.**',
                                        'testpassword')
        UserProfile.objects.create(
            user=user,
            date_start="2019-12-01",
            starting_nb_cig=20,
        )
        stats = SmokeStats(
            user, make_aware(datetime.datetime(2019, 2, 1, 12, 0), pytz.utc),
            -120)
        self.assertEqual(
            stats.nb_full_period_for_average(datetime.date(2020, 2, 1), 'day'),
            62)
        self.assertEqual(
            stats.nb_full_period_for_average(datetime.date(2020, 2, 1),
                                             'week'), 8)
        self.assertEqual(
            stats.nb_full_period_for_average(datetime.date(2020, 2, 1),
                                             'month'), 2)

    def test_update_models_dt_user(self):
        """test method update_dt_user_model_field with actual timedelta tz_offset"""
        conso = ConsoCig.objects.get(user=self.usertest,
                                     datetime_cig=datetime.datetime(
                                         2019, 9, 28, 9, 0, tzinfo=pytz.utc))
        self.assertEqual(
            conso.user_dt,
            datetime.datetime(2019, 9, 28, 11, 0, tzinfo=pytz.utc))

    def test_get_nb_per_day_smoke(self):
        """test method get_nb_per_day_smoke"""
        self.assertEqual(self.stats.nb_per_day(datetime.date(2019, 9, 28)), 12)
        self.assertEqual(self.stats.nb_per_day(datetime.date(2019, 9, 22)), 0)

    def test_total_smoke_all_days(self):
        """test method total_smoke"""
        self.assertEqual(self.stats.total_smoke, 329)

    def test_total_smoke(self):
        """test method total_smoke"""
        self.assertEqual(self.stats.total_smoke, 329)

    def test_average_per_day(self):
        """test method average_per_day"""
        self.assertEqual(round(self.stats.average_per_day), 5)

    def test_nb_jour_since_start(self):
        """test method nb_jour_since_start"""
        self.assertEqual(self.stats.nb_full_days_since_start, 61)

    def test_count_smoking_day(self):
        """test method count_smoking_day"""
        self.assertEqual(self.stats.count_smoking_day, 57)

    def test_count_no_smoking_day(self):
        """test method count_no_smoking_day"""
        self.assertEqual(self.stats.count_no_smoking_day, 4)

    def test_total_cig_with_old_habits(self):
        """test method total_cig_with_old_habits"""
        self.assertEqual(self.stats.total_cig_with_old_habits, 1220)

    def test_nb_not_smoked_cig_full_days(self):
        """test method nb_not_smoked_cig"""
        self.assertEqual(self.stats.nb_not_smoked_cig, 891)

    def test_list_dates(self):
        """test method list_dates"""
        self.assertEqual(len(self.stats.list_dates), 62)
        self.assertEqual(self.stats.list_dates[0], datetime.date(2019, 9, 28))
        self.assertEqual(self.stats.list_dates[-1],
                         datetime.date(2019, 11, 28))

    def test_no_smoking_day_list_dates(self):
        """test method no_smoking_day_list_dates"""
        self.assertEqual(self.stats.no_smoking_day_list_dates, [
            datetime.date(2019, 11, 22),
            datetime.date(2019, 11, 24),
            datetime.date(2019, 11, 25),
            datetime.date(2019, 11, 27),
            datetime.date(2019, 11, 28)
        ])

    def test_money_smoked_per_day(self):
        """test method money_smoked_per_day"""
        self.assertEqual(
            round(self.stats.money_smoked_per_day("2019-09-28"), 2),
            Decimal('5.66'))

    def test_total_money_smoked(self):
        """test method total_money_smoked """
        self.assertEqual(self.stats.total_money_smoked, Decimal('159.155'))

    def test_average_money_per_day(self):
        """test method average_money_per_day"""
        self.assertEqual(round(self.stats.average_money_per_day, 2),
                         Decimal('2.61'))

    def test_total_money_with_starting_nb_cig(self):
        """test method total_money_with_starting_nb_cig"""
        self.assertEqual(round(self.stats.total_money_with_starting_nb_cig, 2),
                         Decimal('591.70'))

    def test_money_saved(self):
        """test method money_saved"""
        self.assertEqual(self.stats.money_saved, Decimal('432.54'))
예제 #16
0
class SmokeStatsTestCaseSmallData(TestCase):
    """class testing CreateSmoke """
    def setUp(self):
        """setup tests"""
        self.usertest = User.objects.create_user('NewUserTest',
                                                 '*****@*****.**',
                                                 'testpassword')
        self.profile = UserProfile.objects.create(user=self.usertest,
                                                  date_start="2020-06-19",
                                                  starting_nb_cig=20)
        self.packs = CreatePacks(self.usertest, row_paquet_data)
        self.packs.populate_db()
        self.smoke = CreateSmoke(self.usertest, fake_smoke)
        self.smoke.populate_db()
        self.stats = SmokeStats(
            self.usertest,
            make_aware(datetime.datetime(2020, 6, 20, 12, 0), pytz.utc), -120)

    def test_get_user_conso(self):
        """test method get_user_conso"""
        self.assertEqual(self.stats.get_user_conso().count(), 17)
        self.assertEqual(self.stats.stats_user_conso.count(), 17)

    def test_get_nb_per_day_smoke(self):
        """test method get_nb_per_day_smoke"""
        self.assertEqual(self.stats.nb_per_day(datetime.date(2020, 6, 19)), 17)
        self.assertEqual(self.stats.nb_per_day(datetime.date(2020, 6, 20)), 16)

    def test_money_smoked_per_day(self):
        """test method money_smoked_per_day"""
        self.assertEqual(self.stats.money_smoked_per_day("2020-06-19"),
                         Decimal('8.24'))
        self.assertEqual(self.stats.money_smoked_per_day("2020-06-20"),
                         Decimal('7.76'))

    def test_total_cig_with_old_habits(self):
        """test method total_cig_with_old_habits"""
        self.assertEqual(self.stats.total_cig_with_old_habits, 20)

    def test_nb_not_smoked_cig_full_days(self):
        """test method nb_not_smoked_cig"""
        self.assertEqual(self.stats.nb_not_smoked_cig, 3)

    def test_average_money_per_day(self):
        """test method average_money_per_day"""
        self.assertEqual(self.stats.average_money_per_day, Decimal('8.245'))

    def test_list_dates(self):
        """test method list_dates"""
        self.assertEqual(len(self.stats.list_dates), 2)
        self.assertEqual(
            self.stats.list_dates,
            [datetime.date(2020, 6, 19),
             datetime.date(2020, 6, 20)])

    def test_total_money_smoked(self):
        """test method total_money_smoked"""
        self.assertEqual(self.stats.total_money_smoked, Decimal('8.245'))

    def test_total_money_with_starting_nb_cig(self):
        """test method total_money_with_starting_nb_cig"""
        self.assertEqual(self.stats.total_money_with_starting_nb_cig,
                         Decimal('9.7'))

    def test_money_saved(self):
        """test method money_saved"""
        self.assertEqual(self.stats.money_saved, Decimal('1.46'))
예제 #17
0
class StatsFirstDay(TestCase):
    """class testing Stats while first day """
    def setUp(self):
        """setup tests"""
        self.usertest = User.objects.create_user('NewUserTest',
                                                 '*****@*****.**',
                                                 'testpassword')
        self.profile = UserProfile.objects.create(user=self.usertest,
                                                  date_start="2020-06-19",
                                                  starting_nb_cig=20)
        self.packs = CreatePacks(self.usertest, row_paquet_data)
        self.packs.populate_db()
        self.smoke = CreateSmoke(self.usertest, fake_smoke)
        self.smoke.populate_db()
        ConsoCig.objects.filter(
            user=self.usertest,
            datetime_cig__gt=datetime.datetime(2020,
                                               6,
                                               19,
                                               22,
                                               0,
                                               tzinfo=pytz.utc)).delete()
        self.stats = SmokeStats(
            self.usertest,
            make_aware(datetime.datetime(2020, 6, 19, 23, 59), pytz.utc), -120)

    def test_first_day(self):
        """test first day user use app"""
        self.assertTrue(self.stats.first_day)

    def test_get_user_conso(self):
        """test method get_user_conso"""
        self.assertEqual(self.stats.get_user_conso().count(), 17)
        self.assertEqual(self.stats.stats_user_conso.count(), 17)

    def test_total_smoke_all_days(self):
        """test method total_smoke_all_days for first day user"""
        self.assertEqual(self.stats.total_smoke_all_days, 17)

    def test_average_per_day(self):
        """test method average_per_day for first day user"""
        self.assertEqual(self.stats.average_per_day, 17)

    def test_count_no_smoking_day(self):
        """test method count_no_smoking_day for first day user"""
        self.assertEqual(self.stats.count_no_smoking_day, 0)

    def test_total_cig_with_old_habits(self):
        """test method total_cig_with_old_habits for first day user"""
        self.assertEqual(self.stats.total_cig_with_old_habits, 20)

    def test_nb_not_smoked_cig_full_days(self):
        """test method nb_not_smoked_cig for first day user"""
        self.assertEqual(self.stats.nb_not_smoked_cig, 3)

    def test_total_money_smoked(self):
        """test method total_money_smoked for first day user"""
        self.assertEqual(self.stats.total_money_smoked, Decimal('8.245'))

    def test_average_money_per_day(self):
        """test method average_money_per_day for first day user"""
        self.assertEqual(self.stats.average_money_per_day,
                         self.stats.total_money_smoked)

    def test_total_money_with_starting_nb_cig(self):
        """test method money_with_starting_nb_cig for first day user"""
        self.assertEqual(self.stats.total_money_with_starting_nb_cig,
                         Decimal('9.700'))

    def test_money_saved(self):
        """test method money_saved for first day user"""
        self.assertEqual(self.stats.money_saved, Decimal('1.46'))

    def test_average_alternative_first_day(self):
        """test method average_alternative for first day user"""
        alternatives = CreateAlternative(self.usertest, row_alternative_data)
        alternatives.populate_db()
        ConsoAlternative.objects.create(
            user=self.usertest,
            datetime_alter=datetime.datetime(2020,
                                             6,
                                             19,
                                             11,
                                             55,
                                             tzinfo=pytz.utc),
            alternative=Alternative.objects.get(id=1001),
            activity_duration=40)
        ConsoAlternative.objects.create(
            user=self.usertest,
            datetime_alter=datetime.datetime(2020,
                                             6,
                                             19,
                                             13,
                                             30,
                                             tzinfo=pytz.utc),
            alternative=Alternative.objects.get(id=1004),
        )
        stats = HealthyStats(
            self.usertest,
            make_aware(datetime.datetime(2020, 6, 19, 23, 59), pytz.utc), -120)
        self.assertTrue(stats.first_day)