def setUp(self): u"""Create a user and image that can be used in all tests. Create a temp folder for images to be stored in, so test images don't clog up regular media folder.""" self.DJANGO_CONFIGURATION = "Test" user = ImagrUser(username="******") user.save() test_dir = os.listdir(os.getcwd() + "/test_data/test_pics") test_dir = [os.getcwd() + "/test_data/test_pics/" + name for name in test_dir] test_albums = [u"Tester's Album", u"Tester's Second Album"] for pic in test_dir: with open(pic, "r") as file_: a_photo = File(file_) photo = Photo() photo.image = a_photo photo.owner = user photo.published = 1 photo.save() for test_album in test_albums: album = Album() album.title = test_album album.owner = user album.published = 1 album.save() self.generator = self._name_generator()
def setUp(self): """Create a user and image that can be used in all tests. Create a temp folder for images to be stored in, so test images don't clog up regular media folder.""" TEST_ROOT = os.path.abspath(os.path.dirname(__file__)) self._old_MEDIA_ROOT = settings.MEDIA_ROOT # override MEDIA_ROOT for this test settings.MEDIA_ROOT = os.path.join(TEST_ROOT, 'testdata/media/') user = ImagrUser(username="******") user.save() with open("/home/nathan/Pictures/codeschool.png", 'rb') as fi: an_image = File(fi) image = Image(title=u"Nathan's Photo", image=an_image, privacy=0, owner=user) image.save() with open("/home/nathan/Pictures/linterLinting.png", 'rb') as fi: an_image = File(fi) image = Image(title=u"Nathan's Second Photo", image=an_image, privacy=0, owner=user) image.save() album = Album(title="Nathan's Album", privacy=0, owner=user) album.save() album2 = Album(title="Nathan's Second Album", privacy=0, owner=user) album2.save()
def _create_album(self): album = Album(title=self.generator, owner=ImagrUser.objects.all()[0], published=1) album.save() return album