Ejemplo n.º 1
0
    def test_find_all(self):
        self.rejection_pattern.save()
        another_rejection_pattern = RejectionPattern("[a-z]+", u"人员")
        another_rejection_pattern.save()

        records = RejectionPattern.findall()
        print "rejection_pattern", records
        self.assertEqual(2, len(records))
Ejemplo n.º 2
0
    def test_find_all(self):
        self.rejection_pattern.save()
        another_rejection_pattern = RejectionPattern('[a-z]+', u'人员')
        another_rejection_pattern.save()

        records = RejectionPattern.findall()
        print 'rejection_pattern', records
        self.assertEqual(2, len(records))
Ejemplo n.º 3
0
class RejectionPatternTest(BaseTestCase):
    def setUp(self):
        self.clean_db()
        self.rejection_pattern = RejectionPattern("[1-9]+", u"人员")

    def tearDown(self):
        pass

    def test_save(self):
        RejectionPattern("Something").save()
        RejectionPattern(u"人员", None).save()

        print RejectionPattern.findall()

        conn = self.connect_db()
        try:
            c = conn.cursor()
            c.execute("SELECT COUNT(*) FROM " + RejectionPattern.table_name)
            self.assertEqual(c.fetchone()[0], 2, "Count of rejection_pattern should be 2")
        except:
            pass
        finally:
            conn.close()

    def test_find_all(self):
        self.rejection_pattern.save()
        another_rejection_pattern = RejectionPattern("[a-z]+", u"人员")
        another_rejection_pattern.save()

        records = RejectionPattern.findall()
        print "rejection_pattern", records
        self.assertEqual(2, len(records))

    def test_find(self):
        self.rejection_pattern.save()
        result = RejectionPattern.find(self.rejection_pattern)
        self.assertEqual(
            self.rejection_pattern.reject_pattern, result.reject_pattern, "Item found should be the same as saved"
        )

    def test_remove(self):
        self.rejection_pattern.save()
        self.rejection_pattern.remove()
        conn = self.connect_db()
        try:
            c = conn.cursor()
            c.execute("SELECT COUNT(*) FROM " + RejectionPattern.table_name)
            self.assertEqual(c.fetchone()[0], 0, "Count of rejection_pattern should be 0 after removing")
        except:
            pass
        finally:
            conn.close()

    def test_should_be_rejected(self):
        RejectionPattern("[1-9]+").save()
        self.assertTrue(RejectionPattern.should_be_rejected("9887"), "input_text should be rejected")
        self.assertFalse(RejectionPattern.should_be_rejected("abcd"), "input_text should not be rejected")
        RejectionPattern(u"(?<!非)中介").save()
        self.assertTrue(RejectionPattern.should_be_rejected(u"中介"), "input_text should be rejected")
        self.assertTrue(RejectionPattern.should_be_rejected(u"是中介"), "input_text should be rejected")
        self.assertFalse(RejectionPattern.should_be_rejected(u"非中介"), "input_text should not be rejected")

    def test_extract_records_as_bytes(self):
        RejectionPattern("Pattern1", "testing1").save()
        RejectionPattern("Pattern2").save()
        RejectionPattern("Pattern3", "测试").save()

        print "Content as txt: ", RejectionPattern.extract_records_as_bytes("txt")
        print "Content as excel: ", RejectionPattern.extract_records_as_bytes("xlsx")
        print "Content as csv: ", RejectionPattern.extract_records_as_bytes("csv")

    def test_get_instance_classname(self):
        self.assertEqual("RejectionPatternTest", self.__class__.__name__)

    @classmethod
    def test_get_classname(cls):
        print cls.__name__

    def test_find_with_pagination(self):
        for i in range(0, 20):
            RejectionPattern("Reject_pattern_%d" % i, "").save()

        records = RejectionPattern.find_with_pagination(page_request={"page_no": 2, "size": 10})

        print "items", records
        self.assertEqual(10, len(records))
Ejemplo n.º 4
0
class RejectionPatternTest(BaseTestCase):
    def setUp(self):
        self.clean_db()
        self.rejection_pattern = RejectionPattern('[1-9]+', u'人员')

    def tearDown(self):
        pass

    def test_save(self):
        RejectionPattern('Something').save()
        RejectionPattern(u'人员', None).save()

        print RejectionPattern.findall()

        conn = self.connect_db()
        try:
            c = conn.cursor()
            c.execute('SELECT COUNT(*) FROM ' + RejectionPattern.table_name)
            self.assertEqual(c.fetchone()[0], 2, 'Count of rejection_pattern should be 2')
        except:
            pass
        finally:
            conn.close()

    def test_find_all(self):
        self.rejection_pattern.save()
        another_rejection_pattern = RejectionPattern('[a-z]+', u'人员')
        another_rejection_pattern.save()

        records = RejectionPattern.findall()
        print 'rejection_pattern', records
        self.assertEqual(2, len(records))

    def test_find(self):
        self.rejection_pattern.save()
        result = RejectionPattern.find(self.rejection_pattern)
        self.assertEqual(self.rejection_pattern.reject_pattern, result.reject_pattern, 'Item found should be the same as saved')

    def test_remove(self):
        self.rejection_pattern.save()
        self.rejection_pattern.remove()
        conn = self.connect_db()
        try:
            c = conn.cursor()
            c.execute('SELECT COUNT(*) FROM ' + RejectionPattern.table_name)
            self.assertEqual(c.fetchone()[0], 0, 'Count of rejection_pattern should be 0 after removing')
        except:
            pass
        finally:
            conn.close()

    def test_should_be_rejected(self):
        RejectionPattern('[1-9]+').save()
        self.assertTrue(RejectionPattern.should_be_rejected('9887'), 'input_text should be rejected')
        self.assertFalse(RejectionPattern.should_be_rejected('abcd'), 'input_text should not be rejected')
        RejectionPattern(u'(?<!非)中介').save()
        self.assertTrue(RejectionPattern.should_be_rejected(u'中介'), 'input_text should be rejected')
        self.assertTrue(RejectionPattern.should_be_rejected(u'是中介'), 'input_text should be rejected')
        self.assertFalse(RejectionPattern.should_be_rejected(u'非中介'), 'input_text should not be rejected')

    def test_extract_records_as_bytes(self):
        RejectionPattern('Pattern1', 'testing1').save()
        RejectionPattern('Pattern2').save()
        RejectionPattern('Pattern3', '测试').save()

        print 'Content as txt: ', RejectionPattern.extract_records_as_bytes('txt')
        print 'Content as excel: ', RejectionPattern.extract_records_as_bytes('xlsx')
        print 'Content as csv: ', RejectionPattern.extract_records_as_bytes('csv')

    def test_get_instance_classname(self):
        self.assertEqual('RejectionPatternTest', self.__class__.__name__)

    @classmethod
    def test_get_classname(cls):
        print cls.__name__


    def test_find_with_pagination(self):
        for i in range(0, 20):
            RejectionPattern('Reject_pattern_%d' % i, '').save()

        records = RejectionPattern.find_with_pagination(page_request={'page_no': 2, 'size': 10})

        print 'items', records
        self.assertEqual(10, len(records))