Skip to content

Instantly share code, notes, and snippets.

@sthzg
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save sthzg/6962aa70745d6499cff4 to your computer and use it in GitHub Desktop.

Select an option

Save sthzg/6962aa70745d6499cff4 to your computer and use it in GitHub Desktop.
class MyModelTest(SimpleTestCase):
def test_something_with_some_file(self):
my_model = MyModel()
my_model.save()
# We change the storage location to save into our test directory.
my_model._meta.get_field('some_file').storage.location = '/somewhere/else'
a_file = '/whatever/is/tosave.txt'
my_model.some_file.save(
os.path.basename(a_file),
File(open(a_file, "r"))
)
self.assertTrue(os.path.exists('/somewhere/else/downloads/tosave.txt'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment