# Path: clubManagement/models.py
# class StatusUpdate(models.Model):
#     """
#     The status update for each data is stored as a string
#     `user_id1 Y/N, user_id Y/N, .....`
#     """
#     date = models.DateField()
#     value = models.CharField(max_length=1000)
#     data = models.CharField(max_length=5000, blank=True)
# 
#     def get_value_dict(self):
#         status_list = self.value.split(', ')
#         status_dict = {}
# 
#         for status in status_list:
#             user_id, status = status.split(' ')
#             status_dict[int(user_id)] = status
# 
#         return status_dict
# 
#     def process_report(self):
#         """
#         saves a dict with key as the year and value as a list of user to the
#         data field
#         list-of-users = [[user, status]] where status is  a string with default
#         value N
#         :return:  {'year': {'name': 'full_name', 'status': 'Y'}}
#         """
#         status_dict = self.get_value_dict()
# 
#         # no status reports found
#         if not status_dict:
#             return
# 
#         start_year = date.today().year
# 
#         if date.today().month < 8:
#             start_year -= 1
# 
#         user_data = {}
# 
#         for year in range(start_year, start_year - 4, -1):
#             user_info_list = UserInfo.objects.filter(year=year)
#             user_list = {}
#             for user_info in user_info_list:
#                 if user_info.user.is_active and not user_info.is_mentor:
#                     status = status_dict.get(int(user_info.user.pk), None)
#                     if status:
#                         user_list[user_info.user.get_full_name()] = status
#                     else:
#                         user_list[user_info.user.get_full_name()] = 'N'
# 
#             if user_list:
#                 user_data[str(year)] = user_list
# 
#         self.data = json.dumps(user_data)
#         self.save()
# 
#     def get_report(self):
#         """
#         Returns a dict with {'year': {'name': 'full_name', 'status': 'Y'}}
#         :return: dict
#         """
#         if not self.data:
#             self.process_report()
#         return json.loads(self.data)
# 
#     def __str__(self):
#         return str(self.date)


import json
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
from django.utils.datetime_safe import date
from clubManagement.models import StatusUpdate
from registration.models import UserInfo

        report = {
            str(self.today.year-1): {str(user1.get_full_name()): 'Y'},
            str(self.today.year-2): {str(user2.get_full_name()): 'N'}
        }

        status_update.process_report()

        self.assertEqual(status_update.data, json.dumps(report))


class StatusUpdateDetailViewTest(TestCase):

    def test_view_loads_correct_data(self):
        today = date.today()

        user1 = User.objects.create(
            username='user1', email='user@email.com', password='pass',
            first_name='User', last_name='1', is_active=True
        )
        user2 = User.objects.create(
            username='user2', email='user@email.com', password='pass',
            first_name='User', last_name='2', is_active=True
        )

        UserInfo.objects.create(user=user1, year=today.year - 1)
        UserInfo.objects.create(user=user2, year=today.year - 2)

        value = str(user1.pk) + ' Y, ' + str(user2.pk) + ' N'


# Path: clubManagement/models.py
# class StatusUpdate(models.Model):
#     """
#     The status update for each data is stored as a string
#     `user_id1 Y/N, user_id Y/N, .....`
#     """
#     date = models.DateField()
#     value = models.CharField(max_length=1000)
#     data = models.CharField(max_length=5000, blank=True)
# 
#     def get_value_dict(self):
#         status_list = self.value.split(', ')
#         status_dict = {}
# 
#         for status in status_list:
#             user_id, status = status.split(' ')
#             status_dict[int(user_id)] = status
# 
#         return status_dict
# 
#     def process_report(self):
#         """
#         saves a dict with key as the year and value as a list of user to the
#         data field
#         list-of-users = [[user, status]] where status is  a string with default
#         value N
#         :return:  {'year': {'name': 'full_name', 'status': 'Y'}}
#         """
#         status_dict = self.get_value_dict()
# 
#         # no status reports found
#         if not status_dict:
#             return
# 
#         start_year = date.today().year
# 
#         if date.today().month < 8:
#             start_year -= 1
# 
#         user_data = {}
# 
#         for year in range(start_year, start_year - 4, -1):
#             user_info_list = UserInfo.objects.filter(year=year)
#             user_list = {}
#             for user_info in user_info_list:
#                 if user_info.user.is_active and not user_info.is_mentor:
#                     status = status_dict.get(int(user_info.user.pk), None)
#                     if status:
#                         user_list[user_info.user.get_full_name()] = status
#                     else:
#                         user_list[user_info.user.get_full_name()] = 'N'
# 
#             if user_list:
#                 user_data[str(year)] = user_list
# 
#         self.data = json.dumps(user_data)
#         self.save()
# 
#     def get_report(self):
#         """
#         Returns a dict with {'year': {'name': 'full_name', 'status': 'Y'}}
#         :return: dict
#         """
#         if not self.data:
#             self.process_report()
#         return json.loads(self.data)
# 
#     def __str__(self):
#         return str(self.date)


# Path: clubManagement/tests.py
import json
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
from django.utils.datetime_safe import date
from clubManagement.models import StatusUpdate
from registration.models import UserInfo


        report = {
            str(self.today.year-1): {str(user1.get_full_name()): 'Y'},
            str(self.today.year-2): {str(user2.get_full_name()): 'N'}
        }

        status_update.process_report()

        self.assertEqual(status_update.data, json.dumps(report))


class StatusUpdateDetailViewTest(TestCase):

    def test_view_loads_correct_data(self):
        today = date.today()

        user1 = User.objects.create(
            username='user1', email='user@email.com', password='pass',
            first_name='User', last_name='1', is_active=True
        )
        user2 = User.objects.create(
            username='user2', email='user@email.com', password='pass',
            first_name='User', last_name='2', is_active=True
        )

        UserInfo.objects.create(user=user1, year=today.year - 1)
        UserInfo.objects.create(user=user2, year=today.year - 2)

        value = str(user1.pk) + ' Y, ' + str(user2.pk) + ' N'


        StatusUpdate.objects.create(