예제 #1
0
 def test_snippets(self):
     instance = UploadedFileFactory.build()
     instance.file = MagicMock()
     instance.file.url = '/media/foo.png'
     snippets = SnippetFactory.create_batch(2, data='lalala {0} foobar'.format(instance.url))
     template = SnippetTemplateFactory.create(code='<foo>{0}</foo>'.format(instance.url))
     more_snippets = SnippetFactory.create_batch(3, template=template)
     eq_(set(instance.snippets), set(list(snippets) + list(more_snippets)))
예제 #2
0
 def test_url_without_cdn_url(self):
     test_file = UploadedFileFactory.build()
     test_file.file = Mock()
     test_file.file.url = 'bar'
     with patch('snippets.base.models.settings', wraps=settings) as settings_mock:
         delattr(settings_mock, 'CDN_URL')
         settings_mock.SITE_URL = 'http://example.com/foo/'
         eq_(test_file.url, 'http://example.com/foo/bar')
예제 #3
0
 def test_snippets(self):
     instance = UploadedFileFactory.build()
     instance.file = MagicMock()
     instance.file.url = '/media/foo.png'
     snippets = SnippetFactory.create_batch(2, data='lalala {0} foobar'.format(instance.url))
     template = SnippetTemplateFactory.create(code='<foo>{0}</foo>'.format(instance.url))
     more_snippets = SnippetFactory.create_batch(3, template=template)
     self.assertEqual(set(instance.snippets), set(list(snippets) + list(more_snippets)))
예제 #4
0
 def test_url_without_cdn_url(self):
     test_file = UploadedFileFactory.build()
     test_file.file = Mock()
     test_file.file.url = 'bar'
     with patch('snippets.base.models.settings', wraps=settings) as settings_mock:
         delattr(settings_mock, 'CDN_URL')
         settings_mock.SITE_URL = 'http://example.com/foo/'
         self.assertEqual(test_file.url, 'http://example.com/foo/bar')
예제 #5
0
 def test_generate_filename_existing_entry(self):
     obj = UploadedFileFactory.build()
     obj.file.name = 'bar.png'
     obj.save()
     filename = _generate_filename(obj, 'new_filename.boing')
     self.assertEqual(filename, 'bar.png')
예제 #6
0
 def test_generate_new_filename(self, uuid_mock):
     uuid_mock.uuid4.return_value = 'bar'
     file = UploadedFileFactory.build()
     filename = _generate_filename(file, 'filename.boing')
     self.assertEqual(filename, 'filesroot/bar.boing')
예제 #7
0
 def test_generate_new_filename(self, uuid_mock):
     uuid_mock.uuid4.return_value = 'bar'
     file = UploadedFileFactory.build()
     UploadedFile.FILES_ROOT = 'filesroot'
     filename = UploadedFile._generate_filename(file, 'filename.boing')
     eq_(filename, 'filesroot/bar.boing')
예제 #8
0
 def test_generate_filename_existing_entry(self):
     obj = UploadedFileFactory.build()
     obj.file.name = 'bar.png'
     obj.save()
     filename = _generate_filename(obj, 'new_filename.boing')
     self.assertEqual(filename, 'bar.png')
예제 #9
0
 def test_generate_new_filename(self, uuid_mock):
     uuid_mock.uuid4.return_value = 'bar'
     file = UploadedFileFactory.build()
     filename = _generate_filename(file, 'filename.boing')
     self.assertEqual(filename, 'filesroot/bar.boing')
예제 #10
0
 def test_generate_new_filename(self, uuid_mock):
     uuid_mock.uuid4.return_value = 'bar'
     file = UploadedFileFactory.build()
     UploadedFile.FILES_ROOT = 'filesroot'
     filename = UploadedFile._generate_filename(file, 'filename.boing')
     eq_(filename, 'filesroot/bar.boing')