import os
import codecs
-from patchwork.models import Project, Person, UserProfile
+from patchwork.models import Project, Person
from django.contrib.auth.models import User
+from email import message_from_file
try:
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
patch_author = 'Patch Author <patch-author@example.com>'
patch_author_person = Person(name = 'Patch Author',
- email = 'patch-author@example.com')
+ email = 'patch-author@example.com')
comment_author = 'Comment Author <comment-author@example.com>'
patch_name = 'Test Patch'
+ patch = """--- /dev/null 2011-01-01 00:00:00.000000000 +0800
++++ a 2011-01-01 00:00:00.000000000 +0800
+@@ -0,0 +1 @@
++a
+"""
+
_user_idx = 1
def create_user():
global _user_idx
- userid = 'test-%d' % _user_idx
+ userid = 'test%d' % _user_idx
email = '%s@example.com' % userid
_user_idx += 1
user = User.objects.create_user(userid, email, userid)
user.save()
- profile = UserProfile(user = user)
- profile.save()
+ return user
+def create_maintainer(project):
+ user = create_user()
+ profile = user.get_profile()
+ profile.maintainer_projects.add(project)
+ profile.save()
return user
def find_in_context(context, key):
def read_patch(filename, encoding = None):
file_path = os.path.join(_test_patch_dir, filename)
if encoding is not None:
- f = codecs.open(file_path, encoding = encoding)
+ f = codecs.open(file_path, encoding = encoding)
else:
f = file(file_path)
return f.read()
+def read_mail(filename, project = None):
+ file_path = os.path.join(_test_mail_dir, filename)
+ mail = message_from_file(open(file_path))
+ if project is not None:
+ mail['List-Id'] = project.listid
+ return mail
+
def create_email(content, subject = None, sender = None, multipart = False,
project = None, content_encoding = None):
if subject is None:
sender = defaults.sender
if project is None:
project = defaults.project
+ if content_encoding is None:
+ content_encoding = 'us-ascii'
if multipart:
msg = MIMEMultipart()
- body = MIMEText(content, _subtype = 'plain')
- if content_encoding is not None:
- body.set_charset(content_encoding)
+ body = MIMEText(content, _subtype = 'plain',
+ _charset = content_encoding)
msg.attach(body)
else:
- msg = MIMEText(content)
- if content_encoding is not None:
- msg.set_charset(content_encoding)
+ msg = MIMEText(content, _charset = content_encoding)
msg['Subject'] = subject
msg['From'] = sender