def test_shift_manager_for_facility(self): """ checks that get_days_with_shifts() returns only dates later than datetime.now() """ now = datetime.now() yesterday_start = now - timedelta(1) yesterday_end = yesterday_start + timedelta(hours=1) tomorrow_start = now + timedelta(1) tomorrow_end = tomorrow_start + timedelta(hours=1) facility = FacilityFactory.create() task = TaskFactory.create(facility=facility) yesterday_shift = ShiftFactory.create(facility=facility, task=task, starting_time=yesterday_start, ending_time=yesterday_end) tomorrow_shift = ShiftFactory.create(facility=facility, task=task, starting_time=tomorrow_start, ending_time=tomorrow_end) assert Facility.objects.count( ) == 1, "test case assumes that shifts have been created for the same facility, as the ShiftFactory indeed does at the time of writing of this test case" assert Facility.objects.get() == task.facility shifts = Shift.open_shifts.filter(facility=facility) assert shifts.count( ) == 1, "only 1 shift should be found with Shifts.open_shifts" shift = shifts.get() assert shift == tomorrow_shift, "wrong shift was found" assert shift.ending_time > now, "the time has to be in the future"
def setup(self, session): self.factory = TaskFactory self.dummy_instance = TaskFactory.create() self.model = Task( id=self.dummy_instance.id, agile=self.dummy_instance.agile, title=self.dummy_instance.title, state=self.dummy_instance.state, due=self.dummy_instance.due, priority=self.dummy_instance.priority, ) self.model_attributes = [ 'agile', 'body', 'estimate', 'due', 'fun', 'id', 'priority', 'state', 'title', 'value', 'wait', 'willpower', ]
def test_task(graph_client): query = ''' query($id: ID!) { task(id: $id) { name description owner { username } category { name } } } ''' task = TaskFactory.create() result = graph_client.execute(query, variable_values={'id': model_instance_id_to_base64(task)}) assert result == { 'data': { 'task': { 'name': task.name, 'description': task.description, 'owner': { 'username': task.owner.username }, 'category': { 'name': task.category.name } } } }
def test_shift_manager_for_facility(self): """ checks that get_days_with_shifts() returns only dates later than datetime.now() """ now = datetime.now() yesterday_start = now - timedelta(1) yesterday_end = yesterday_start + timedelta(hours=1) tomorrow_start = now + timedelta(1) tomorrow_end = tomorrow_start + timedelta(hours=1) facility = FacilityFactory.create() task = TaskFactory.create(facility=facility) yesterday_shift = ShiftFactory.create(facility=facility, task=task, starting_time=yesterday_start, ending_time=yesterday_end) tomorrow_shift = ShiftFactory.create(facility=facility, task=task, starting_time=tomorrow_start, ending_time=tomorrow_end) assert Facility.objects.count() == 1, "test case assumes that shifts have been created for the same facility, as the ShiftFactory indeed does at the time of writing of this test case" assert Facility.objects.get() == task.facility shifts = Shift.open_shifts.filter(facility=facility) assert shifts.count() == 1, "only 1 shift should be found with Shifts.open_shifts" shift = shifts.get() assert shift == tomorrow_shift, "wrong shift was found" assert shift.ending_time > now, "the time has to be in the future"
def test_archive_task(): user = UserFactory.create() task = TaskFactory.create() task.archive() assert task.is_archived is True
def test_create_task(): user = UserFactory.create() # Check there are 0 tasks before a new task is added number_tasks = Task.objects.filter(user_id=user.id).count() assert number_tasks == 0 task = TaskFactory.create() # Check there is 1 task after a new task is added number_tasks = Task.objects.filter(user_id=user.id).count() assert number_tasks == 1
def test_report_does_not_print_tags_without_open_tasks(self): tag = TagFactory.create() tag_with_closed_tasks = TagFactory.create() completed_task = TaskFactory.create(state='completed') completed_task.tags = [tag_with_closed_tasks] deleted_task = TaskFactory.create(state='deleted') deleted_task.tags = [tag_with_closed_tasks] # Tag assignment for task in self.tasks: task.tags = [tag] self.session.commit() self.report.print(columns=self.columns, labels=self.labels) self.tabulate.assert_called_once_with([ [tag.id, 20, tag.description], ], headers=self.labels, tablefmt='simple') self.print.assert_called_once_with(self.tabulate.return_value)
def test_report_does_not_print_projects_without_open_tasks(self): project = ProjectFactory.create() project_with_closed_tasks = ProjectFactory.create() completed_task = TaskFactory.create(state='completed') completed_task.project = project_with_closed_tasks deleted_task = TaskFactory.create(state='deleted') deleted_task.project = project_with_closed_tasks # Project assignment for task in self.tasks: task.project = project self.session.commit() self.report.print(columns=self.columns, labels=self.labels) self.tabulate.assert_called_once_with([ [project.id, 20, project.description], ], headers=self.labels, tablefmt='simple') self.print.assert_called_once_with(self.tabulate.return_value)
def test_create_task(): user = UserFactory.create() # Check there are 0 tasks before a new task is added number_tasks = Task.objects.filter(user_id=user.id).count() assert number_tasks == 0 task = TaskFactory.create() # Check there is 1 task after a new task is added and that it's not archived number_tasks = Task.objects.filter(user_id=user.id).count() task = Task.objects.get(user_id=user.id) assert number_tasks == 1 assert task.is_archived is False
def test_complete_task_by_fulid(self): closed = self.fake.date_time() self.datetime.datetime.now.return_value = closed task = TaskFactory.create(state='open') assert self.session.query(Task).one() self.manager.complete(task.id) modified_task = self.session.query(Task).get(task.id) assert modified_task.closed == closed assert modified_task.title == task.title assert modified_task.state == 'completed' self.log_debug.assert_called_with( 'Completed task {}: {}'.format( modified_task.id, modified_task.title, ) )