Example #1
0
def show(request, profile_id):
    profile = Profile.all().filter('uid =', profile_id).get()
    #bd_end_user = EndUser(end_user_login=profile.uid)

    eul = "profile:%s" % profile.uid
    c = Client(settings.BDM_SECRET, settings.BDM_KEY)
    try:
        bd_end_user = c.get('end_user/%s' % eul)[0]
    except ValueError, e:
        payload = dict(end_user_login=eul)
        bd_end_user = c.post('end_user', payload=payload)[0]
Example #2
0
    def kill(self, killed_by_role, round_number):
        self.is_dead = True
        self.put()

        # TODO: these should be moved to tasks
        # at this point, we don't care if the response is good or not.
        c = Client(settings.BDM_SECRET, settings.BDM_KEY)
        
        txn_id = kill_txn_ids[self.get_side()][killed_by_role]
        eul = "profile:%s" % self.player.uid

        endpoint = "named_transaction_group/%d/execute/%s"
        endpoint = endpoint % (txn_id, eul)
        resp = c.post(endpoint)

        if round_number == 1 and killed_by_role == role_vanillager:
            # Bandwagoned. <Nelson>Ha ha!</Nelson>
            endpoint = "named_transaction_group/613292/execute/%s" % eul
            resp = c.post(endpoint)
Example #3
0
 def setUp(self):
     self.client = Client(TEST_APP_SECRET, TEST_APP_KEY)
Example #4
0
class TestClient(TestCase):
    def setUp(self):
        self.client = Client(TEST_APP_SECRET, TEST_APP_KEY)

    def test_client_init(self):
        # test the basics
        assert_equal(self.client.app_secret, TEST_APP_SECRET)
        assert_equal(self.client.app_key, TEST_APP_KEY)

    def test_generate_signature(self):
        expected_sig = "9d1550bb516ee2cc47d163b4b99f00e15c84b3cd32a82df9fd808aa0eb505f04"
        params = {"time": 1270503018.33}
        url = "/api/publisher/%s/transaction_summary" % TEST_APP_KEY
        sig = self.client.generate_signature(url, params)
        assert_equal(expected_sig, sig)

    def test_generate_signature_without_params(self):
        expected_sig = "fa5ae4f36a4d90abae0cbbe5fd3d59b73bae6638ff517e9c26be64569c696bcc"
        url = "/api/publisher/%s/transaction_summary" % TEST_APP_KEY
        sig = self.client.generate_signature(url)
        assert_equal(expected_sig, sig)

    def test_generate_signature_with_whitelisted_params(self):
        expected_sig = "fa5ae4f36a4d90abae0cbbe5fd3d59b73bae6638ff517e9c26be64569c696bcc"
        url = "/api/publisher/%s/transaction_summary" % TEST_APP_KEY
        params = {"format": "json", "sig": "this_sig_is_fake!"}
        sig = self.client.generate_signature(url, params)
        assert_equal(expected_sig, sig)

    def test_generate_signature_with_post_params(self):
        from time import time

        expected_sig = "cd073723c4901b57466694f63a2b7746caf1836c9bcdd4f98d55357334c2de64"
        url = "/api/publisher/%s/currency/1" % TEST_APP_KEY
        query_params = {"format": "json", "time": "1270517162.52"}
        body_params = {
            "end_user_description": "Testing signature generation.",
            "time": "1270517162.52",
            "token": "bd323c0ca7c64277ba2b0cd9f93fe463",
        }
        sig = self.client.generate_signature(url, query_params, body_params)
        assert_equal(expected_sig, sig)

    def test_generate_signature_with_unicode(self):
        expected_sig = "bc41b88b9cf85434893169cd844da161530ee645fc18dc64c51568ed3b0de075"
        url = "/api/publisher/%s/currency/1" % TEST_APP_KEY

        title = 'Bashō\'s "old pond"'.decode("utf-8")
        description = "古池や蛙飛込む水の音".decode("utf-8")

        query_params = {"format": "json", "time": "1270517162.52"}

        body_params = {
            "end_user_title": title,
            "end_user_description": description,
            "time": "1270517162.52",
            "token": "bd323c0ca7c64277ba2b0cd9f93fe463",
        }

        sig = self.client.generate_signature(url, query_params, body_params)
        assert_equal(expected_sig, sig)

    def test_get(self):
        result = self.client.get("transaction_summary")
        assert_equal(len(result[0][0]), 10)

    def test_delete(self):
        raise SkipTest()
        result = self.client.delete("currency/1")

    def test_post(self):
        raise SkipTest()
        result = self.client.post("currency")

    def test_put(self):
        raise SkipTest()
        result = self.client.put("currency/1")
Example #5
0
def votes(request, game_id, round_id, thread_id):
    thread = Thread.get_by_uid(thread_id)
    game = Game.get_by_uid(game_id)
    if thread is None:
        raise Http404

    if not thread.profile_can_view(request.profile):
        return HttpResponse('Unauthorized', status=401)

    if request.method == 'GET':
        since = request.GET.get('since', None)
        return json(Vote.get_activities(request.user, thread, since=since))

    if request.method == 'POST':
        if not thread.profile_can_create(request.profile):
            return HttpResponse('Unauthorized', status=401)

        # find the target
        target_id = request.POST.get('target_id', None)
        if target_id is None:
            raise Exception('No target')

        target_profile = Profile.get_by_uid(target_id)
        target = Role.all().filter('player', target_profile)
        target = target.filter('game', game)
        target = target.fetch(1)[0]

        # find the last vote this user made (if any)
        game = Game.get_by_uid(game_id)
        actor = Role.get_by_profile(game, request.profile)

        last_vote = Vote.all().filter("thread", thread)
        last_vote = last_vote.filter("actor", actor)
        last_vote = last_vote.order("-created")
        try:
            last_vote = last_vote.fetch(1)[0]
        except IndexError, e:
            last_vote = None

        # if we found a vote, decrement that vote's counter
        if last_vote is not None:
            last_vote.decrement()

        # create the new vote
        vote = Vote(actor=actor,
                    target=target,
                    thread=thread)
        vote.put()

        # increment the counter
        vote.increment()

        if thread.name == role_vanillager:
            vote_count = Vote.all().filter('thread', thread).count()
            if not vote_count:
                # First vote in round
                c = Client(settings.BDM_SECRET, settings.BDM_KEY)
                eul = "profile:%s" % request.profile.uid
                c.post("named_transaction_group/613301/execute/%s" % eul)
                if thread.round.number == 1:
                    # First vote in game
                    c.post("named_transaction_group/613302/execute/%s" % eul)

        return json(vote)
Example #6
0
        #deal with the error here
        raise

    if vote > 0:
        # vote up
        vote_value = 1
    else:
        vote_value = -1

    incident_uid = request.GET['objid']
    incident = models.Incident.objects.get(objid=incident_uid)

    app_key = 'e608258751c54fb4adba113c7998dc69'
    secret_key = 'beec8efa9a014573b12e59498554b9c0'
    # create an instance of the bigdoor client
    c = Client(secret_key, app_key)

    # create request post data
    payload = dict(amount=vote_value,
                   verbosity=9,
                   allow_negative_balance=1)
    # execute transaction for incident
    resp = c.post('named_transaction_group/612563/execute/incident:%d' % incident.objid,
                  payload=payload)
    resp = resp[0]


    balances = resp['end_user']['currency_balances']

    # this probably wants to be pulled from settings
    vote_currency_id = 1065