prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Test management commands
  Because in three years, run_tasks will silently fail on the production system and nobody will notice.
  - [x] **run_tasks** - shouldn't be too hard and is rather important
  - [x] **anonymize** - might be a bit of work to cover it properly, but should be straightforward.
  - [x] **refresh_results_cache** - should be easy
  - [x] **dump_testdata** - don't know how not to overwrite the file during testing, but should be possible
  
  the other commands are already tested or rather unsuitable for testing
  - [x] **merge_users** - already has a test (#703) and is shown to be pretty broken.
  - [x] **run** - don't know how to test this and there isn't really anything that could break. still, somehow running it to check that it doesn't crash right away on e.g. imports would be cool
  - [x] **reload_testdata** - don't know whether it's possible at all to test that, i mean it drops the whole database...
  - [ ] **import_ad** - we never used it and i don't know whether it's feasible to mock ldap
  
  use `self.stdout.write` instead of `print` and `call_command("command_name", stdout=StringIO())` to avoid console output during tests. don't know what to do about calls to `input`.
  
  
  </issue>
  <code>
  [start of evap/evaluation/management/commands/import_ad.py]
  1 import getpass
  2 import ldap
  3 import sys
  4 
  5 from django.core.management.base import BaseCommand
  6 
  7 from evap.evaluation.models import UserProfile
  8 
  9 
  10 class Command(BaseCommand):
  11     args = '<ldap server> <username>'
  12     help = 'Imports user data from Active Directory. The username should be specified with realm.'
  13 
  14     def handle(self, *args, **options):
  15         try:
  16             # connect
  17             l = ldap.initialize(args[0])
  18 
  19             # bind
  20             l.bind_s(args[1], getpass.getpass("AD Password: "))
  21 
  22             # find all users
  23             result = l.search_s("OU=INSTITUT,DC=hpi,DC=uni-potsdam,DC=de", ldap.SCOPE_SUBTREE, filterstr="(&(&(objectClass=user)(!(objectClass=computer)))(givenName=*)(sn=*)(mail=*))")
  24             for _, attrs in result:
  25                 try:
  26                     user = UserProfile.objects.get(username__iexact=attrs['sAMAccountName'][0])
  27                     user.first_name = attrs['givenName'][0]
  28                     user.last_name = attrs['sn'][0]
  29                     user.email = attrs['mail'][0]
  30                     user.save()
  31 
  32                     print("Successfully updated: '{0}'".format(user.username))
  33                 except UserProfile.DoesNotExist:
  34                     pass
  35                 except Exception as e:
  36                     print(e)
  37 
  38             l.unbind_s()
  39 
  40         except KeyboardInterrupt:
  41             sys.stderr.write("\nOperation cancelled.\n")
  42             sys.exit(1)
  43
  [end of evap/evaluation/management/commands/import_ad.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/evap/evaluation/management/commands/import_ad.py b/evap/evaluation/management/commands/import_ad.py
  deleted file mode 100644
  --- a/evap/evaluation/management/commands/import_ad.py
  +++ /dev/null
  @@ -1,42 +0,0 @@
  -import getpass
  -import ldap
  -import sys
  -
  -from django.core.management.base import BaseCommand
  -
  -from evap.evaluation.models import UserProfile
  -
  -
  -class Command(BaseCommand):
  -    args = '<ldap server> <username>'
  -    help = 'Imports user data from Active Directory. The username should be specified with realm.'
  -
  -    def handle(self, *args, **options):
  -        try:
  -            # connect
  -            l = ldap.initialize(args[0])
  -
  -            # bind
  -            l.bind_s(args[1], getpass.getpass("AD Password: "))
  -
  -            # find all users
  -            result = l.search_s("OU=INSTITUT,DC=hpi,DC=uni-potsdam,DC=de", ldap.SCOPE_SUBTREE, filterstr="(&(&(objectClass=user)(!(objectClass=computer)))(givenName=*)(sn=*)(mail=*))")
  -            for _, attrs in result:
  -                try:
  -                    user = UserProfile.objects.get(username__iexact=attrs['sAMAccountName'][0])
  -                    user.first_name = attrs['givenName'][0]
  -                    user.last_name = attrs['sn'][0]
  -                    user.email = attrs['mail'][0]
  -                    user.save()
  -
  -                    print("Successfully updated: '{0}'".format(user.username))
  -                except UserProfile.DoesNotExist:
  -                    pass
  -                except Exception as e:
  -                    print(e)
  -
  -            l.unbind_s()
  -
  -        except KeyboardInterrupt:
  -            sys.stderr.write("\nOperation cancelled.\n")
  -            sys.exit(1)
  
verification_info: {"golden_diff": "diff --git a/evap/evaluation/management/commands/import_ad.py b/evap/evaluation/management/commands/import_ad.py\ndeleted file mode 100644\n--- a/evap/evaluation/management/commands/import_ad.py\n+++ /dev/null\n@@ -1,42 +0,0 @@\n-import getpass\n-import ldap\n-import sys\n-\n-from django.core.management.base import BaseCommand\n-\n-from evap.evaluation.models import UserProfile\n-\n-\n-class Command(BaseCommand):\n-    args = '<ldap server> <username>'\n-    help = 'Imports user data from Active Directory. The username should be specified with realm.'\n-\n-    def handle(self, *args, **options):\n-        try:\n-            # connect\n-            l = ldap.initialize(args[0])\n-\n-            # bind\n-            l.bind_s(args[1], getpass.getpass(\"AD Password: \"))\n-\n-            # find all users\n-            result = l.search_s(\"OU=INSTITUT,DC=hpi,DC=uni-potsdam,DC=de\", ldap.SCOPE_SUBTREE, filterstr=\"(&(&(objectClass=user)(!(objectClass=computer)))(givenName=*)(sn=*)(mail=*))\")\n-            for _, attrs in result:\n-                try:\n-                    user = UserProfile.objects.get(username__iexact=attrs['sAMAccountName'][0])\n-                    user.first_name = attrs['givenName'][0]\n-                    user.last_name = attrs['sn'][0]\n-                    user.email = attrs['mail'][0]\n-                    user.save()\n-\n-                    print(\"Successfully updated: '{0}'\".format(user.username))\n-                except UserProfile.DoesNotExist:\n-                    pass\n-                except Exception as e:\n-                    print(e)\n-\n-            l.unbind_s()\n-\n-        except KeyboardInterrupt:\n-            sys.stderr.write(\"\\nOperation cancelled.\\n\")\n-            sys.exit(1)\n", "issue": "Test management commands\nBecause in three years, run_tasks will silently fail on the production system and nobody will notice.\n- [x] **run_tasks** - shouldn't be too hard and is rather important\n- [x] **anonymize** - might be a bit of work to cover it properly, but should be straightforward.\n- [x] **refresh_results_cache** - should be easy\n- [x] **dump_testdata** - don't know how not to overwrite the file during testing, but should be possible\n\nthe other commands are already tested or rather unsuitable for testing\n- [x] **merge_users** - already has a test (#703) and is shown to be pretty broken.\n- [x] **run** - don't know how to test this and there isn't really anything that could break. still, somehow running it to check that it doesn't crash right away on e.g. imports would be cool\n- [x] **reload_testdata** - don't know whether it's possible at all to test that, i mean it drops the whole database...\n- [ ] **import_ad** - we never used it and i don't know whether it's feasible to mock ldap\n\nuse `self.stdout.write` instead of `print` and `call_command(\"command_name\", stdout=StringIO())` to avoid console output during tests. don't know what to do about calls to `input`.\n\n", "before_files": [{"content": "import getpass\nimport ldap\nimport sys\n\nfrom django.core.management.base import BaseCommand\n\nfrom evap.evaluation.models import UserProfile\n\n\nclass Command(BaseCommand):\n    args = '<ldap server> <username>'\n    help = 'Imports user data from Active Directory. The username should be specified with realm.'\n\n    def handle(self, *args, **options):\n        try:\n            # connect\n            l = ldap.initialize(args[0])\n\n            # bind\n            l.bind_s(args[1], getpass.getpass(\"AD Password: \"))\n\n            # find all users\n            result = l.search_s(\"OU=INSTITUT,DC=hpi,DC=uni-potsdam,DC=de\", ldap.SCOPE_SUBTREE, filterstr=\"(&(&(objectClass=user)(!(objectClass=computer)))(givenName=*)(sn=*)(mail=*))\")\n            for _, attrs in result:\n                try:\n                    user = UserProfile.objects.get(username__iexact=attrs['sAMAccountName'][0])\n                    user.first_name = attrs['givenName'][0]\n                    user.last_name = attrs['sn'][0]\n                    user.email = attrs['mail'][0]\n                    user.save()\n\n                    print(\"Successfully updated: '{0}'\".format(user.username))\n                except UserProfile.DoesNotExist:\n                    pass\n                except Exception as e:\n                    print(e)\n\n            l.unbind_s()\n\n        except KeyboardInterrupt:\n            sys.stderr.write(\"\\nOperation cancelled.\\n\")\n            sys.exit(1)\n", "path": "evap/evaluation/management/commands/import_ad.py"}]}