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 create_users(): with open("users.json") as f: users = json.load(f) for user_dict in users: user = User() user.first_name = user_dict["firstName"] user.last_name = user_dict["lastName"] user.username = user_dict["username"] user.avatar_url = user_dict["avatarUrl"] db.session.add(user) db.session.commit()
def seed_db(): """Seeds the database.""" with open("authentication.json") as f: users = json.load(f) for user in users: user_object = User() user_object.user_id = user["id"] user_object.username = user["username"] user_object.hashed_password = user["hashedPassword"] user_object.birthdate = dateutil.parser.parse(user["birthdate"]) for profile in user["profiles"]: profile_id = int(profile["id"]) obj = Profile.query.filter_by(profile_id=profile_id).first() if obj is None: obj = Profile() obj.profile_id = profile_id obj.name = profile["name"] user_object.profiles.append(obj) db.session.add(user_object) with open("programming.json") as f: dictionary = json.load(f) assets = dictionary["assets"] providers = dictionary["providers"] for provider in providers: obj = Provider() obj.refresh_rate_in_seconds = provider["refreshRateInSeconds"] obj.provider_id = provider["id"] obj.name = provider["name"] for prof_id in provider["profileIds"]: profile = Profile.query.filter_by(profile_id=prof_id).first() obj.profiles.append(profile) db.session.add(obj) for asset in assets: asset_object = Asset() asset_object.media_id = asset["mediaId"] asset_object.title = asset["title"] asset_object.provider_id = asset["providerId"] asset_object.duration_in_seconds = asset["durationInSeconds"] asset_object.licensing_window_start = dateutil.parser.parse( asset["licensingWindow"]["start"]) asset_object.licensing_window_end = dateutil.parser.parse( asset["licensingWindow"]["end"]) for prof_id in asset["profileIds"]: profile = Profile.query.filter_by(profile_id=prof_id).first() asset_object.profiles.append(profile) db.session.add(asset_object) db.session.commit()
def bell_hidden_account(): """Creates a user account""" response = {} secret_key = request.headers.get("secretKey") request_json = request.get_json() # Validation if secret_key != os.environ["HEADER_SECRET_KEY"]: response["message"] = "Invalid header secret key" return jsonify(response), 401 keys = ["accountId", "profiles", "username", "password"] for key in keys: if key not in request_json: response["message"] = "Missing {} key in request body".format(key) return jsonify(response), 400 profile_names = request_json["profiles"] for name in profile_names: profile = Profile.query.filter_by(name=name).first() if profile is None: response["message"] = "Invalid profile name: {}".format(name) return jsonify(response), 400 username = request_json["username"] user = User.query.filter_by(username=username).first() if user is not None: response["message"] = "Username already exists" return jsonify(response), 409 # Create user user = User() user.user_id = request_json["accountId"] user.username = username password = request_json["password"].encode("utf-8") user.hashed_password = hashlib.sha256(password).hexdigest() for name in profile_names: profile = Profile.query.filter_by(name=name).first() user.profiles.append(profile) 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()