def get(self): if request.args.get('email_or_username'): ms_users = [ MinespaceUser.find_by_email( request.args.get('email_or_username')) ] else: ms_users = MinespaceUser.get_all() return ms_users
def test_minespace_user_model_find_all(db_session): user1 = MinespaceUserFactory() user2 = MinespaceUserFactory() all_mu = MinespaceUser.get_all() assert len(all_mu) == 2 assert any(mu.email == user1.email for mu in all_mu)
def setup_info(test_client): mu = MinespaceUser.create_minespace_user(TEST_MINESPACE_USER_EMAIL1) mu.save() yield dict(test_minespace_user_email=TEST_MINESPACE_USER_EMAIL1, test_minespace_user_id=mu.user_id) db.session.delete(mu) db.session.commit()
def post(self): data = self.parser.parse_args() new_user = MinespaceUser.create_minespace_user(data.get('email')) new_user.save() for guid in data.get('mine_guids'): guid = uuid.UUID(guid) #ensure good formatting new_mum = MinespaceUserMine.create(new_user.user_id, guid) new_mum.save() return new_user
def delete(self, user_id): user = MinespaceUser.find_by_id(user_id) if not user: raise NotFound("user not found") for um in user.mines: db.session.delete(um) db.session.commit() db.session.delete(user) db.session.commit() return ('', 204)
def test_post_minespace_user_new_email(test_client, auth_headers, setup_info): data = { "email": "*****@*****.**", "mine_guids": ["7dc50e1c-18cf-4272-9d5c-eb144959e109"] } post_resp = test_client.post('/users/minespace', json=data, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 200, post_resp.response new_mu = MinespaceUser.find_by_email(data["email"]) db.session.delete(new_mu) db.session.commit() assert json.loads(post_resp.data.decode())["email"] == data["email"]
def delete(self, user_id=None, mine_guid=None): if not user_id or not mine_guid: raise BadRequest("user_guid or mine_guid not found") user = MinespaceUser.find_by_id(user_id) if not user: raise NotFound("user not found") found = False for mum in user.mines: if str(mum.mine_guid) == mine_guid: db.session.delete(mum) found = True break if not found: raise NotFound('user is not related to the provided mine') user.save() return ('', 204)
def get(self, user_id): user = MinespaceUser.find_by_id(user_id) if not user: raise NotFound("user not found") return user
def test_minespace_user_model_find_by_id(db_session): user = MinespaceUserFactory() mu = MinespaceUser.find_by_id(user.user_id) assert mu.email == user.email
def test_minespace_user_model_find_by_email(db_session): email = MinespaceUserFactory().email mu = MinespaceUser.find_by_email(email) assert mu.email == email
def test_delete_minespace_success(test_client, auth_headers, setup_info): new_mu = MinespaceUser.create_minespace_user(email="*****@*****.**") db.session.commit() del_resp = test_client.delete('/users/minespace/' + str(new_mu.user_id), headers=auth_headers['full_auth_header']) assert del_resp.status_code == 204, del_resp.response
def test_setup_data(test_client): mu = MinespaceUser.create_minespace_user('*****@*****.**') mu.save()
def test_minespace_user_model_find_by_email(db_session): email_or_username = MinespaceUserFactory().email_or_username mu = MinespaceUser.find_by_email(email_or_username) assert mu.email_or_username == email_or_username