Exemplo n.º 1
0
    def test_mediafield_assign_video_to_image_field(self):
        """
        Test video assignment to MediaField with type=image
        Condition: Authorized user tries to assign video to image field
        Result: Model returns a validation error
        """
        from media_explorer.tests.customfields.models import Example

        #Save a video
        url = reverse("api-media-elements")

        c = Client()
        c.login(username="******",password="******")

        response = c.post(url, {'name':'test_mediafield_assign_image_to_video_field','video_url':'https://www.youtube.com/watch?v=nBupSKjSQM0'},HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(response.status_code, 200)

        #Check the DB to make sure element is present
        video = Element.objects.get(type="video",name="test_mediafield_assign_image_to_video_field",video_embed__isnull=False)

        #Now create Example object and assign video to image
        #NOTE: Do not save because the table is not created in test db
        error_message = ""
        example = Example()
        example.image = video
        try:
            example.clean_fields()
        except ValidationError as e:
            error_message = e.message_dict["image"][0]

        self.assertTrue("Invalid media type" in error_message)