Ejemplo n.º 1
0
    def test_delete_user_auth_token(self):
        # Create user and token
        user = G(User)
        G(Token, user=user)

        # Verify token exists
        self.assertTrue(Token.objects.filter(user=user).exists())

        # Call delete method
        delete_user_auth_token(user.username)

        # Verify token no longer exists
        self.assertFalse(Token.objects.filter(user=user).exists())
    def test_delete_user_auth_token(self):
        # Create user and token
        user = G(User)
        G(Token, user=user)

        # Verify token exists
        self.assertTrue(Token.objects.filter(user=user).exists())

        # Call delete method
        delete_user_auth_token(user.username)

        # Verify token no longer exists
        self.assertFalse(Token.objects.filter(user=user).exists())
Ejemplo 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
Ejemplo 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
Ejemplo n.º 5
0
 def test_delete_user_auth_token_non_existing(self):
     user = G(User)
     self.assertFalse(Token.objects.filter(user=user).exists())
     delete_user_auth_token(user.username)
     self.assertFalse(Token.objects.filter(user=user).exists())
 def test_delete_user_auth_token_non_existing(self):
     user = G(User)
     self.assertFalse(Token.objects.filter(user=user).exists())
     delete_user_auth_token(user.username)
     self.assertFalse(Token.objects.filter(user=user).exists())