def save_user(self): """ Save user to database. params: user_info: dict returns: bloolean """ try: email = self.user_info['email'] name = self.user_info['name'] picture = self.user_info['picture'] user = User.query.filter_by(email=email).first() role = Role.query.filter_by(role='Default User').first() if not role: role = Role(role='Default User') role.save() if not user: try: user_data = User(email=email, name=name, picture=picture) user_data.roles.append(role) user_data.save() notification_settings = NotificationModel( user_id=user_data.id) notification_settings.save() except Exception as e: # noqa db_session.rollback() except SQLAlchemyError: pass return True
def create_user(): user = User(email="*****@*****.**", location="Lagos", name="test test", picture="www.andela.com/test") user.save() db_session().commit()
def setUp(self): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) command.stamp(self.alembic_configuration, 'head') command.downgrade(self.alembic_configuration, '-1') command.upgrade(self.alembic_configuration, 'head') user = User(fullname="doe jon", username="******", email="*****@*****.**") user.save() challenge = Challenge(title="zanku challenge", start_date="2019-08-15 06:00:49.303402", end_date="2019-08-15 06:00:49.303402", description="*****@*****.**", image="https://picsum.photos/200", prize="10000") challenge.save() contestant = Contestant(challenge=1, contestant=2, state="subscribed") contestant.save() challenge_entry = ChallengeEntry(contestant_id=2, challenge_id=1, file_url="http://foobar.hj") challenge_entry.save()
def seed_data(apps, schema_editor): user = User(name='boris', email='*****@*****.**', is_staff=True, is_superuser=True, gender='Male') user.set_password('1234qwe') user.save()
def seed_data(apps, schema_editor): user = User( name='sagar', email='*****@*****.**', is_staff=True, is_superuser=True, ) user.set_password('12345') user.save()
def test_paginate__users_query(self): user = User(email='*****@*****.**', name="test test", picture="www.andela.com/test") user.save() self.client.execute(user_query, context_value={'session': db_session}) CommonTestCases.admin_token_assert_equal(self, paginated_users_query, paginated_users_response)
def func_wrapper(self): user_role = Role(role='Default User') user_role.save() user = User(email='*****@*****.**', name='Test user', location="Lagos", picture='www.andela.com/testuser') user.save() user.roles.append(user_role) db_session().commit()
def func_wrapper(self): headers = {"Authorization": "Bearer" + " " + USER_TOKEN} user = User(email='*****@*****.**', name='this user', location="Nairobi", picture='www.andela.com/user') user.save() user.roles.append(role) db_session().commit() return headers
def seed_data(apps, schema_editor): user = User(name='Sumit', email='*****@*****.**', is_staff=True, is_superuser=True, phone='9876543210', gender="Male", address="17, Mayur Park Society") user.set_password('1234') user.save()
def create_user(): user = User(email='*****@*****.**', location="Kampala", name="test test", picture="www.andela.com/testuser") user.save() role = base.role user.roles.append(role) db_session().commit() return user
def test_user_delete_admin(self): admin_user = User(email="*****@*****.**", location="Kampala", name="test test", picture="www.andela.com/test") admin_user.save() role = base.role admin_user.roles.append(role) CommonTestCases.user_token_assert_in( self, delete_user, "You are not authorized to perform this action")
def func_wrapper(self): headers = {"Authorization": "Bearer" + " " + user_api_token} user = User(email='*****@*****.**', name='this user', location="Nairobi", picture='www.andela.com/user') user.save() user_role = UsersRole(user_id=user.id, role_id=1) user_role.save() db_session().commit() return headers
def test_user_delete_admin(self): admin_user = User(email="*****@*****.**", location="Kampala", name="test test", picture="www.andela.com/test") admin_user.save() user_role = UsersRole(user_id=admin_user.id, role_id=1) user_role.save() CommonTestCases.user_token_assert_in( self, delete_user, "You are not authorized to perform this action")
def test_query_users_by_email(self): user = User(email='*****@*****.**', name="test test", picture="www.andela.com/test") user.save() db_session().commit() execute_query = self.client.execute( query_user_by_email, context_value={'session': db_session}) expected_responese = query_user_email_response self.assertEqual(execute_query, expected_responese)
def test_deleteuser_when_admin(self): user = User(email="*****@*****.**", location="Kampala", name="test test", picture="www.andela.com/test") user.save() role = Role(role="Default User") role.save() user.roles.append(role) CommonTestCases.admin_token_assert_equal(self, delete_user_2, expected_query_after_delete)
def test_change_user_role(self): user = User(email='*****@*****.**', location="Kampala", name="test test", picture="www.andela.com/testuser") user.save() user_role = UsersRole(user_id=user.id, role_id=1) user_role.save() db_session().commit() CommonTestCases.admin_token_assert_equal( self, change_user_role_mutation_query, change_user_role_mutation_response)
def test_query_users(self): """ Testing for User creation """ user = User(email='*****@*****.**', name="test test", picture="www.andela.com/test") user.save() execute_query = self.client.execute( user_query, context_value={'session': db_session}) expected_response = user_query_response self.assertEqual(execute_query, expected_response)
def test_query_users_role_by_role(self): user = User(email='*****@*****.**', location="Lagos", name="test test", picture="www.andela.com/testuser") user.save() user_role = UsersRole(user_id=user.id, role_id=1) user_role.save() db_session().commit() execute_query = self.client.execute( query_user_by_user_id, context_value={'session': db_session}) expected_response = query_user_by_user_id_response self.assertEqual(execute_query, expected_response)
def test_query_users_role_by_role(self): user = User(email='*****@*****.**', location="Lagos", name="test test", picture="www.andela.com/testuser") user.save() role = base.role user.roles.append(role) db_session().commit() execute_query = self.client.execute( query_user_by_user_email, context_value={'session': db_session}) expected_response = query_user_by_user_email_response self.assertEqual(execute_query, expected_response)
def test_user_role_creation(self): """ Testing for User Role creation """ user = User(email="*****@*****.**", location="Lagos", name="test test", picture="www.andela.com/test") user.save() db_session().commit() execute_query = self.client.execute( user_role_mutation_query, context_value={'session': db_session}) expected_responese = user_role_mutation_response self.assertEqual(execute_query, expected_responese)
def setUp(self): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) admin_user = User(email="*****@*****.**", location="Kampala", name="Peter Walugembe", picture="https://www.andela.com/walugembe") admin_user.save() role = Role(role="Admin") role.save() user_role = UsersRole(user_id=admin_user.id, role_id=role.id) user_role.save() location = Location(name='Kampala', abbreviation='KLA') location.save() location_two = Location(name='Nairobi', abbreviation='NBO') location_two.save() office = Office(name="St. Catherines", location_id=location.id) office.save() office_two = Office(name="dojo", location_id=location_two.id) office_two.save() block = Block(name='EC', office_id=office.id) block.save() floor = Floor(name='3rd', block_id=block.id) floor.save() room = Room( name='Entebbe', room_type='meeting', capacity=6, floor_id=floor.id, calendar_id= '*****@*****.**', # noqa: E501 image_url= "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" ) # noqa: E501 room.save() resource = Resource(name='Markers', quantity=3, room_id=room.id) resource.save() device = Devices(resource_id=resource.id, last_seen="2018-06-08T11:17:58.785136", date_added="2018-06-08T11:17:58.785136", name="Samsung", location="Nairobi", device_type="External Display") device.save() db_session.commit()
def test_query_users_role(self): """ Testing for query User role """ user = User(email="*****@*****.**", location="Lagos", name="test test", picture="www.andela.com/testuser") user.save() user.roles.append(user_role) db_session().commit() execute_query = self.client.execute( user_role_query, context_value={'session': db_session}) expected_responese = user_role_query_response self.assertEqual(execute_query, expected_responese)
def setUp(self): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) command.stamp(self.alembic_configuration, 'head') # command.downgrade(self.alembic_configuration, '-1') command.upgrade(self.alembic_configuration, 'head') user = User(name="Ken", password="******", user_type='default') user.save() product = Product(name="Eggs", manufacturer="none", price=200, tax=0, UOM="none", user_id="1") product.save() db_session.commit()
def setUp(self, mock_verify_calendar_id): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) command.stamp(self.alembic_configuration, 'head') command.downgrade(self.alembic_configuration, '-1') command.upgrade(self.alembic_configuration, 'head') admin_user = User(email="*****@*****.**", name="Peter Walugembe", picture="https://www.andela.com/walugembe") admin_user.location = "Kampala" admin_user.save() lagos_admin = User(email="*****@*****.**", location="Lagos", name="Peter Adeoye", picture="https://www.andela.com/adeoye") lagos_admin.save() global role role = Role(role="Admin") role.save() role_2 = Role(role="Test") role_2.save() role_3 = Role(role="Super Admin") role_3.save() admin_user.roles.append(role) lagos_admin.roles.append(role) tag = Tag(name='Block-B', color='green', description='The description') tag.save() location = Location(name='Kampala', abbreviation='KLA') location.save() location_two = Location(name='Nairobi', abbreviation='NBO') location_two.save() location_three = Location(name='Lagos', abbreviation='LOS') location_three.save() tag_two = Tag(name='Block-C', color='blue', description='The description') tag_two.save() room = Room( name='Entebbe', room_type='meeting', capacity=6, location_id=location.id, structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87', calendar_id= '*****@*****.**', # noqa: E501 image_url= "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 room_labels=["1st Floor", "Wing A"]) room.save() room.room_tags.append(tag) room_2 = Room( name='Tana', room_type='meeting', capacity=14, location_id=location.id, structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87', calendar_id= '*****@*****.**', # noqa: E501 image_url= "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 room_labels=["1st Floor", "Wing B"]) room_2.save() room_2.room_tags.append(tag) resource = Resource(name='Markers', quantity=3) resource.save() device = Devices(last_seen="2018-06-08T11:17:58.785136", date_added="2018-06-08T11:17:58.785136", name="Samsung", location="Kampala", device_type="External Display", room_id=1, state="active") device.save() question_1 = Question( question_type="rate", question_title="Rating Feedback", question="How will you rate the brightness of the room", start_date="20 Nov 2018", end_date="28 Nov 2018", is_active=True) question_1.save() question_2 = Question( question_type="check", question_title="check Feedback", question="Is there anything missing in the room", check_options=['apple tv', 'whiteboard', 'maker pen'], start_date="20 Nov 2018", end_date="30 Nov 2018", is_active=True) event = Events(event_id="test_id5", room_id=1, event_title="Onboarding", start_time="2018-07-11T09:00:00Z", end_time="2018-07-11T09:45:00Z", number_of_participants=4, checked_in=False, cancelled=False) event.save() question_2.save() question_3 = Question(question_type="input", question_title="input Feedback", question="Any other suggestion", start_date="20 Nov 2018", end_date="28 Nov 2018") question_3.save() question_4 = Question(question_type="check", question_title="Missing item", question="Anything missing in the room?", check_options=['duster'], start_date="20 Nov 2018", end_date="30 Nov 2018", is_active=True) question_4.save() response_1 = Response( question_id=1, room_id=1, question_type="rate", created_date=datetime.now(), response="1", resolved=False, ) response_1.save() response_2 = Response( question_id=question_2.id, room_id=room.id, question_type="check", created_date=datetime.now(), response=['marker pen', 'apple tv'], resolved=True, ) response_2.save() response_2.missing_resources.append(resource) response_3 = Response(question_id=question_4.id, room_id=room_2.id, question_type="check", created_date=datetime.now(), response=['duster'], resolved=True, state="archived") response_3.save() structure = Structure( structure_id='b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968', level=1, name='Epic tower', parent_id="1", parent_title="parent_title", tag='Building', location_id=1, position=1, ) structure.save() parent_node = OfficeStructure( id='C56A4180-65AA-42EC-A945-5FD21DEC0518', name='Epic Tower', tag='Lagos Building', location_id=1) parent_node.save() child_node = OfficeStructure( id='C56A4180-65AA-42EC-A945-5FD21DEC0519', name='Gold Coast', tag='First Floor', parent_id='C56A4180-65AA-42EC-A945-5FD21DEC0518', location_id=1) child_node.save() db_session.commit() f = open('mrm.err.log', 'a+') f.write('[2019-08-06 13:22:32 +0000] [1574] [ERROR] Error /logs\r') f.write('Traceback (most recent call last):\r') f.write('if pattern.search(line):\r')
def setUp(self): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) command.stamp(self.alembic_configuration, 'head') command.downgrade(self.alembic_configuration, '-1') command.upgrade(self.alembic_configuration, 'head') admin_user = User(email="*****@*****.**", location="Kampala", name="Peter Walugembe", picture="https://www.andela.com/walugembe") admin_user.save() lagos_admin = User(email="*****@*****.**", location="Lagos", name="Peter Adeoye", picture="https://www.andela.com/adeoye") lagos_admin.save() global role role = Role(role="Admin") role.save() admin_user.roles.append(role) lagos_admin.roles.append(role) tag = Tag(name='Block-B', color='green', description='The description') tag.save() root_node = OfficeStructure(name='location', tag_id=1) root_node.save() leaf_node = OfficeStructure(name='wings', parent_id=1) leaf_node.save() location = Location(name='Kampala', abbreviation='KLA', structure_id=1) location.save() location_two = Location(name='Nairobi', abbreviation='NBO', structure_id=1) location_two.save() location_three = Location(name='Lagos', abbreviation='LOS', structure_id=1) location_three.save() tag_two = Tag(name='Block-C', color='blue', description='The description') tag_two.save() room = Room( name='Entebbe', room_type='meeting', capacity=6, location_id=location.id, calendar_id= '*****@*****.**', # noqa: E501 image_url= "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" ) # noqa: E501 room.save() room.room_tags.append(tag) resource = Resource(name='Markers', quantity=3, room_id=room.id) resource.save() device = Devices(last_seen="2018-06-08T11:17:58.785136", date_added="2018-06-08T11:17:58.785136", name="Samsung", location="Nairobi", device_type="External Display") device.save() question_1 = Question( question_type="rate", question_title="Rating Feedback", question="How will you rate the brightness of the room", start_date="20 Nov 2018", end_date="28 Nov 2018", is_active=True) question_1.save() question_2 = Question( question_type="check", question_title="check Feedback", question="Is there anything missing in the room", start_date="20 Nov 2018", end_date="30 Nov 2018", is_active=True) event = Events(event_id="test_id5", room_id=1, event_title="Onboarding", start_time="2018-07-11T09:00:00Z", end_time="2018-07-11T09:45:00Z", number_of_participants=4, checked_in=False, cancelled=False) event.save() question_2.save() question_3 = Question(question_type="input", question_title="input Feedback", question="Any other suggestion", start_date="20 Nov 2018", end_date="28 Nov 2018") question_3.save() response_1 = Response( question_id=1, room_id=1, rate=2, created_date=datetime.now(), resolved=False, ) response_1.save() response_2 = Response( question_id=question_2.id, room_id=room.id, check=True, created_date=datetime.now(), resolved=True, ) response_2.save() response_2.missing_resources.append(resource) structure = Structure( structure_id='b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968', level=1, name='Epic tower', parent_id="1", parent_title="parent_title", tag='Building', location_id=1, position=1, ) structure.save() db_session.commit()
def setUp(self): app = self.create_app() self.app_test = app.test_client() with app.app_context(): Base.metadata.create_all(bind=engine) admin_user = User(first_name="doe", last_name="jon", other_names="smith", email="*****@*****.**", password="******", picture="https://picsum.photos/200", user_type="admin") admin_user.save() citizen_user = User(first_name="doe", last_name="jon", other_names="smith", email="*****@*****.**", password="******", picture="https://picsum.photos/200", user_type="citizen") citizen_user.save() politician_user = User(first_name="doe", last_name="jon", other_names="smith", email="*****@*****.**", password="******", picture="https://picsum.photos/200", user_type="politician") politician_user.save() dup_politician_user = User(first_name="doe", last_name="jon", other_names="smith", email="*****@*****.**", password="******", picture="https://picsum.photos/200", user_type="politician") dup_politician_user.save() party = Party( party_name="party", hq_address= "5 City Of Power Avenue, Somolu, Lagos, Nigeria", # noqa logo_url="www.ipsum/pic") party.save() party_2 = Party( party_name="second_party", hq_address= "5 City Of Power Avenue, Somolu, Lagos, Nigeria", # noqa logo_url="www.ipsum/pic") party_2.save() office = Office(office_name="office", office_type="state", age_limit=50, description="my testing office") office.save() candidate = Candidate(user_id=4, office_id=1, party_id=1) candidate.save() db_session.commit()