-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
12 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,11 @@ class TasksViewSetTestCase(APITestCase): | |
def setUp(self): | ||
self.user = User.objects.create_user(email='[email protected]', password='password12345', user_type='P') | ||
self.user_info = UserInfo.objects.create(user=self.user, first_name='John', last_name='Doe', date_of_birth='1990-01-01') | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.user.auth_token.key) | ||
self.client.force_login(self.user) | ||
self.task = Task.objects.create(user_id=self.user.id, title='Test Task 1', discription='Test Description 1', do_date='2024-03-22', start_time='10:00:00', end_time='12:00:00', repetation=False, alarm=True) | ||
|
||
print(" prems le id est" + str(self.task.id)) | ||
|
||
|
||
# on test la creation d'une tache car on a redéfini la méthode create dans la view | ||
def test_create_task(self): | ||
url = '/tasks/' | ||
data = { | ||
|
@@ -43,50 +42,34 @@ def test_create_task(self): | |
self.assertEqual(task.end_time.strftime('%H:%M:%S'), '12:00:00') | ||
self.assertFalse(task.repetation) | ||
self.assertTrue(task.alarm) | ||
|
||
|
||
def test_get_task(self): | ||
url = '/tasks/' | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
# Créer un sérialiseur avec l'instance de la tâche | ||
serializer = TaskSerializer(instance=self.task) | ||
print(serializer.data) | ||
|
||
# Convertir les données renvoyées en JSON | ||
json_data = response.data | ||
expected_data = json.dumps(serializer.data) | ||
print(json_data) | ||
|
||
# Comparer les données JSON | ||
self.assertEqual(json_data, expected_data) | ||
|
||
|
||
|
||
|
||
|
||
|
||
# on test la methode put pour etre sur que la modification d'une tache fais par le framework (class ModelViewSet) fonctionne | ||
# Les autres methodes : GET, DELETE, PATCH sont testées par le framework aussi on considere que c'est ok | ||
def test_update_task(self): | ||
|
||
print("le id est" + str(self.task.id)) | ||
|
||
url = '/tasks/' + str(self.task.id) + '/' | ||
updated_data = { | ||
'title': 'Updated Task', | ||
'description': 'Updated Description', | ||
'discription': 'Updated Description', | ||
'do_date': '2024-03-21', | ||
'start_time': '12:00:00', | ||
'end_time': '14:00:00', | ||
'repetition': True, | ||
'repetation': True, | ||
'alarm': False | ||
} | ||
response = self.client.put(url, updated_data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
task = Task.objects.get(response.data['id']) | ||
response_data = response.json() | ||
|
||
task = Task.objects.get(id=response_data['id']) | ||
self.assertEqual(task.title, updated_data['title']) | ||
self.assertEqual(task.description, updated_data['description']) | ||
self.assertEqual(task.discription, updated_data['discription']) | ||
self.assertEqual(task.do_date.strftime('%Y-%m-%d'), updated_data['do_date']) | ||
self.assertEqual(task.start_time.strftime('%H:%M:%S'), updated_data['start_time']) | ||
self.assertEqual(task.end_time.strftime('%H:%M:%S'), updated_data['end_time']) | ||
self.assertEqual(task.repetition, updated_data['repetition']) | ||
self.assertEqual(task.repetation, updated_data['repetation']) | ||
self.assertEqual(task.alarm, updated_data['alarm']) |