mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 17:02:18 +00:00
Minor fix for importer adding @nottingham.ac.uk to empty emails.
Small test case for email fixer to make sure that emails are fixed correctly.
This commit is contained in:
@@ -14,6 +14,13 @@ from RIGS import models
|
|||||||
import reversion
|
import reversion
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def fix_email(email):
|
||||||
|
if not (email is None or email is "") and ("@" not in email):
|
||||||
|
email += "@nottingham.ac.uk"
|
||||||
|
return email
|
||||||
|
|
||||||
|
|
||||||
def setup_cursor():
|
def setup_cursor():
|
||||||
try:
|
try:
|
||||||
cursor = connections['legacy'].cursor()
|
cursor = connections['legacy'].cursor()
|
||||||
@@ -63,8 +70,7 @@ def import_people(delete=False):
|
|||||||
resp = cursor.fetchall()
|
resp = cursor.fetchall()
|
||||||
for row in resp:
|
for row in resp:
|
||||||
email = row[3]
|
email = row[3]
|
||||||
if (email is not None) and ("@" not in email):
|
fix_email(email)
|
||||||
email += "@nottingham.ac.uk"
|
|
||||||
|
|
||||||
notes = ""
|
notes = ""
|
||||||
if row[5] != "Normal":
|
if row[5] != "Normal":
|
||||||
@@ -256,14 +262,14 @@ def import_nonrigs(delete=False):
|
|||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# import_users()
|
import_users()
|
||||||
# import_people()
|
import_people()
|
||||||
# import_organisations()
|
import_organisations()
|
||||||
# import_vat_rates()
|
import_vat_rates()
|
||||||
# import_venues(True)
|
import_venues(False)
|
||||||
# import_rigs(False)
|
import_rigs(False)
|
||||||
# import_eventitem(True)
|
import_eventitem(False)
|
||||||
import_nonrigs(True)
|
import_nonrigs(False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
28
RIGS/importer_tests.py
Normal file
28
RIGS/importer_tests.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
__author__ = 'ghost'
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from importer import fix_email
|
||||||
|
|
||||||
|
|
||||||
|
class EmailFixerTest(unittest.TestCase):
|
||||||
|
def test_correct(self):
|
||||||
|
e = fix_email("tom@ghost.uk.net")
|
||||||
|
self.assertEqual(e, "tom@ghost.uk.net")
|
||||||
|
|
||||||
|
def test_partial(self):
|
||||||
|
e = fix_email("psytp")
|
||||||
|
self.assertEqual(e, "psytp@nottingham.ac.uk")
|
||||||
|
|
||||||
|
def test_none(self):
|
||||||
|
old = None
|
||||||
|
new = fix_email(old)
|
||||||
|
self.assertEqual(old, new)
|
||||||
|
|
||||||
|
def test_empty(self):
|
||||||
|
old = ""
|
||||||
|
new = fix_email(old)
|
||||||
|
self.assertEqual(old, new)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user