def test_userdb_modify_details(self): """ Test if we can add more user details to db """ user = User(eth_address="0x0E35462535daE6fd521f0Eea67dc4e9485C714dC") db.session.add(user) db.session.commit() old_id = user.id user.username = "******" user.email = "test" user.city_country = "test" user.tags = "test1, test2" user.img_src = "www.testurl.com" user.about = "test" db.session.commit() self.assertTrue(old_id == user.id) self.assertTrue( "0x0E35462535daE6fd521f0Eea67dc4e9485C714dC" == user.eth_address) self.assertTrue("test" == user.username) self.assertTrue("test" == user.email) self.assertTrue("test" == user.city_country) self.assertTrue(["test1", "test2"] == user.tags) self.assertTrue("www.testurl.com" == user.img_src) self.assertTrue("test" == user.about) self.assertTrue(user.active)
def seed_db(): """Seeds the database.""" with open("tags.json") as f: tags = json.load(f) for tag in tags: tag_object = Tag() tag_object.name = tag["name"] db.session.add(tag_object) db.session.commit() with open("users.json") as f: users = json.load(f) for user in users: user_object = User() user_object.email = user["email"] user_object.name = user["name"] user_object.birthdate = dateutil.parser.parse(user["birthdate"]) user_object.gender = user["gender"] user_object.interested_in = user["interestedIn"] user_object.picture_url = user["pictureUrl"] user_object.hashed_password = user["hashedPassword"] user_object.description = user["description"] for tag_id in user["tags"]: tag_object = Tag.query.filter_by(tag_id=tag_id).first() user_object.tags.append(tag_object) db.session.add(user_object) db.session.commit() with open("ratings.json") as f: ratings = json.load(f) for rating in ratings: rating_object = Rating() rating_object.from_user_id = rating["fromUserId"] rating_object.to_user_id = rating["toUserId"] rating_object.stars = rating["stars"] rating_object.comment = rating["comment"] db.session.add(rating_object) db.session.commit() with open("messages.json") as f: messages = json.load(f) for message in messages: message_object = Message() message_object.from_user_id = message["fromUserId"] message_object.content = message["content"] message_object.date_time = dateutil.parser.parse( message["date_time"]) db.session.add(message_object) db.session.commit()
def register(): """Creates a user account""" response = {} request_json = request.get_json() # Validation keys = [ "email", "name", "birthdate", "gender", "interestedIn", "description", "pictureURL", "password", "tags", ] for key in keys: if key not in request_json: response["message"] = "Missing {} key in request body".format(key) return jsonify(response), 400 email = request_json["email"] user = User.query.filter_by(email=email).first() if user is not None: response["message"] = "Email already exists" return jsonify(response), 409 # Create user user = User() user.email = email user.name = request_json["name"] user.birthdate = dateutil.parser.parse(request_json["birthdate"]) user.gender = request_json["gender"] user.interested_in = request_json["interestedIn"] user.description = request_json["description"] user.picture_url = request_json["pictureURL"] password = request_json["password"].encode("utf-8") user.hashed_password = hashlib.sha256(password).hexdigest() for tag_id in request_json["tags"]: tag = Tag.query.filter_by(tag_id=tag_id).first() user.tags.append(tag) db.session.add(user) db.session.commit() response["message"] = "Account created successfully" return jsonify(response), 201
def seed_db(): """ Seeds the database with some initial data """ user1 = User( eth_address='0x0d604C28A2a7c199c7705859c3f88A71cCE2aCb7'.lower()) user1.username = "******" user1.email = "*****@*****.**" user1.city_country = "Singapore, SG" user1.tags = "Meeting Spaces" user1.about = '''This is the best meeting space you will ever see''' user1.seller_detail = '''We sell space''' user1.buyer_detail = '''We are not buying''' user2 = User( eth_address='0xF4675187bD8B058CcF87f7116b54970fC3f81b52'.lower()) user2.username = "******" user2.email = "*****@*****.**" user2.city_country = "Singapore, SG" user2.tags = "Stylist" user2.about = '''Reimagine your looks with us''' user2.seller_detail = '''We are serving looks tonight''' user2.buyer_detail = '''We are not buying''' user3 = User( eth_address='0x4FaE992a476bB00Be85B7BF76fef8e27DE2231C7'.lower()) user3.username = "******" user3.email = "*****@*****.**" user3.city_country = "Singapore, SG" user3.tags = "Buffet" user3.about = '''Eat till you get a heart attack''' user3.seller_detail = '''We sell food''' user3.buyer_detail = '''We are not buying''' user4 = User( eth_address='0x6ea57F562Ef39f1776eb66D91c54A961Fa6DdadA'.lower()) user4.username = "******" user4.email = "*****@*****.**" user4.city_country = "Singapore, SG" user4.tags = "Photography" user4.about = ('We are a group of photographers specialized in wedding' 'photography. ' 'We have won numerous awards for our photos. ' 'We will capture your ' 'memories in ways you cannot imagine.') user4.seller_detail = '''We sell photos''' user4.buyer_detail = '''We are not buying''' user5 = User( eth_address='0x04Ee2da68b909684d586a852970E424981f30928'.lower()) user5.username = "******" user5.email = "*****@*****.**" user5.city_country = "Singapore, SG" user5.tags = "Bar, Restaurant" user5.about = ('Award winnning winebar with the best selection of alcohol.' 'We serve delicious international cuisine, with fusion' 'dishes inspired from our travels. We are always ready for' 'your craziest events.') user5.seller_detail = '''We sell wine''' user5.buyer_detail = '''We are not buying''' user6 = User( eth_address='0x50E9002d238d9a2A29C3047971E8006663A9d799'.lower()) user6.username = "******" user6.email = "*****@*****.**" user6.city_country = "Singapore, SG" user6.tags = "Performer" user6.about = ('Dancers who dance are people who like to dance alot.' 'Give us music and we will dance for you.') user6.seller_detail = '''We sell dance''' user6.buyer_detail = '''We are not buying''' db.session.add(user1) db.session.add(user2) db.session.add(user3) db.session.add(user4) db.session.add(user5) db.session.add(user6) db.session.commit()