Ejemplo n.º 1
0
    def test_delete_membership_before_user(self):
        """
         if user's membership is deleted then user should still exist
        """
        u, m = self._create_user_with_membership()
        self.assertIsNotNone(m)
        self.assertEqual(User.get_by_id(u.id).members, [m])

        m.delete()
        self.assertIsNone(Member.get_by_id(m.id))
        self.assertIsNotNone(User.get_by_id(u.id))
        self.assertEqual(User.get_by_id(u.id).members, [])
Ejemplo n.º 2
0
 def test_delete_purchase(self):
     """
     Purchase deleted -> Member NOT deleted -> User NOT deleted
     """
     p, m, u = self._create_purchase_with_member_with_user()
     p.delete()
     self.assertEqual(Purchase.query.count(), 0)
     assert not Purchase.get_by_id(p.id) and Member.get_by_id(m.id) and User.get_by_id(u.id)
     self.assertEqual(len(m.purchases), 0)
Ejemplo n.º 3
0
 def test_delete_membership(self):
     """
     Member deleted -> Purchases by that member deleted -> User NOT deleted
     """
     p, m, u = self._create_purchase_with_member_with_user()
     m.delete()
     self.assertIsNone(Purchase.get_by_id(p.id))
     self.assertIsNone(Member.get_by_id(m.id))
     self.assertIsNotNone(User.get_by_id(u.id))
     self.assertEqual(u.members, [])
Ejemplo n.º 4
0
    def test_delete_user_before_membership(self):
        """
        if user is deleted then user's membership should be deleted
        """
        u, m = self._create_user_with_membership()
        self.assertEqual(u.members, [m])
        self.assertIsNotNone(m)

        u.delete()
        self.assertIsNone(User.get_by_id(u.id))
        self.assertIsNone(Member.get_by_id(m.id))
Ejemplo n.º 5
0
def get_blogs(user_id=None):
    user = None
    if user_id:
        user = User.get_by_id(user_id)
    elif not user_id:
        user = User.get_by_email(session.get('email'))
    if not user:
        return render_template('error_404.html')
    user_blogs = user.get_blogs()
    return render_template('myblogs.html',
                           blogs=user_blogs,
                           email=session.get('email'),
                           c=0)
Ejemplo n.º 6
0
def user_interact(user_id):
    """
    Get user from DB by id
        param: user_id
        returns user
    """

    # update user
    if request.method == 'POST':
        form = AuthForm(request.form)
        User.update(user_id, {
            'email': form.email.data,
            'password': form.password.data
        })
        return f"Successfully updated user {user_id}\n"

    # get user
    user = User.get_by_id(user_id)
    return make_response(json.dumps(user, cls=AlchemyEncoder))
Ejemplo n.º 7
0
def load_user(user_id):
    """
    User by the login manager
    Load the user object from user id stored in session
    """
    return User.get_by_id(user_id)
Ejemplo n.º 8
0
 def test_delete_user(self):
     u = self._create_user()
     u.delete()
     self.assertEqual(User.query.count(), 0)
     self.assertIsNone(User.get_by_id(u.id))
Ejemplo n.º 9
0
 def test_update_user(self):
     u = self._create_user()
     new_account_id = 'abc456'
     u.update(account_id=new_account_id)
     self.assertEqual(User.get_by_id(u.id).account_id, new_account_id)