def test_subject_update(
            self, client, user_token,
            subject
    ):
        """
        Given subject,
        And new subject title,
        When update subject,
        Then subject is updated,
        And response contains new subject info.
        """
        subject_title = 'ЯРусский'

        encoded_data, content_type = encode_data({'title': subject_title})

        response = client.put(
            f'/api/schedule_subjects/{subject.pk}',
            encoded_data,
            **user_token,
            content_type=content_type
        )

        assert ScheduleSubject.objects.get(pk=subject.pk).title == subject_title
        assert response.data == {
            'title': subject_title,
            'id': subject.pk
        }
    def test_alter_notification(self, client, user_token, sent_notification,
                                notification_data):
        """
        Given notification,
        And altered notification data,
        When update notification,
        Then notification is updated.
        """
        notification_data['send_once'] = False

        encoded_data, content_type = encode_data(notification_data)
        response = client.put(f'/api/notifications/{sent_notification.pk}',
                              encoded_data,
                              content_type=content_type,
                              **user_token)

        notification = Notification.objects.get(pk=sent_notification.pk)
        assert not notification.send_once
        assert response.data == {
            'id': notification.pk,
            'text': notification_data['text'],
            'frequency': notification_data['frequency'],
            'send_once': notification_data['send_once'],
            'groups': notification_data['groups'],
            'created_by': 'potykion',
            'until': datetime_to_drf(notification.until)
        }
Example #3
0
    def test_event_update(
            self, client, user_token,
            event,
            user, group
    ):
        """
        Given event,
        And new event data
        When update event data,
        Then response contains updated event,
        And event is updated.
        """
        start_date = timezone.now() + timedelta(days=2)
        end_date = start_date + timedelta(hours=2)
        new_event_data = {
            'title': event.title,
            'place': 'Ne wkola',
            'description': event.description,

            'participation_groups': [],

            'start_date': start_date,
            'end_date': end_date,
        }

        encoded_data, content_type = encode_data(new_event_data)

        response = client.put(
            f'/api/events/{event.pk}',
            encoded_data,
            **user_token,
            content_type=content_type
        )

        assert response.data == {
            'id': 1,

            'title': event.title,
            'place': 'Ne wkola',
            'description': event.description,

            'created_by': user.username,
            'participation_groups': [],

            'start_date': datetime_to_drf(start_date),
            'end_date': datetime_to_drf(end_date)
        }
    def test_group_update(self, client, user_token, group):
        """
        Given group,
        And new group title,
        When update group,
        Then response is successful,
        And group title equals to given group title.
        """
        group_title = 'Sample group 2'

        encoded_data, content_type = encode_data({'title': group_title})

        response: Response = client.put(f'/api/groups/{group.pk}',
                                        encoded_data,
                                        **user_token,
                                        content_type=content_type)

        assert response.status_code == 200
        assert Group.objects.get(pk=group.pk).title == group_title
    def test_update_schedule_item(
            self, client, teacher_token,
            schedule_item, teacher
    ):
        """
        Given schedule item,
        And new schedule data,
        When update schedule item,
        Then schedule item is updated,
        And response contains new schedule data.
        """
        new_schedule_data = {
            'place': 'wkola2',
            'start_time': '13:00',
            'weekday': 2,
            'subject': schedule_item.subject.pk,
            'groups': list(schedule_item.groups.values_list('pk', flat=True)),
        }

        encoded_data, content_type = encode_data(new_schedule_data)

        response = client.put(
            f'/api/schedule_lessons/{schedule_item.pk}',
            encoded_data,
            **teacher_token,
            content_type=content_type
        )

        item = ScheduleLesson.objects.get(pk=schedule_item.pk)
        assert str(item.start_time)[:-3] == '13:00'
        assert response.data == {
            'id': item.pk,
            'teacher': teacher.username,

            'place': new_schedule_data['place'],
            'groups': new_schedule_data['groups'],
            'start_time': new_schedule_data['start_time'],
            'subject': new_schedule_data['subject'],
            'weekday': new_schedule_data['weekday']
        }