def setUp(self): BaseTest.setUp(self) # upload a photo self.u = models.User("super", "*****@*****.**") self.u.set_password("aqwsed7890") db.session.add(self.u) db.session.commit() self.up = models.UploadedPhoto() self.up.url = "http://example.com/meh.jpeg" self.up.filename = "meh.jpeg" self.up.size = 123 self.up.key = "grrr_meh.jpeg" self.up.user_id = self.u.id db.session.add(self.up) db.session.commit() s3conn = s3.S3Adapter() bucket = s3conn.get_bucket(app.config["INCOMING_PHOTO_BUCKET"]) k = Key(bucket) k.key = self.up.key with open(PHOTO_PATH, "rb") as f: k.set_contents_from_file(f) self.key = k
def test_basic_relationships(self): #create user user = models.User("john", "*****@*****.**") db.session.add(user) # a photo photo = models.Photo() photo.rating = 1.3 photo.title = "title" photo.user = user db.session.add(photo) db.session.commit() # a few tags for i in range(1, 11): photo.add_tag("tag%2d" % i) db.session.commit() photos = models.Photo.query.filter_by(title="title") assert photos.count() == 1 photo = photos.first() assert photo.title == "title" assert photo.rating == 1.3 assert photo.user_id == user.id assert photo.user == user assert len(photo.tags) == 10 t = models.Tag.query.filter_by(name="tag10") assert t.count() == 1 t = t.first() assert t.photos.count() == 1
def setUp(self): BaseTest.setUp(self) self.user = models.User("john", "*****@*****.**") self.user.set_password("doe") db.session.add(self.user) db.session.commit() self.now = datetime.now()
def setUp(self): BaseTest.setUp(self) self.user = models.User("john", "*****@*****.**") self.user.set_password("doe") db.session.add(self.user) db.session.commit() self.user2 = models.User("john2", "*****@*****.**") self.user2.set_password("doe") db.session.add(self.user2) db.session.commit() with open(path.join(DOT, "fixtures/4843655940_d8dd79d602_o.jpg")) as f: fs = FileStorage(f, "4843655940_d8dd79d602_o.jpg") self.photo = models.Photo.from_file(self.user, fs) self.photo.user = self.user self.photo.title = "Landscape" self.photo.description = """This is an awesome description""" self.photo.url = "s3://dev.pinhole.tty.cl/mesh" self.photo.rating = 5.0 db.session.add(self.photo) db.session.commit() self.photo_id = self.photo.id
def setUpClass(cls): s3conn = S3Adapter() bucket = s3conn.lookup(app.config["PHOTO_BUCKET"]) assert bucket is not None cls.s3_keys = bucket.get_all_keys() db.create_all() cls.app = TestApp(application()) cls.user = models.User("john", "*****@*****.**") cls.user.set_password("doe") db.session.add(cls.user) db.session.commit() cls.roll = models.Roll() cls.roll.timestamp = datetime.now() db.session.add(cls.roll) db.session.commit() cls.photos = [] start = datetime.now() - timedelta(days=1) for i in range(20): photo = models.Photo() photo.title = "Photo%.2d" % i photo.description = "Photo desc" photo.width = 10 * (i + 1) photo.height = 10 * (i + 1) # exif photo.make = "Make%s" % i photo.model = "Model%s" % i photo.software = "Software%s" % i photo.host_computer = "HostComputer%s" % i photo.orientation = 1 photo.date_time = start + timedelta(seconds=3600 * i) photo.date_time_digitized = start + timedelta(seconds=3600 * i + 1) photo.date_time_original = start + timedelta(seconds=3600 * i + 2) photo.user = cls.user photo.roll = cls.roll db.session.add(photo) db.session.commit() photo.add_tag("tag%s" % i) cls.photos.append(photo) cls.login("john", "doe")
def post(self): args = params.register_user.parse_args() filters = or_() filters.append(models.User.email == args["email"]) filters.append(models.User.username == args["username"]) users = models.User.query.filter(filters) if users.count() > 0: return abort(400, message="Username/email already in use") user = models.User(args["username"], args["email"]) user.set_password(args["password"], commit=False) db.session.add(user) db.session.commit() login_user(user, remember=False) return {"user": user}
def setUp(self): db.create_all() #create user self.user = models.User("john", "*****@*****.**") db.session.add(self.user) db.session.commit()