Esempio n. 1
0
 def test_user_does_not_unlock_achievement(self):
     """
     Tests that an achievement is not improperly
     unlocked.
     """
     payload = {"action": "forced"}
     unlocked = check_for_unlocked_achievements('pull_request', payload)
     self.assertTrue(
         len(unlocked) == 0,
         'Achievement should not be unlocked for non-matching event.')
     payload = {"action": ""}
     unlocked = check_for_unlocked_achievements('push', payload)
     self.assertTrue(
         len(unlocked) == 0,
         'Achievement should not be unlocked for non-matching value.')
Esempio n. 2
0
    def test_qualifiers_01(self):
        """
        Tests that qualifiers actually work.
        """
        payload = {'download': {'url': "http", 'html_url': "hfss"}}
        unlocked = check_for_unlocked_achievements('download', payload)
        self.assertTrue(
            len(unlocked) == 2,
            'Achievement should be unlocked based on qualifier.')

        payload = {'download': {'url': "Http", 'html_url': "https"}}
        unlocked = check_for_unlocked_achievements('download', payload)
        self.assertTrue(
            len(unlocked) == 0,
            'Achievement should not be unlocked based on qualifier.')
Esempio n. 3
0
 def test_user_unlocks_achievement(self):
     """
     Tests that a user can unlock an achievement.
     """
     payload = {"action": "forced"}
     unlocked = check_for_unlocked_achievements('push', payload)
     self.assertTrue(len(unlocked) == 1, 'Achievement should be unlocked.')
Esempio n. 4
0
    def process_event(cls, event_name, event):
        """
        Processes a hook service event from Github.
        """
        # Create the Event object as a convenience
        event = EventData(event_name, **event)
        unlocked = []
        if event.user is not None:
            unlocked = check_for_unlocked_achievements(event_name, event,
                                                       event.user)

        return json_response(unlocked)
Esempio n. 5
0
def web_local_hook(request):
    """
    Processes a request from a local web service request.

    @param: HttpRequest
    @return: HttpResponse
    """
    data = json.loads(request.body)
    data = check_for_unlocked_achievements(data.get('event'),
                                           data.get('payload'))

    return HttpResponse(json.dumps(data),
                        status=200,
                        content_type="application/json")
Esempio n. 6
0
    def test_quantifier_01(self):
        """
        Tests that quantifiers actually work.
        """
        payload = {
            'download': {
                'files': [{
                    'name': "a.txt"
                }, {
                    'name': "b.txtp"
                }]
            }
        }

        self.assertEqual(
            ["a.txt", "b.txtp"],
            find_nested_json(payload, "download.files.name".split('.')),
            "Nested json results should match the values in the list.")
        unlocked = check_for_unlocked_achievements('download', payload)
        self.assertTrue(
            len(unlocked) == 1,
            'Achievement was unlocked via quantifer and __or__')