damned-lies r1237 - in trunk: . stats stats/conf stats/tests
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1237 - in trunk: . stats stats/conf stats/tests
- Date: Tue, 23 Dec 2008 20:48:57 +0000 (UTC)
Author: claudep
Date: Tue Dec 23 20:48:57 2008
New Revision: 1237
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1237&view=rev
Log:
2008-12-23 Claude Paroz <claude 2xlibre net>
* stats/conf/settings_sample.py: NOTIFICATIONS_TO is now a list.
* stats/models.py: Syntax fix.
* stats/tests/__init__.py: Add more tests (notification email, invalid
branch)
* stats/utils.py: Use django mail module instead of directly calling
smtplib.
Modified:
trunk/ChangeLog
trunk/stats/conf/settings_sample.py
trunk/stats/models.py
trunk/stats/tests/__init__.py
trunk/stats/utils.py
Modified: trunk/stats/conf/settings_sample.py
==============================================================================
--- trunk/stats/conf/settings_sample.py (original)
+++ trunk/stats/conf/settings_sample.py Tue Dec 23 20:48:57 2008
@@ -7,7 +7,7 @@
WHOAREWE = 'danilo gnome org'
# When in STRINGFREEZE, where to send notifications (gnome-i18n gnome org) on any POT changes
-NOTIFICATIONS_TO = 'gnome-i18n gnome org'
+NOTIFICATIONS_TO = ['gnome-i18n gnome org']
# Local directories
SCRATCHDIR = ""
Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py (original)
+++ trunk/stats/models.py Tue Dec 23 20:48:57 2008
@@ -156,7 +156,7 @@
if os.access(localdir, os.W_OK):
import shutil # os.rmdir cannot delete non-empty dirs
shutil.rmtree(localdir)
- models.Model.delete(self)
+ super(Branch, self).delete()
def __cmp__(self, other):
if self.name in BRANCH_HEAD_NAMES:
Modified: trunk/stats/tests/__init__.py
==============================================================================
--- trunk/stats/tests/__init__.py (original)
+++ trunk/stats/tests/__init__.py Tue Dec 23 20:48:57 2008
@@ -18,12 +18,14 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import unittest
+import os, unittest
import threading
-from stats.models import Module, Domain, Branch, Statistics
+from django.core import mail
+from stats.models import Module, Domain, Branch, Category, Release, Statistics
class ModuleTestCase(unittest.TestCase):
def setUp(self):
+ # TODO: load bulk data from fixtures
self.mod = Module(name="gnome-hello",
bugs_base="http://bugzilla.gnome.org",
bugs_product="test", # This product really exists
@@ -36,20 +38,23 @@
dom.save()
dom = Domain(module=self.mod, name='help', description='User Guide', dtype='doc', directory='help')
dom.save()
-
+ self.rel = Release(name='gnome-2-24', status='official',
+ description='GNOME 2.24 (stable)',
+ string_frozen=True)
+ self.rel.save()
+
def testModuleFunctions(self):
self.assertEquals(self.mod.get_description(), 'gnome-hello')
- def testBranch(self):
+ def testCreateAndDeleteBranch(self):
# Create branch (include checkout)
branch = Branch(name="trunk",
module = self.mod)
branch.save()
-
- self.assertEquals(branch.is_head(), True)
+ self.assertTrue(branch.is_head())
self.assertEquals(branch.get_vcs_url(), "http://svn.gnome.org/svn/gnome-hello/trunk")
self.assertEquals(branch.get_vcs_web_url(), "http://svn.gnome.org/viewvc/gnome-hello/trunk")
-
+
# save() launch update_stats in a separate thread, wait for the thread to end before pursuing the tests
for th in threading.enumerate():
if th != threading.currentThread():
@@ -61,8 +66,37 @@
self.assertEquals(fr_po_stat.translated, 40)
fr_doc_stat = Statistics.objects.get(branch=branch, domain__name='help', language__locale='fr')
self.assertEquals(fr_doc_stat.translated, 36)
-
- # Delete branch to remove the repo checkout
+
+ # Link gnome-hello trunk to a string_frozen release
+ cat = Category(release=self.rel, branch=branch, name='desktop')
+ cat.save()
+
+ # Create a new file with translation
+ new_file_path = os.path.join(branch.co_path(), "dummy_file.h")
+ new_string = "Dummy string for D-L tests"
+ f = open(new_file_path,'w')
+ f.write("a = _('%s')" % new_string)
+ f.close()
+ # Add the new file to POTFILES.in
+ f = open(os.path.join(branch.co_path(), "po", "POTFILES.in"), 'a')
+ f.write("dummy_file.h")
+ f.close()
+ # Regenerate stats (mail should be sent)
+ branch.update_stats()
+ # Assertions
+ self.assertEquals(len(mail.outbox), 1);
+ self.assertEquals(mail.outbox[0].subject, "String additions to '%s'")
+ self.assertTrue(new_string in mail.outbox[0].message)
+
+ # Delete the branch (removing the repo checkout in the file system)
+ checkout_path = branch.co_path()
+ branch = Branch.objects.get(name="trunk", module = self.mod)
branch.delete()
-
- # TODO: Try to create a non-existing branch...
+ self.assertFalse(os.access(checkout_path, os.F_OK))
+
+ def testCreateUnexistingBranch(self):
+ """ Try to create a non-existing branch """
+ branch = Branch(name="trunk2",
+ module = self.mod)
+ self.assertRaises(ValueError, branch.save)
+
Modified: trunk/stats/utils.py
==============================================================================
--- trunk/stats/utils.py (original)
+++ trunk/stats/utils.py Tue Dec 23 20:48:57 2008
@@ -20,6 +20,7 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.utils.translation import ugettext as _, ugettext_noop
+from django.core.mail import send_mail
from stats.conf import settings
import sys, os, re, time, commands
@@ -276,13 +277,7 @@
return 0
def notify_list(out_domain, diff):
- """Send notification about string changes described in diff.
-
- Uses settings.NOTIFICATIONS_TO as "to" address,
- settings.WHOAREWE as "from" address, and sends
- using SMTP on localhost:25."""
- import smtplib
- from email.mime.text import MIMEText
+ """Send notification about string changes described in diff."""
text = u"""This is an automatic notification from status generation scripts on:
%(ourweb)s.
@@ -296,15 +291,10 @@
'ourweb' : settings.WHEREAREWE,
'potdiff' : "\n ".join(diff).decode('utf-8') }
- msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8')
- msg['Subject'] = "String additions to '%s'" % (out_domain)
- msg['From'] = "GNOME Status Pages <%s>" % (settings.WHOAREWE)
- msg['To'] = settings.NOTIFICATIONS_TO
-
- s = smtplib.SMTP()
- s.connect()
- s.sendmail(settings.WHOAREWE, settings.NOTIFICATIONS_TO, msg.as_string())
- s.close()
+ send_mail(subject="String additions to '%s'" % (out_domain),
+ message=text,
+ from_email="GNOME Status Pages <%s>" % (settings.WHOAREWE),
+ recipient_list=settings.NOTIFICATIONS_TO)
class Profiler(object):
def __init__(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]