Пример #1
0
class TaskModelTest(unittest.TestCase):
    def setUp(self):
        self.task = Task(mock_task_data)

    def testInitialization(self):
        for key in mock_task_data:
            result = self.task.__dict__[key]
            self.assertEqual(result, mock_task_data[key])

    def testUpdateTaskData(self):
        new_data = {
            "id": 20,
            "topic": "Project Deadline",
            "description": "Send SEP project.",
            "created_at": "2019-05-29T09:18:23.223777Z",
            "start_at": "2019-06-02T06:00:00Z",
            "end_at": "2019-06-02T09:00:00Z",
            "status": False,
            "location": "International College, KMITL",
            "user": 1
        }
        self.task.update(new_data)
        for key in new_data.keys():
            result = self.task.__dict__[key]
            self.assertEqual(result, new_data[key])
Пример #2
0
    def retrieve_task(task_id):
        retrieve_task_endpoint = TASKS_API + str(task_id) + '/'
        response = requests.get(url=retrieve_task_endpoint, )

        if response.status_code == 200:
            return Task(response.json())
        return None
Пример #3
0
    def create_task(payload: Dict):
        response = requests.post(url=TASKS_API, data=payload)

        if response.status_code == 201:
            return Task(response.json())
        else:
            return None
Пример #4
0
    def update_task(task_id, payload):
        update_task_endpoint = TASKS_API + str(task_id) + '/'

        response = requests.put(url=update_task_endpoint, data=payload)

        if response.status_code == 200:
            return Task(response.json())
        return None
Пример #5
0
 def testGetTask(self):
     task = Task(mock_task_data)
     tasks = [
         mock_task_data,
         mock_task_data.copy(),
         mock_task_data.copy()
     ]
     task_list = TaskList(tasks)
     result = task_list.get_task(task.id)
     self.assertEqual(result, task)
Пример #6
0
 def testAddTask(self):
     task = Task(mock_task_data)
     tasks = [
         mock_task_data,
         mock_task_data.copy(),
         mock_task_data.copy()
     ]
     task_list = TaskList(tasks)
     task_list.add_task(mock_task_data)
     result = task_list.tasks[-1]
     self.assertEqual(result, task)
Пример #7
0
 def testCountTask(self):
     task = Task(mock_task_data)
     mock_task_data_2 = mock_task_data.copy()
     mock_task_data_3 = mock_task_data.copy()
     mock_task_data_2['id'] = 1
     mock_task_data_3['id'] = 2
     tasks = [
         mock_task_data,
         mock_task_data_2,
         mock_task_data_3
     ]
     task_list = TaskList(tasks)
     self.assertEqual(task_list.count(), 3)
Пример #8
0
 def testDeleteTask(self):
     task = Task(mock_task_data)
     mock_task_data_2 = mock_task_data.copy()
     mock_task_data_3 = mock_task_data.copy()
     mock_task_data_2['id'] = 1
     mock_task_data_3['id'] = 2
     tasks = [
         mock_task_data,
         mock_task_data_2,
         mock_task_data_3
     ]
     task_list = TaskList(tasks)
     task_list.delete_task(1)
     self.assertEqual(task_list.get_task(1), None)
Пример #9
0
    def testUpdateTask(self):
        task = Task(mock_task_data)
        mock_task_data_2 = mock_task_data.copy()
        mock_task_data_3 = mock_task_data.copy()
        mock_task_data_2['id'] = 1
        mock_task_data_3['id'] = 2
        tasks = [
            mock_task_data,
            mock_task_data_2,
            mock_task_data_3
        ]
        task_list = TaskList(tasks)
        new_data = mock_task_data.copy()
        new_data['topic'] = "hello world"
        result = task_list.update_task(task.id, new_data)

        self.assertEqual(result.topic, "hello world")
        self.assertEqual(result, task_list.get_task(task.id))
Пример #10
0
 def setUp(self):
     self.task = Task(mock_task_data)