# Path: patchwork/models.py
# class Person(models.Model):
#     email = models.CharField(max_length=255, unique=True)
#     name = models.CharField(max_length=255, null=True, blank=True)
#     user = models.ForeignKey(User, null=True, blank=True,
#                              on_delete=models.SET_NULL)
# 
#     def display_name(self):
#         if self.name:
#             return self.name
#         else:
#             return self.email
# 
#     def email_name(self):
#         if (self.name):
#             return "\"%s\" <%s>" % (self.name, self.email)
#         else:
#             return self.email
# 
#     def link_to_user(self, user):
#         self.name = user.profile.name()
#         self.user = user
# 
#     def __str__(self):
#         return self.display_name()
# 
#     class Meta:
#         verbose_name_plural = 'People'
# 
# class Patch(models.Model):
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     msgid = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
#     date = models.DateTimeField(default=datetime.datetime.now)
#     last_updated = models.DateTimeField(auto_now=True)
#     submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
#     delegate = models.ForeignKey(User, blank=True, null=True,
#                                  on_delete=models.CASCADE)
#     state = models.ForeignKey(State, null=True, on_delete=models.CASCADE)
#     archived = models.BooleanField(default=False)
#     headers = models.TextField(blank=True)
#     content = models.TextField(null=True, blank=True)
#     pull_url = models.CharField(max_length=255, null=True, blank=True)
#     commit_ref = models.CharField(max_length=255, null=True, blank=True)
#     hash = HashField(null=True, blank=True)
#     tags = models.ManyToManyField(Tag, through=PatchTag)
# 
#     objects = PatchManager()
# 
#     def commit_message(self):
#         """Retrieves the commit message"""
#         return Comment.objects.filter(patch=self, msgid=self.msgid)
# 
#     def answers(self):
#         """Retrieves the answers (ie all comments but the commit message)"""
#         return Comment.objects.filter(Q(patch=self) & ~Q(msgid=self.msgid))
# 
#     def comments(self):
#         """Retrieves all comments of this patch ie. the commit message and the
#            answers"""
#         return Comment.objects.filter(patch=self)
# 
#     def series(self):
#         try:
#             rev = SeriesRevisionPatch.objects.filter(patch=self)[0].revision
#             return rev.series
#         except Exception:
#             return None
# 
#     def _set_tag(self, tag, count):
#         if count == 0:
#             self.patchtag_set.filter(tag=tag).delete()
#             return
#         (patchtag, _) = PatchTag.objects.get_or_create(patch=self, tag=tag)
#         if patchtag.count != count:
#             patchtag.count = count
#             patchtag.save()
# 
#     def refresh_tag_counts(self):
#         tags = self.project.tags
#         counter = Counter()
#         for comment in self.comment_set.all():
#             counter = counter + extract_tags(comment.content, tags)
# 
#         for tag in tags:
#             self._set_tag(tag, counter[tag])
# 
#     def save(self):
#         if not hasattr(self, 'state') or not self.state:
#             self.state = get_default_initial_patch_state()
# 
#         if self.hash is None and self.content is not None:
#             self.hash = hash_patch(self.content).hexdigest()
# 
#         super(Patch, self).save()
# 
#     def filename(self):
#         return filename(self.name, '.patch')
# 
#     def human_name(self):
#         return self.name
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('patch', (), {'patch_id': self.id})
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Patches'
#         ordering = ['date']
#         unique_together = [('msgid', 'project')]


import datetime
import re
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.six.moves import zip
from patchwork.models import Person, Patch
from patchwork.tests.utils import defaults
        ('FpvAhWRdX', 'FpKAhWRdX@agxnCAI.wFO',
         d(2014, 3, 15, 13, 4, 50, 201398)),

        ('bmoYvnyWa', 'bmdYvnyWa@aeoPnlX.juy',
         d(2014, 3, 4, 13, 4, 50, 206800)),

        ('CiReUQsAq', 'CiieUQsAq@DnOYRuf.TTI',
         d(2014, 3, 28, 13, 4, 50, 212169)),
    ]

    def setUp(self):
        defaults.project.save()

        for (name, email, date) in self.patchmeta:
            patch_name = 'testpatch' + name
            person = Person(name=name, email=email)
            person.save()
            patch = Patch(project=defaults.project, msgid=patch_name,
                          submitter=person, content='', date=date)
            patch.save()

    def _extract_patch_ids(self, response):
        id_re = re.compile(r'<tr id="patch_row:(\d+)"')
        ids = [int(m.group(1))
               for m in id_re.finditer(response.content.decode())]
        return ids

    def _test_sequence(self, response, test_fn):
        ids = self._extract_patch_ids(response)
        self.assertTrue(bool(ids))

