def test_leave_group_user_post(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testLeaveGroupUserGroup") person.delete_user("testLeaveGroupUser") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testLeaveGroupUser' session['group_name'] = 'testLeaveGroupUserGroup' group_member = Person("testLeaveGroupUser", "testLeaveGroupUser", "*****@*****.**", "testLeaveGroupUser") group_member_2 = Person("testLeaveGroupUser2", "testLeaveGroupUser2", "*****@*****.**", "testLeaveGroupUser2") response = client.post('/create_group', data=dict(group_name="testLeaveGroupUserGroup", selected_members=['testLeaveGroupUser2']), follow_redirects=True) self.assertEqual(["testLeaveGroupUser", "testLeaveGroupUser2"], group.get_all_users_in_group("testLeaveGroupUserGroup")) response = client.post('/leave_group_user', follow_redirects=True) self.assertIn(b'<h5 class="text-right" id="brand">testLeaveGroupUser</h5>', response.data) self.assertEqual(["testLeaveGroupUser2"], group.get_all_users_in_group("testLeaveGroupUserGroup")) group.delete_group("testLeaveGroupUserGroup") person.delete_user("testLeaveGroupUser") person.delete_user("testLeaveGroupUser2") person.remove_email_from_auth("*****@*****.**", "password")
def test_add_group_picture(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testAddGroupPictureGroup") person.delete_user("testAddGroupPicture") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testAddGroupPicture' session['group_name'] = 'testAddGroupPictureGroup' group_member = Person("testAddGroupPicture", "testAddGroupPicture", "*****@*****.**", "testAddGroupPicture") group_member_2 = Person("testAddGroupPicture2", "testAddGroupPicture2", "*****@*****.**", "testAddGroupPicture2") response = client.post('/create_group', data=dict(group_name="testAddGroupPictureGroup", selected_members=['testAddGroupPicture2']), follow_redirects=True) response = client.post("/add_group_picture", data=dict(image=(io.BytesIO(b"test bytes"), 'test.jpg')), follow_redirects=True) self.assertIn(b'testAddGroupPictureGroup_group_picture.JPG', response.data) group.delete_group("testAddGroupPictureGroup") person.delete_user("testAddProfilePicture") person.delete_user("testAddProfilePicture2") person.remove_email_from_auth("*****@*****.**", "password") person.remove_email_from_auth("*****@*****.**", "password")
def test_leave_group_invalid_group_name(self): p0 = Person("t0", "t0", "t0", "t0") p1 = Person("t1", "t1", "t1", "t1") p2 = Person("t2", "t2", "t2", "t2") p3 = Person("t3", "t3", "t3", "t3") Group("leave group", [p0, p1, p2, p3]) group.leave_group("leav group", "t1") self.assertRaises(Exception) group.delete_group("leave group")
def test_leave_group(self): p0 = Person("t0", "t0", "t0", "t0") p1 = Person("t1", "t1", "t1", "t1") p2 = Person("t2", "t2", "t2", "t2") p3 = Person("t3", "t3", "t3", "t3") Group("leave group", [p0, p1, p2, p3]) group.leave_group("leave group", "t1") self.assertEqual(3, len(group.get_all_users_in_group("leave group"))) group.delete_group("leave group")
def test_get_venmos2(self): p0 = Person("b0", "b0", "b0", "b0") p1 = Person("b1", "b1", "b1", "b1") p2 = Person("b2", "b2", "b2", "b2") p3 = Person("b3", "b3", "b3", "b3") group = Group("test group", [p0, p1, p2, p3]) # Purchase("b0", "test group", "sausage", 400, {"b0": 25, "b1": 25, "b2": 25, "b3": 25}) print("WORKED")
def test_delete_purchase(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testDeletePurchaseGroup") person.delete_user("testDeletePurchase") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testDeletePurchase' session['group_name'] = 'testDeletePurchaseGroup' group_member = Person("testDeletePurchase", "testDeletePurchase", "*****@*****.**", "testDeletePurchase") group_member_2 = Person("testDeletePurchase2", "testDeletePurchase2", "*****@*****.**", "testDeletePurchase2") response = client.post('/create_group', data=dict(group_name="testDeletePurchaseGroup", selected_members=['testDeletePurchase2']), follow_redirects=True) response = client.post('/add_purchase', data=dict(item="testItem", price=1.23, testDeletePurchase=50, testDeletePurchase2=50), follow_redirects=True) self.assertEqual((['testItem'], ['testDeletePurchase'], ['1.23']), group.get_all_purchases_for_group("testDeletePurchaseGroup")) response = client.post('/add_purchase', data=dict(item="testItem2", price=1.24, testDeletePurchase=50, testDeletePurchase2=50), follow_redirects=True) self.assertEqual((['testItem', 'testItem2'], ['testDeletePurchase', 'testDeletePurchase'], ['1.23', '1.24']), group.get_all_purchases_for_group("testDeletePurchaseGroup")) response = client.post('/delete_purchase', data=dict(item_name="testItem"), follow_redirects=True) self.assertEqual((['testItem2'], ['testDeletePurchase'], ['1.24']), group.get_all_purchases_for_group("testDeletePurchaseGroup")) group.delete_group("testDeletePurchaseGroup") person.delete_user("testDeletePurchase") person.delete_user("testDeletePurchase2") person.remove_email_from_auth("*****@*****.**", "password") person.remove_email_from_auth("*****@*****.**", "password")
def test_group_add_member(self): db.child("users").child("Morty").remove() Person("Morty", "Morty", "*****@*****.**", "Morty_venmo") Person("Morty2", "Morty2", "*****@*****.**", "Morty2_venmo") print("HERE") db.child("groups").child("test_add_member").remove() curr_group = Group("test_add_member") curr_group.add_member("Morty") curr_group.add_member("Morty2") members = db.child("groups").child("test_add_member").child( "members").get().val() self.assertEqual(len(members), 2)
def test_split(self): p0 = Person("b0", "b0", "b0", "b0") p1 = Person("b1", "b1", "b1", "b1") p2 = Person("b2", "b2", "b2", "b2") p3 = Person("b3", "b3", "b3", "b3") gr = Group("Test Split Purchases", [p0, p1, p2, p3]) Purchase("b0", "Test Split Purchases", "sausage", 400, { "b0": 25, "b1": 25, "b2": 25, "b3": 25 }) ret = group.split_purchases("Test Split Purchases") self.assertEqual(int(ret[0][2]), int(100))
def test_add_purchase_post_splits_not_100(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testAddPurchasePost") person.delete_user("testAddPurchasePostMember") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'test1' session['group_name'] = 'testAddPurchasePost' group_member = Person("testAddPurchasePostMember", "testAddPurchasePostMember", "*****@*****.**", "testAddPurchasePostMember") response = client.post('/create_group', data=dict(group_name="testAddPurchasePost", selected_members=['testAddPurchasePostMember']), follow_redirects=True) response = client.post('/add_purchase', data=dict(item="testItem", price=1.23, test1=50, testAddPurchasePostMember=49), follow_redirects=True) self.assertIn(b'Add a Purchase', response.data) group.delete_group("testAddPurchasePost") person.delete_user("testAddPurchasePostMember") person.remove_email_from_auth("*****@*****.**", "password")
def sign_up(email: str, password: str, name: str, username: str, venmo: str) -> Dict: """Signs the user up and adds them to the Firebase database. If they do not input the values correctly or enter information such as an email or username that already exists, an error code will be returned. :param email: (str) The specific user's email address for their account :param password: (str) The specific user's password for their account :param name: (str) The specific user's full name (first and last name) :param username: (str) The specific user's username to be used when creating groups and purchases :param venmo: (str) The specific user's venmo username that will be accessed later for payment requests :return: (dictionary) containing the specific error_code (0 to pass, 1 to fail) and an associated message explaining what the specific issue is """ users = db.child("users").get().val() response = {} if users is not None and username in users.keys(): response['error_code'] = 1 response['msg'] = 'Username already exists.' return response try: auth.create_user_with_email_and_password(email, password) # create the person Person(name, username, email, venmo) response['error_code'] = 0 response['msg'] = "Account successfully created! Log in now." except Exception as e: # TODO: Make error output correct response['error_code'] = 1 response[ 'msg'] = "Email already exists, please use a new email address to log in!" return response
def test_add_purchase_post_with_image(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testAddPurchasePost") person.delete_user("testAddPurchasePostMember") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'test1' session['group_name'] = 'testAddPurchasePost' group_member = Person("testAddPurchasePostMember", "testAddPurchasePostMember", "*****@*****.**", "testAddPurchasePostMember") response = client.post('/create_group', data=dict(group_name="testAddPurchasePost", selected_members=['testAddPurchasePostMember']), follow_redirects=True) response = client.post('/add_purchase', data=dict(image=(io.BytesIO(b"test bytes"), 'test.jpg'), item="testItem", price=1.23, test1=50, testAddPurchasePostMember=50), follow_redirects=True) self.assertIn(b'<b>Buyer: </b>test1', response.data) self.assertIn(b'<b>Item: </b>testItem', response.data) self.assertIn(b'<b>Cost: </b>1.23', response.data) group.delete_group("testAddPurchasePost") person.delete_user("testAddPurchasePostMember") person.remove_email_from_auth("*****@*****.**", "password")
def test_add_person_no_name(self): db.child("users").child("Morty").remove() all_users = db.child("users").get().val() prev_users_count = len(all_users) Person("", "Morty", "*****@*****.**", "Morty_venmo") all_users = db.child("users").get().val() updated_users_count = len(all_users) self.assertEqual(prev_users_count, updated_users_count)
def test_delete_user(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testLeaveGroupUserGroup") person.delete_user("testDeleteUser") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testDeleteUser' user = Person("testDeleteUser", "testDeleteUser", "*****@*****.**", "testDeleteUser") response = client.get('/delete_user', follow_redirects=True) self.assertIn(b'Sign Up', response.data)
def test_create_group_post(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testCreateGroupPost") person.delete_user("testCreateGroupPostMember") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = "test1" group_member = Person("testCreateGroupPostMember", "testCreateGroupPostMember", "*****@*****.**", "testCreateGroupPostMember") response = client.post('/create_group', data=dict(group_name="testCreateGroupPost", selected_members=['testCreateGroupPostMember']), follow_redirects=True) self.assertIn(b'testCreateGroupPost', response.data) group.delete_group("testCreateGroupPost") person.delete_user("testCreateGroupPostMember") person.remove_email_from_auth("*****@*****.**", "password")
def test_venmo_display(self): flask_app = create_app() client = flask_app.test_client() with client.session_transaction() as session: session['is_logged'] = 'test1' session['group_name'] = 'testVenmoDisplayGroup' group_member = Person("testVenmoDisplay", "testVenmoDisplay", "*****@*****.**", "testVenmoDisplayVENMO") response = client.post('/create_group', data=dict(group_name="testVenmoDisplayGroup", selected_members=['testVenmoDisplay']), follow_redirects=True) response = client.get('/group', follow_redirects=True) self.assertIn(b'testVenmoDisplay', response.data) self.assertIn(b'Venmo: </b>testVenmoDisplayVENMO', response.data) group.delete_group("testVenmoDisplayGroup") person.delete_user("testVenmoDisplay") person.remove_email_from_auth("*****@*****.**", "password")
def test_leave_group_user_get(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testLeaveGroupUserGroup") person.delete_user("testLeaveGroupUser") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testLeaveGroupUser' session['group_name'] = 'testLeaveGroupUserGroup' group_member = Person("testLeaveGroupUser", "testLeaveGroupUser", "*****@*****.**", "testLeaveGroupUser") response = client.get('/leave_group_user', follow_redirects=True) self.assertIn(b'<h5 class="text-right" id="brand">testLeaveGroupUser</h5>', response.data) group.delete_group("testLeaveGroupUserGroup") person.delete_user("testLeaveGroupUser") person.remove_email_from_auth("*****@*****.**", "password")
def test_leave_group(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("testLeaveGroupGroup") person.delete_user("testLeaveGroup") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'testLeaveGroup' session['group_name'] = 'testLeaveGroupGroup' group_member = Person("testLeaveGroup", "testLeaveGroup", "*****@*****.**", "testLeaveGroup") response = client.get('/leave_group', follow_redirects=True) self.assertIn(b'Would you, testLeaveGroup, like to leave group testLeaveGroupGroup?', response.data) group.delete_group("testLeaveGroupGroup") person.delete_user("testLeaveGroup") person.remove_email_from_auth("*****@*****.**", "password")
def test_get_venmo(self): flask_app = create_app() client = flask_app.test_client() group.delete_group("groupGetVenmo") person.delete_user("testGetVenmoMember") person.remove_email_from_auth("*****@*****.**", "password") with client.session_transaction() as session: session['is_logged'] = 'test1' session['group_name'] = 'groupGetVenmo' group_member = Person("testGetVenmoMember", "testGetVenmoMember", "*****@*****.**", "testGetVenmoMember") response = client.post('/create_group', data=dict(group_name="groupGetVenmo", selected_members=['testGetVenmoMember']), follow_redirects=True) response = client.get('/get_venmo', follow_redirects=True) self.assertIn(b'List of Venmo Transactions For Group:', response.data) group.delete_group("groupGetVenmo") person.delete_user("testGetVenmoMember") person.remove_email_from_auth("*****@*****.**", "password")
def test_no_person_profile_picture(self): db.child("users").child("Morty").remove() Person("Morty", "Morty", "*****@*****.**", "morty-venmo") self.assertFalse(person.has_profile_picture("Morty"))
def test_get_default_profile_picture(self): db.child("users").child("Morty").remove() Person("Morty", "Morty", "*****@*****.**", "morty-venmo") pic_link = person.get_default_profile_picture() self.assertFalse(pic_link is None)
def test_add_person_profile_picture(self): db.child("users").child("Morty").remove() Person("Morty", "Morty", "*****@*****.**", "morty-venmo") person.add_profile_picture(None, "Morty") self.assertTrue(person.has_profile_picture("Morty"))