Exemplo n.º 1
0
    def test_set_user_auth_token(self):
        user = G(User)
        key = "Avengers Assemble!"
        self.assertFalse(Token.objects.filter(user=user).exists())
        set_user_auth_token(user, key)
        self.assertEqual(Token.objects.get(user=user).key, key)

        key = "Hulk Smash!"
        set_user_auth_token(user, key)
        self.assertEqual(Token.objects.get(user=user).key, key)

        # Verify we don't create token conflicts
        user2 = G(User)
        self.assertRaises(AttributeError, set_user_auth_token, user2, key)
    def test_set_user_auth_token(self):
        user = G(User)
        key = "Avengers Assemble!"
        self.assertFalse(Token.objects.filter(user=user).exists())
        set_user_auth_token(user, key)
        self.assertEqual(Token.objects.get(user=user).key, key)

        key = "Hulk Smash!"
        set_user_auth_token(user, key)
        self.assertEqual(Token.objects.get(user=user).key, key)

        # Verify we don't create token conflicts
        user2 = G(User)
        self.assertRaises(AttributeError, set_user_auth_token, user2, key)
Exemplo n.º 3
0
    def handle(self, *args, **options):
        if options['username'] is None:
            raise CommandError("You must supply a username.")

        username = options['username']

        if options['delete_key']:
            delete_user_auth_token(username)
            print 'Removed API key for user: <{0}>'.format(username)
        else:
            if options['api_key'] is None:
                raise CommandError("You must supply both a username and key.")

            # pylint: disable=no-member
            user, _ = User.objects.get_or_create(username=username)

            try:
                key = options['api_key']
                set_user_auth_token(user, key)
            except AttributeError:
                print "The key %s is in use by another user. Please select another key." % key
Exemplo n.º 4
0
    def handle(self, *args, **options):
        if options['username'] is None:
            raise CommandError("You must supply a username.")

        username = options['username']

        if options['delete_key']:
            delete_user_auth_token(username)
            print 'Removed API key for user: <{0}>'.format(username)
        else:
            if options['api_key'] is None:
                raise CommandError("You must supply both a username and key.")

            # pylint: disable=no-member
            user, _ = User.objects.get_or_create(username=username)

            try:
                key = options['api_key']
                set_user_auth_token(user, key)
            except AttributeError:
                print "The key %s is in use by another user. Please select another key." % key