コード例 #1
0
 def test_add(self):
     """
     Behaviour: Calling the API to add credit should result credit being added to
     the database.
     """
     user = create_user('user','testuser2','testuser2','testuser2')
     touch_to_add_credit(user,1000)
     credit = check_credit(user)
     self.assertEqual(credit, 1000)
コード例 #2
0
 def test_subtract(self):
     """
     Behaviour: Calling the API to add credit should result credit being
     subtracted from the database.
     """
     user = create_user('user', 'testuser3', 'testuser3', 'testuser3')
     touch_to_add_credit(user,-500)
     credit = check_credit(user)
     self.assertEqual(credit, -500)
コード例 #3
0
ファイル: views.py プロジェクト: environmentalomics/eos-db
def retrieve_user_credit(request):
    """Return credits outstanding for any user.

    :param name: User for which we are checking credit.
    :returns: JSON containing actor_id and current balance.
    """
    username = request.matchdict['name']
    try:
        user_id = server.get_user_id_from_name(username)
        credits = server.check_credit(user_id)
        return {'actor_id': user_id, 'credit_balance': int(credits)}
    except KeyError as e:
        return HTTPNotFound(str(e))
コード例 #4
0
ファイル: views.py プロジェクト: cedadev/eos-db
def retrieve_user_credit(request):
    """Return credits outstanding for any user.

    :param name: User for which we are checking credit.
    :returns: JSON containing actor_id and current balance.
    """
    username = request.matchdict["name"]
    try:
        user_id = server.get_user_id_from_name(username)
        credits = server.check_credit(user_id)
        return {"actor_id": user_id, "credit_balance": int(credits)}
    except KeyError as e:
        return HTTPNotFound(str(e))
コード例 #5
0
ファイル: views.py プロジェクト: environmentalomics/eos-db
def retrieve_my_user(request):
    """Return account details for logged-in user.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.authenticated_userid
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({'credits': server.check_credit(actor_id)})
        return details
    except KeyError:
        #Should be impossible unless a logged-in user is deleted.
        return HTTPInternalServerError()
コード例 #6
0
ファイル: views.py プロジェクト: environmentalomics/eos-db
def retrieve_user(request):
    """Return account details for any user.  Anybody should be able to do this,
       though most users have no need to.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.matchdict['name']
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({'credits': server.check_credit(actor_id)})
        return details
    except KeyError:
        return HTTPNotFound()
コード例 #7
0
ファイル: views.py プロジェクト: cedadev/eos-db
def retrieve_my_user(request):
    """Return account details for logged-in user.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.authenticated_userid
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({"credits": server.check_credit(actor_id)})
        return details
    except KeyError:
        # Should be impossible unless a logged-in user is deleted.
        return HTTPInternalServerError()
コード例 #8
0
ファイル: views.py プロジェクト: cedadev/eos-db
def retrieve_user(request):
    """Return account details for any user.  Anybody should be able to do this,
       though most users have no need to.

    :param name: The user we are interested in.
    :returns JSON object containing user table data.
    """
    username = request.matchdict["name"]
    try:
        actor_id = server.get_user_id_from_name(username)
        details = server.check_user_details(actor_id)
        details.update({"credits": server.check_credit(actor_id)})
        return details
    except KeyError:
        return HTTPNotFound()
コード例 #9
0
ファイル: views.py プロジェクト: cedadev/eos-db
def create_user_credit(request):
    """Adds credit to a user account, negative or positive.  Only an administrator can do this
       directly.  Boost and Deboost actions will do this implicitly.

    Checks if username is valid, otherwise throws HTTP 404.
    Checks if credit is an integer, otherwise throws HTTP 400.

    :param name: User for which we are amending credit.
    :returns: JSON containing actor id, credit change and new balance.
    """
    username, credit = request.matchdict["name"], request.POST["credit"]
    try:
        user_id = server.get_user_id_from_name(username)
        server.touch_to_add_credit(user_id, int(credit))
        credits = server.check_credit(user_id)
        return {"actor_id": int(user_id), "credit_change": int(credit), "credit_balance": int(credits)}
    except ValueError:
        return HTTPBadRequest()
    except KeyError:
        return HTTPNotFound()
コード例 #10
0
ファイル: views.py プロジェクト: cedadev/eos-db
def create_user_credit(request):
    """Adds credit to a user account, negative or positive.  Only an administrator can do this
       directly.  Boost and Deboost actions will do this implicitly.

    Checks if username is valid, otherwise throws HTTP 404.
    Checks if credit is an integer, otherwise throws HTTP 400.

    :param name: User for which we are amending credit.
    :returns: JSON containing actor id, credit change and new balance.
    """
    username, credit = request.matchdict['name'], request.POST['credit']
    try:
        user_id = server.get_user_id_from_name(username)
        server.touch_to_add_credit(user_id, int(credit))
        credits = server.check_credit(user_id)
        return  {'actor_id': int(user_id),
                 'credit_change': int(credit),
                 'credit_balance': int(credits)}
    except ValueError:
        return HTTPBadRequest()
    except KeyError:
        return HTTPNotFound()