We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
OnlineUser.year tests
We really should write some tests to verify that the year attribute actually produces a correct value.

Make sure to include:
- Any date in August should produce a correct value for year. Especially important if "now" is august
- Masters degrees are registered differently in the user object now, many field_of_study entries will be eligible for 4th and 5th year.
- What happens to a user that started in january?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/authentication/models.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import datetime
4 
5 from django.conf import settings
6 from django.contrib.auth.models import AbstractUser
7 from django.db import models
8 from django.utils.translation import ugettext as _
9 from django.utils import timezone
10 
11 
12 # If this list is changed, remember to check that the year property on
13 # OnlineUser is still correct!
14 FIELD_OF_STUDY_CHOICES = [
15     (0, _(u'Gjest')),
16     (1, _(u'Bachelor i Informatikk (BIT)')),
17     # master degrees take up the interval [10,30]
18     (10, _(u'Software (SW)')),
19     (11, _(u'Informasjonsforvaltning (DIF)')),
20     (12, _(u'Komplekse Datasystemer (KDS)')),
21     (13, _(u'Spillteknologi (SPT)')),
22     (14, _(u'Intelligente Systemer (IRS)')),
23     (15, _(u'Helseinformatikk (MSMEDTEK)')),
24     (30, _(u'Annen mastergrad')),
25     (80, _(u'PhD')),
26     (90, _(u'International')),
27     (100, _(u'Annet Onlinemedlem')),
28 ]
29 
30 class OnlineUser(AbstractUser):
31 
32     IMAGE_FOLDER = "images/profiles"
33     IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']
34     
35     # Online related fields
36     field_of_study = models.SmallIntegerField(_(u"studieretning"), choices=FIELD_OF_STUDY_CHOICES, default=0)
37     started_date = models.DateField(_(u"startet studie"), default=timezone.now().date())
38     compiled = models.BooleanField(_(u"kompilert"), default=False)
39 
40     # Email
41     infomail = models.BooleanField(_(u"vil ha infomail"), default=True)
42 
43     # Address
44     phone_number = models.CharField(_(u"telefonnummer"), max_length=20, blank=True, null=True)
45     address = models.CharField(_(u"adresse"), max_length=30, blank=True, null=True)
46     zip_code = models.CharField(_(u"postnummer"), max_length=4, blank=True, null=True)
47 
48     # Other
49     allergies = models.TextField(_(u"allergier"), blank=True, null=True)
50     mark_rules = models.BooleanField(_(u"godtatt prikkeregler"), default=False)
51     rfid = models.CharField(_(u"RFID"), max_length=50, blank=True, null=True)
52     nickname = models.CharField(_(u"nickname"), max_length=50, blank=True, null=True)
53     website = models.URLField(_(u"hjemmeside"), blank=True, null=True)
54 
55 
56     image = models.ImageField(_(u"bilde"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,
57                               default=settings.DEFAULT_PROFILE_PICTURE_URL)
58 
59     # NTNU credentials
60     ntnu_username = models.CharField(_(u"NTNU-brukernavn"), max_length=10, blank=True, null=True)
61 
62     # TODO checkbox for forwarding of @online.ntnu.no mail
63         
64     @property
65     def is_member(self):
66         """
67         Returns true if the User object is associated with Online.
68         """
69         if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:
70             return True
71         return False
72 
73     def get_full_name(self):
74         """
75         Returns the first_name plus the last_name, with a space in between.
76         """
77         full_name = u'%s %s' % (self.first_name, self.last_name)
78         return full_name.strip()
79 
80     def get_email(self):
81         return self.get_emails().filter(primary = True)[0]
82 
83     def get_emails(self):
84         return Email.objects.all().filter(user = self)
85 
86     @property
87     def year(self):
88         today = timezone.now().date()
89         started = self.started_date
90 
91         # We say that a year is 360 days incase we are a bit slower to
92         # add users one year.
93         year = ((today - started).days / 360) + 1
94 
95         if self.field_of_study == 0 or self.field_of_study == 100:  # others
96             return 0
97         # dont return a bachelor student as 4th or 5th grade
98         elif self.field_of_study == 1:  # bachelor
99             if year > 3:
100                 return 3
101             return year
102         elif 9 < self.field_of_study < 30:  # 10-29 is considered master
103             if year >= 2:
104                 return 5
105             return 4
106         elif self.field_of_study == 80:  # phd
107             return year + 5
108         elif self.field_of_study == 90:  # international
109             if year == 1:
110                 return 1
111             return 4
112 
113     def __unicode__(self):
114         return self.get_full_name()
115 
116     class Meta:
117         ordering = ['first_name', 'last_name']
118         verbose_name = _(u"brukerprofil")
119         verbose_name_plural = _(u"brukerprofiler")
120 
121 
122 class Email(models.Model):
123     user = models.ForeignKey(OnlineUser, related_name="email_user")
124     email = models.EmailField(_(u"epostadresse"), unique=True)
125     primary = models.BooleanField(_(u"aktiv"), default=False)
126     verified = models.BooleanField(_(u"verifisert"), default=False)
127 
128     def __unicode__(self):
129         return self.email
130 
131     class Meta:
132         verbose_name = _(u"epostadresse")
133         verbose_name_plural = _(u"epostadresser")
134 
135 
136 class RegisterToken(models.Model):
137     user = models.ForeignKey(OnlineUser, related_name="register_user")
138     email = models.EmailField(_(u"epost"), max_length=254)
139     token = models.CharField(_(u"token"), max_length=32)
140     created = models.DateTimeField(_(u"opprettet dato"), editable=False, auto_now_add=True)
141 
142     @property
143     def is_valid(self):
144         valid_period = datetime.timedelta(days=1)
145         now = timezone.now()
146         return now < self.created + valid_period 
147 
148 
149 class AllowedUsername(models.Model):
150     """
151     Holds usernames that are considered valid members of Online and the time they expire.
152     """
153     username = models.CharField(_(u"brukernavn"), max_length=10)
154     registered = models.DateField(_(u"registrert"))
155     note = models.CharField(_(u"notat"), max_length=100)
156     description = models.TextField(_(u"beskrivelse"), blank=True, null=True)
157     expiration_date = models.DateField(_(u"utløpsdato"))
158 
159     @property
160     def is_active(self):
161         return timezone.now().date() < self.expiration_date
162 
163     def __unicode__(self):
164         return self.username
165 
166     class Meta:
167         verbose_name = _(u"tillatt brukernavn")
168         verbose_name_plural = _(u"tillatte brukernavn")
169         ordering = (u"username",)
170 
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -99,7 +99,7 @@
             if year > 3:
                 return 3
             return year
-        elif 9 < self.field_of_study < 30:  # 10-29 is considered master
+        elif 10 <= self.field_of_study <= 30:  # 10-29 is considered master
             if year >= 2:
                 return 5
             return 4
@@ -109,6 +109,9 @@
             if year == 1:
                 return 1
             return 4
+        # If user's field of study is not matched by any of these tests, return -1
+        else:
+            return -1
 
     def __unicode__(self):
         return self.get_full_name()

{"golden_diff": "diff --git a/apps/authentication/models.py b/apps/authentication/models.py\n--- a/apps/authentication/models.py\n+++ b/apps/authentication/models.py\n@@ -99,7 +99,7 @@\n             if year > 3:\n                 return 3\n             return year\n-        elif 9 < self.field_of_study < 30:  # 10-29 is considered master\n+        elif 10 <= self.field_of_study <= 30:  # 10-29 is considered master\n             if year >= 2:\n                 return 5\n             return 4\n@@ -109,6 +109,9 @@\n             if year == 1:\n                 return 1\n             return 4\n+        # If user's field of study is not matched by any of these tests, return -1\n+        else:\n+            return -1\n \n     def __unicode__(self):\n         return self.get_full_name()\n", "issue": "OnlineUser.year tests\nWe really should write some tests to verify that the year attribute actually produces a correct value.\n\nMake sure to include:\n- Any date in August should produce a correct value for year. Especially important if \"now\" is august\n- Masters degrees are registered differently in the user object now, many field_of_study entries will be eligible for 4th and 5th year.\n- What happens to a user that started in january?\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport datetime\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import AbstractUser\nfrom django.db import models\nfrom django.utils.translation import ugettext as _\nfrom django.utils import timezone\n\n\n# If this list is changed, remember to check that the year property on\n# OnlineUser is still correct!\nFIELD_OF_STUDY_CHOICES = [\n    (0, _(u'Gjest')),\n    (1, _(u'Bachelor i Informatikk (BIT)')),\n    # master degrees take up the interval [10,30]\n    (10, _(u'Software (SW)')),\n    (11, _(u'Informasjonsforvaltning (DIF)')),\n    (12, _(u'Komplekse Datasystemer (KDS)')),\n    (13, _(u'Spillteknologi (SPT)')),\n    (14, _(u'Intelligente Systemer (IRS)')),\n    (15, _(u'Helseinformatikk (MSMEDTEK)')),\n    (30, _(u'Annen mastergrad')),\n    (80, _(u'PhD')),\n    (90, _(u'International')),\n    (100, _(u'Annet Onlinemedlem')),\n]\n\nclass OnlineUser(AbstractUser):\n\n    IMAGE_FOLDER = \"images/profiles\"\n    IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']\n    \n    # Online related fields\n    field_of_study = models.SmallIntegerField(_(u\"studieretning\"), choices=FIELD_OF_STUDY_CHOICES, default=0)\n    started_date = models.DateField(_(u\"startet studie\"), default=timezone.now().date())\n    compiled = models.BooleanField(_(u\"kompilert\"), default=False)\n\n    # Email\n    infomail = models.BooleanField(_(u\"vil ha infomail\"), default=True)\n\n    # Address\n    phone_number = models.CharField(_(u\"telefonnummer\"), max_length=20, blank=True, null=True)\n    address = models.CharField(_(u\"adresse\"), max_length=30, blank=True, null=True)\n    zip_code = models.CharField(_(u\"postnummer\"), max_length=4, blank=True, null=True)\n\n    # Other\n    allergies = models.TextField(_(u\"allergier\"), blank=True, null=True)\n    mark_rules = models.BooleanField(_(u\"godtatt prikkeregler\"), default=False)\n    rfid = models.CharField(_(u\"RFID\"), max_length=50, blank=True, null=True)\n    nickname = models.CharField(_(u\"nickname\"), max_length=50, blank=True, null=True)\n    website = models.URLField(_(u\"hjemmeside\"), blank=True, null=True)\n\n\n    image = models.ImageField(_(u\"bilde\"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,\n                              default=settings.DEFAULT_PROFILE_PICTURE_URL)\n\n    # NTNU credentials\n    ntnu_username = models.CharField(_(u\"NTNU-brukernavn\"), max_length=10, blank=True, null=True)\n\n    # TODO checkbox for forwarding of @online.ntnu.no mail\n        \n    @property\n    def is_member(self):\n        \"\"\"\n        Returns true if the User object is associated with Online.\n        \"\"\"\n        if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:\n            return True\n        return False\n\n    def get_full_name(self):\n        \"\"\"\n        Returns the first_name plus the last_name, with a space in between.\n        \"\"\"\n        full_name = u'%s %s' % (self.first_name, self.last_name)\n        return full_name.strip()\n\n    def get_email(self):\n        return self.get_emails().filter(primary = True)[0]\n\n    def get_emails(self):\n        return Email.objects.all().filter(user = self)\n\n    @property\n    def year(self):\n        today = timezone.now().date()\n        started = self.started_date\n\n        # We say that a year is 360 days incase we are a bit slower to\n        # add users one year.\n        year = ((today - started).days / 360) + 1\n\n        if self.field_of_study == 0 or self.field_of_study == 100:  # others\n            return 0\n        # dont return a bachelor student as 4th or 5th grade\n        elif self.field_of_study == 1:  # bachelor\n            if year > 3:\n                return 3\n            return year\n        elif 9 < self.field_of_study < 30:  # 10-29 is considered master\n            if year >= 2:\n                return 5\n            return 4\n        elif self.field_of_study == 80:  # phd\n            return year + 5\n        elif self.field_of_study == 90:  # international\n            if year == 1:\n                return 1\n            return 4\n\n    def __unicode__(self):\n        return self.get_full_name()\n\n    class Meta:\n        ordering = ['first_name', 'last_name']\n        verbose_name = _(u\"brukerprofil\")\n        verbose_name_plural = _(u\"brukerprofiler\")\n\n\nclass Email(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"email_user\")\n    email = models.EmailField(_(u\"epostadresse\"), unique=True)\n    primary = models.BooleanField(_(u\"aktiv\"), default=False)\n    verified = models.BooleanField(_(u\"verifisert\"), default=False)\n\n    def __unicode__(self):\n        return self.email\n\n    class Meta:\n        verbose_name = _(u\"epostadresse\")\n        verbose_name_plural = _(u\"epostadresser\")\n\n\nclass RegisterToken(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"register_user\")\n    email = models.EmailField(_(u\"epost\"), max_length=254)\n    token = models.CharField(_(u\"token\"), max_length=32)\n    created = models.DateTimeField(_(u\"opprettet dato\"), editable=False, auto_now_add=True)\n\n    @property\n    def is_valid(self):\n        valid_period = datetime.timedelta(days=1)\n        now = timezone.now()\n        return now < self.created + valid_period \n\n\nclass AllowedUsername(models.Model):\n    \"\"\"\n    Holds usernames that are considered valid members of Online and the time they expire.\n    \"\"\"\n    username = models.CharField(_(u\"brukernavn\"), max_length=10)\n    registered = models.DateField(_(u\"registrert\"))\n    note = models.CharField(_(u\"notat\"), max_length=100)\n    description = models.TextField(_(u\"beskrivelse\"), blank=True, null=True)\n    expiration_date = models.DateField(_(u\"utl\u00f8psdato\"))\n\n    @property\n    def is_active(self):\n        return timezone.now().date() < self.expiration_date\n\n    def __unicode__(self):\n        return self.username\n\n    class Meta:\n        verbose_name = _(u\"tillatt brukernavn\")\n        verbose_name_plural = _(u\"tillatte brukernavn\")\n        ordering = (u\"username\",)\n\n", "path": "apps/authentication/models.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport datetime\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import AbstractUser\nfrom django.db import models\nfrom django.utils.translation import ugettext as _\nfrom django.utils import timezone\n\n\n# If this list is changed, remember to check that the year property on\n# OnlineUser is still correct!\nFIELD_OF_STUDY_CHOICES = [\n    (0, _(u'Gjest')),\n    (1, _(u'Bachelor i Informatikk (BIT)')),\n    # master degrees take up the interval [10,30]\n    (10, _(u'Software (SW)')),\n    (11, _(u'Informasjonsforvaltning (DIF)')),\n    (12, _(u'Komplekse Datasystemer (KDS)')),\n    (13, _(u'Spillteknologi (SPT)')),\n    (14, _(u'Intelligente Systemer (IRS)')),\n    (15, _(u'Helseinformatikk (MSMEDTEK)')),\n    (30, _(u'Annen mastergrad')),\n    (80, _(u'PhD')),\n    (90, _(u'International')),\n    (100, _(u'Annet Onlinemedlem')),\n]\n\nclass OnlineUser(AbstractUser):\n\n    IMAGE_FOLDER = \"images/profiles\"\n    IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']\n    \n    # Online related fields\n    field_of_study = models.SmallIntegerField(_(u\"studieretning\"), choices=FIELD_OF_STUDY_CHOICES, default=0)\n    started_date = models.DateField(_(u\"startet studie\"), default=timezone.now().date())\n    compiled = models.BooleanField(_(u\"kompilert\"), default=False)\n\n    # Email\n    infomail = models.BooleanField(_(u\"vil ha infomail\"), default=True)\n\n    # Address\n    phone_number = models.CharField(_(u\"telefonnummer\"), max_length=20, blank=True, null=True)\n    address = models.CharField(_(u\"adresse\"), max_length=30, blank=True, null=True)\n    zip_code = models.CharField(_(u\"postnummer\"), max_length=4, blank=True, null=True)\n\n    # Other\n    allergies = models.TextField(_(u\"allergier\"), blank=True, null=True)\n    mark_rules = models.BooleanField(_(u\"godtatt prikkeregler\"), default=False)\n    rfid = models.CharField(_(u\"RFID\"), max_length=50, blank=True, null=True)\n    nickname = models.CharField(_(u\"nickname\"), max_length=50, blank=True, null=True)\n    website = models.URLField(_(u\"hjemmeside\"), blank=True, null=True)\n\n\n    image = models.ImageField(_(u\"bilde\"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,\n                              default=settings.DEFAULT_PROFILE_PICTURE_URL)\n\n    # NTNU credentials\n    ntnu_username = models.CharField(_(u\"NTNU-brukernavn\"), max_length=10, blank=True, null=True)\n\n    # TODO checkbox for forwarding of @online.ntnu.no mail\n        \n    @property\n    def is_member(self):\n        \"\"\"\n        Returns true if the User object is associated with Online.\n        \"\"\"\n        if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:\n            return True\n        return False\n\n    def get_full_name(self):\n        \"\"\"\n        Returns the first_name plus the last_name, with a space in between.\n        \"\"\"\n        full_name = u'%s %s' % (self.first_name, self.last_name)\n        return full_name.strip()\n\n    def get_email(self):\n        return self.get_emails().filter(primary = True)[0]\n\n    def get_emails(self):\n        return Email.objects.all().filter(user = self)\n\n    @property\n    def year(self):\n        today = timezone.now().date()\n        started = self.started_date\n\n        # We say that a year is 360 days incase we are a bit slower to\n        # add users one year.\n        year = ((today - started).days / 360) + 1\n\n        if self.field_of_study == 0 or self.field_of_study == 100:  # others\n            return 0\n        # dont return a bachelor student as 4th or 5th grade\n        elif self.field_of_study == 1:  # bachelor\n            if year > 3:\n                return 3\n            return year\n        elif 10 <= self.field_of_study <= 30:  # 10-29 is considered master\n            if year >= 2:\n                return 5\n            return 4\n        elif self.field_of_study == 80:  # phd\n            return year + 5\n        elif self.field_of_study == 90:  # international\n            if year == 1:\n                return 1\n            return 4\n        # If user's field of study is not matched by any of these tests, return -1\n        else:\n            return -1\n\n    def __unicode__(self):\n        return self.get_full_name()\n\n    class Meta:\n        ordering = ['first_name', 'last_name']\n        verbose_name = _(u\"brukerprofil\")\n        verbose_name_plural = _(u\"brukerprofiler\")\n\n\nclass Email(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"email_user\")\n    email = models.EmailField(_(u\"epostadresse\"), unique=True)\n    primary = models.BooleanField(_(u\"aktiv\"), default=False)\n    verified = models.BooleanField(_(u\"verifisert\"), default=False)\n\n    def __unicode__(self):\n        return self.email\n\n    class Meta:\n        verbose_name = _(u\"epostadresse\")\n        verbose_name_plural = _(u\"epostadresser\")\n\n\nclass RegisterToken(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"register_user\")\n    email = models.EmailField(_(u\"epost\"), max_length=254)\n    token = models.CharField(_(u\"token\"), max_length=32)\n    created = models.DateTimeField(_(u\"opprettet dato\"), editable=False, auto_now_add=True)\n\n    @property\n    def is_valid(self):\n        valid_period = datetime.timedelta(days=1)\n        now = timezone.now()\n        return now < self.created + valid_period \n\n\nclass AllowedUsername(models.Model):\n    \"\"\"\n    Holds usernames that are considered valid members of Online and the time they expire.\n    \"\"\"\n    username = models.CharField(_(u\"brukernavn\"), max_length=10)\n    registered = models.DateField(_(u\"registrert\"))\n    note = models.CharField(_(u\"notat\"), max_length=100)\n    description = models.TextField(_(u\"beskrivelse\"), blank=True, null=True)\n    expiration_date = models.DateField(_(u\"utl\u00f8psdato\"))\n\n    @property\n    def is_active(self):\n        return timezone.now().date() < self.expiration_date\n\n    def __unicode__(self):\n        return self.username\n\n    class Meta:\n        verbose_name = _(u\"tillatt brukernavn\")\n        verbose_name_plural = _(u\"tillatte brukernavn\")\n        ordering = (u\"username\",)\n\n", "path": "apps/authentication/models.py"}]}