def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.second_cell = Cell.objects.create( name="my second cell", address=self.address, ) self.cycle = Cycle.objects.create( name="my cycle", ) self.second_cycle = Cycle.objects.create( name="my second cycle", ) self.task_type = TaskType.objects.create( name="my tasktype", ) self.second_task_type = TaskType.objects.create( name="my second tasktype", ) start_date = timezone.now() end_date = start_date + timezone.timedelta( minutes=100, ) self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.tasktype = TaskType.objects.create(name='TaskType 1', )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="Random Country", iso_code="RC", )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.cycle = Cycle.objects.create( name='Cycle 1', start_date=timezone.now(), end_date=timezone.now() + timezone.timedelta(minutes=100, ), )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password("Test123!") self.user.save() self.admin = AdminFactory() self.admin.set_password("Test123!") self.admin.save() self.random_country = Country.objects.create( name="Random Country 1", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="Random StateProvince 1", iso_code="RS", country=self.random_country)
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.user_cell_manager = UserFactory() self.user_cell_manager.set_password('Test123!') self.user_cell_manager.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.second_cell = Cell.objects.create( name="my second cell", address=self.address, ) self.cell_with_manager = Cell.objects.create( name="my cell with manager", address=self.address, ) self.cell_with_manager.save() self.cell_with_manager.managers = [self.user_cell_manager, ] self.cell_with_manager.save() self.cycle = Cycle.objects.create( name="my cycle", ) self.task_type = TaskType.objects.create( name="my tasktype", ) start_date = timezone.now() - timezone.timedelta( minutes=100, ) end_date = start_date + timezone.timedelta( minutes=50, ) self.cycle_inactive = Cycle.objects.create( name="my cycle", start_date=start_date, end_date=end_date ) # Some date INSIDE the cycle range start_date = start_date + timezone.timedelta( minutes=2, ) end_date = end_date - timezone.timedelta( minutes=1, ) self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_second_cell = Event.objects.create( cell=self.second_cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_inactive = Event.objects.create( cell=self.cell, cycle=self.cycle_inactive, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_inactive_second_cel = Event.objects.create( cell=self.second_cell, cycle=self.cycle_inactive, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_with_manager = Event.objects.create( cell=self.cell_with_manager, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) # Decrement start_date for event_2 start_date = start_date - timezone.timedelta( minutes=1, ) self.event_2 = Event.objects.create( cell=self.cell, cycle=self.cycle_inactive, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_2 = Event.objects.create( cell=self.second_cell, cycle=self.cycle_inactive, task_type=self.task_type, start_date=start_date, end_date=end_date, )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.user2 = UserFactory() self.user2.set_password('Test123!') self.user2.save() self.user_cell_manager = UserFactory() self.user_cell_manager.set_password('Test123!') self.user_cell_manager_no_perms = UserFactory() self.user_cell_manager_no_perms.set_password('Test123!') self.user_cell_manager_no_perms.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.cell_with_manager = Cell.objects.create( name="my cell with manager", address=self.address, ) self.cell_with_manager.managers = [ self.user_cell_manager, ] self.cell_with_manager.save() self.cycle = Cycle.objects.create(name="my cycle", ) self.task_type = TaskType.objects.create(name="my tasktype", ) start_date = timezone.now() + timezone.timedelta(minutes=100, ) end_date = start_date + timezone.timedelta(minutes=100, ) self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event2 = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event_with_manager = Event.objects.create( cell=self.cell_with_manager, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) subscription_date = timezone.now() with mock.patch('django.utils.timezone.now') as mock_now: mock_now.return_value = subscription_date self.participation = Participation.objects.create( standby=True, subscription_date=subscription_date, user=self.user, event=self.event2, ) self.participation2 = Participation.objects.create( standby=True, subscription_date=subscription_date, user=self.user2, event=self.event2, ) self.participation_cell_manager = Participation.objects.create( standby=True, subscription_date=subscription_date, user=self.user2, event=self.event_with_manager, )
def test_cycle_generate_report_data_error(self): self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.cycle = Cycle.objects.create( name="my cycle", ) self.task_type = TaskType.objects.create( name="my tasktype", ) event_start_date = timezone.now() self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=event_start_date, end_date=event_start_date + timezone.timedelta(minutes=100), ) self.participation = Participation.objects.create( standby=True, user=self.admin, event=self.event, ) self.event_2 = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=event_start_date, end_date=event_start_date + timezone.timedelta(minutes=100), ) self.participation_presence = Participation.objects.create( standby=True, user=self.admin, event=self.event_2, presence_status='P', presence_duration_minutes=300, ) # Test error case test_data_error = { 'error': 'All of the Participations presence ' 'status must be initialised.', } data = self.cycle.generate_participation_report_data() self.assertEqual(data, test_data_error) # Test normal case self.participation.presence_status = 'A' self.participation.save() data = self.cycle.generate_participation_report_data() test_data = { self.admin.pk: { 'first_name': self.admin.first_name, 'last_name': self.admin.last_name, 'email': self.admin.email, 'total_time': 300, } } self.assertEqual(data, test_data)
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.cycle = Cycle.objects.create(name="my cycle", ) self.task_type = TaskType.objects.create(name="my tasktype", ) event_start_date = timezone.now() self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=event_start_date, end_date=event_start_date + timezone.timedelta(minutes=100), ) self.participation = Participation.objects.create( standby=True, user=self.admin, event=self.event, ) self.event_2 = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=event_start_date, end_date=event_start_date + timezone.timedelta(minutes=100), ) self.participation_presence = Participation.objects.create( standby=True, user=self.admin, event=self.event_2, presence_status='P', presence_duration_minutes=300, )
def setUp(self): self.client = APIClient() self.user = UserFactory() self.user.set_password('Test123!') self.user.save() self.user2 = UserFactory() self.user2.set_password('Test123!') self.user2.save() self.admin = AdminFactory() self.admin.set_password('Test123!') self.admin.save() self.random_country = Country.objects.create( name="random country", iso_code="RC", ) self.random_state_province = StateProvince.objects.create( name="random state", iso_code="RS", country=self.random_country, ) self.address = Address.objects.create( address_line1='random address 1', postal_code='RAN DOM', city='random city', state_province=self.random_state_province, country=self.random_country, ) self.cell = Cell.objects.create( name="my cell", address=self.address, ) self.cycle = Cycle.objects.create( name="my cycle", ) self.task_type = TaskType.objects.create( name="my tasktype", ) start_date = timezone.now() - timezone.timedelta( minutes=100, ) end_date = start_date + timezone.timedelta( minutes=50, ) self.cycle_inactive = Cycle.objects.create( name="my cycle", start_date=start_date, end_date=end_date, ) # Some date INSIDE the cycle range start_date = start_date + timezone.timedelta( minutes=1, ) end_date = end_date - timezone.timedelta( minutes=1, ) self.event = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) self.event2 = Event.objects.create( cell=self.cell, cycle=self.cycle, task_type=self.task_type, start_date=start_date, end_date=end_date, ) subscription_date = timezone.now() with mock.patch('django.utils.timezone.now') as mock_now: mock_now.return_value = subscription_date self.participation = Participation.objects.create( standby=True, user=self.user, event=self.event2, ) self.participation2 = Participation.objects.create( standby=True, user=self.user2, event=self.event2, ) self.participation3 = Participation.objects.create( standby=True, user=self.user2, event=self.event, ) "Create temp directory and update MEDIA_ROOT and default storage." settings._original_media_root = settings.MEDIA_ROOT settings._original_file_storage = settings.DEFAULT_FILE_STORAGE self._temp_media = tempfile.mkdtemp() settings.MEDIA_ROOT = self._temp_media settings.DEFAULT_FILE_STORAGE = \ 'django.core.files.storage.FileSystemStorage'