예제 #1
0
파일: tests.py 프로젝트: ljean/balafon
 def _notify_due_actions(self, verbosity=0):
     """call notify_due_actions and check what is printed on the console"""
     buf = StringIO()
     sysout = sys.stdout
     sys.stdout = buf
     management.call_command('notify_due_actions',
                             verbosity=verbosity,
                             stdout=buf)
     buf.seek(0, 0)
     sys.stdout = sysout
     return buf.readlines()
예제 #2
0
    def test_find_same_as(self):

        contact1 = mommy.make(models.Contact, firstname="John", lastname="Lennon")
        contact2 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney")
        contact3 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney")

        buf = StringIO()
        sysout = sys.stdout
        sys.stdout = buf
        management.call_command('find_same_as', verbosity=0, interactive=False, stdout=buf)
        buf.seek(0, 0)
        sys.stdout = sysout
        self.assertEqual(2, len(buf.readlines()))
예제 #3
0
    def test_find_same_as_with_group(self):

        contact1 = mommy.make(models.Contact, firstname="John", lastname="Lennon")
        contact2 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney")
        contact3 = mommy.make(models.Contact, firstname="Paul", lastname="McCartney")

        buf = StringIO()
        sysout = sys.stdout
        sys.stdout = buf
        management.call_command('find_same_as', "SameAs", verbosity=0, interactive=False, stdout=buf)
        buf.seek(0, 0)
        sys.stdout = sysout
        self.assertEqual(2, len(buf.readlines()))
        qs = models.Group.objects.filter(name="SameAs")
        self.assertEqual(1, qs.count())
        self.assertEqual(qs[0].contacts.count(), 2)
        self.assertFalse(contact1 in qs[0].contacts.all())
        self.assertTrue(contact2 in qs[0].contacts.all())
        self.assertTrue(contact3 in qs[0].contacts.all())
예제 #4
0
파일: utils.py 프로젝트: ljean/balafon
def unicode_csv_reader(the_file, encoding, dialect=csv.excel, **kwargs):
    """read csv file properly"""
    the_file.seek(0)
    content = the_file.read()
    decoded = content.decode(encoding)

    text_file = StringIO(decoded)

    if 'delimiter' in kwargs:
        kwargs['delimiter'] = str(kwargs['delimiter'])
    csv_reader = csv.reader(text_file, dialect=dialect, **kwargs)
    for row in csv_reader:
        yield [cell for cell in row]