# Path: patchwork/models.py
# class Person(models.Model):
#     email = models.CharField(max_length=255, unique=True)
#     name = models.CharField(max_length=255, null=True, blank=True)
#     user = models.ForeignKey(User, null=True, blank=True,
#                              on_delete=models.SET_NULL)
# 
#     def display_name(self):
#         if self.name:
#             return self.name
#         else:
#             return self.email
# 
#     def email_name(self):
#         if (self.name):
#             return "\"%s\" <%s>" % (self.name, self.email)
#         else:
#             return self.email
# 
#     def link_to_user(self, user):
#         self.name = user.profile.name()
#         self.user = user
# 
#     def __str__(self):
#         return self.display_name()
# 
#     class Meta:
#         verbose_name_plural = 'People'
# 
# class Patch(models.Model):
#     project = models.ForeignKey(Project, on_delete=models.CASCADE)
#     msgid = models.CharField(max_length=255)
#     name = models.CharField(max_length=255)
#     date = models.DateTimeField(default=datetime.datetime.now)
#     last_updated = models.DateTimeField(auto_now=True)
#     submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
#     delegate = models.ForeignKey(User, blank=True, null=True,
#                                  on_delete=models.CASCADE)
#     state = models.ForeignKey(State, null=True, on_delete=models.CASCADE)
#     archived = models.BooleanField(default=False)
#     headers = models.TextField(blank=True)
#     content = models.TextField(null=True, blank=True)
#     pull_url = models.CharField(max_length=255, null=True, blank=True)
#     commit_ref = models.CharField(max_length=255, null=True, blank=True)
#     hash = HashField(null=True, blank=True)
#     tags = models.ManyToManyField(Tag, through=PatchTag)
# 
#     objects = PatchManager()
# 
#     def commit_message(self):
#         """Retrieves the commit message"""
#         return Comment.objects.filter(patch=self, msgid=self.msgid)
# 
#     def answers(self):
#         """Retrieves the answers (ie all comments but the commit message)"""
#         return Comment.objects.filter(Q(patch=self) & ~Q(msgid=self.msgid))
# 
#     def comments(self):
#         """Retrieves all comments of this patch ie. the commit message and the
#            answers"""
#         return Comment.objects.filter(patch=self)
# 
#     def series(self):
#         try:
#             rev = SeriesRevisionPatch.objects.filter(patch=self)[0].revision
#             return rev.series
#         except Exception:
#             return None
# 
#     def _set_tag(self, tag, count):
#         if count == 0:
#             self.patchtag_set.filter(tag=tag).delete()
#             return
#         (patchtag, _) = PatchTag.objects.get_or_create(patch=self, tag=tag)
#         if patchtag.count != count:
#             patchtag.count = count
#             patchtag.save()
# 
#     def refresh_tag_counts(self):
#         tags = self.project.tags
#         counter = Counter()
#         for comment in self.comment_set.all():
#             counter = counter + extract_tags(comment.content, tags)
# 
#         for tag in tags:
#             self._set_tag(tag, counter[tag])
# 
#     def save(self):
#         if not hasattr(self, 'state') or not self.state:
#             self.state = get_default_initial_patch_state()
# 
#         if self.hash is None and self.content is not None:
#             self.hash = hash_patch(self.content).hexdigest()
# 
#         super(Patch, self).save()
# 
#     def filename(self):
#         return filename(self.name, '.patch')
# 
#     def human_name(self):
#         return self.name
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('patch', (), {'patch_id': self.id})
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = 'Patches'
#         ordering = ['date']
#         unique_together = [('msgid', 'project')]


# Path: patchwork/tests/test_list.py
import datetime
import re
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.six.moves import zip
from patchwork.models import Person, Patch
from patchwork.tests.utils import defaults

        ('FpvAhWRdX', 'FpKAhWRdX@agxnCAI.wFO',
         d(2014, 3, 15, 13, 4, 50, 201398)),

        ('bmoYvnyWa', 'bmdYvnyWa@aeoPnlX.juy',
         d(2014, 3, 4, 13, 4, 50, 206800)),

        ('CiReUQsAq', 'CiieUQsAq@DnOYRuf.TTI',
         d(2014, 3, 28, 13, 4, 50, 212169)),
    ]

    def setUp(self):
        defaults.project.save()

        for (name, email, date) in self.patchmeta:
            patch_name = 'testpatch' + name
            person = Person(name=name, email=email)
            person.save()
            patch = Patch(project=defaults.project, msgid=patch_name,
                          submitter=person, content='', date=date)
            patch.save()

    def _extract_patch_ids(self, response):
        id_re = re.compile(r'<tr id="patch_row:(\d+)"')
        ids = [int(m.group(1))
               for m in id_re.finditer(response.content.decode())]
        return ids

    def _test_sequence(self, response, test_fn):
        ids = self._extract_patch_ids(response)
        self.assertTrue(bool(ids))

        patches = [Patch.objects.get(id=i) for i in ids]