def test_create_course_attachment(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        tmp_file = attachmenthelper.given_file_exists()

        # WHEN
        with open(tmp_file.name) as fp:
            data = {'course': course.pk, 'file[]': [fp]}
            response = self.client.post(reverse('planner_attachments_list'),
                                        data)

        # THEN
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['title'],
                         os.path.basename(tmp_file.name))
        self.assertEqual(response.data[0]['size'],
                         os.path.getsize(tmp_file.name))
        self.assertEqual(response.data[0]['course'], data['course'])
        self.assertEqual(Attachment.objects.count(), 1)
        attachment = Attachment.objects.get(pk=response.data[0]['id'])
        attachmenthelper.verify_attachment_matches_data(
            self, attachment, response.data[0])
    def test_get_attachment_by_id(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        attachment = attachmenthelper.given_attachment_exists(user, course)

        # WHEN
        response = self.client.get(
            reverse('planner_attachments_detail', kwargs={'pk':
                                                          attachment.pk}))

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        attachmenthelper.verify_attachment_matches_data(
            self, attachment, response.data)