def test_find_all(self): self.blocked_contact.save() another_blocked_contact = BlockedContact("99999999", u"中介") another_blocked_contact.save() records = BlockedContact.findall() print "BlockedContacts", records self.assertEqual(2, len(records))
def test_find_all(self): self.blocked_contact.save() another_blocked_contact = BlockedContact('99999999', u'中介') another_blocked_contact.save() records = BlockedContact.findall() print 'BlockedContacts', records self.assertEqual(2, len(records))
def test_find_with_pagination(self): for i in range(0, 20): BlockedContact('%d' % i, '').save() records = BlockedContact.find_with_pagination(page_request={'page_no': 2, 'size': 10}) print 'items', records self.assertEqual(10, len(records))
def should_load_details(self, job_item): if JobItem.is_exists(job_item): logger.info( '[%s] skipping loading details as job already exists. job_title: %s' % (self.name, job_item.job_title)) return False if JobItem.is_older_required(job_item): logger.info( '[%s] skipping loading details as job is older than %s days. job_title: %s' % (self.name, str(config.HOUSEKEEPING_RECORD_ORDLER_THAN), job_item.job_title)) return False if BlockedContact.is_contact_blocked(job_item.contact): logger.info( '[%s] skipping loading details as job contact is blocked. contact: %s' % (self.name, job_item.contact)) return False if RejectionPattern.should_be_rejected(job_item.job_title): logger.info( '[%s] skipping loading details as job matches rejection pattern. job_title: %s' % (self.name, job_item.job_title)) return False return True
def test_find_with_pagination(self): for i in range(0, 20): BlockedContact("%d" % i, "").save() records = BlockedContact.find_with_pagination(page_request={"page_no": 2, "size": 10}) print "items", records self.assertEqual(10, len(records))
def should_load_details(self, job_item): if JobItem.is_exists(job_item): logger.info('[%s] skipping loading details as job already exists. job_title: %s' % (self.name, job_item.job_title)) return False if JobItem.is_older_required(job_item): logger.info('[%s] skipping loading details as job is older than %s days. job_title: %s' % (self.name, str(config.HOUSEKEEPING_RECORD_ORDLER_THAN), job_item.job_title)) return False if BlockedContact.is_contact_blocked(job_item.contact): logger.info('[%s] skipping loading details as job contact is blocked. contact: %s' % (self.name, job_item.contact)) return False if RejectionPattern.should_be_rejected(job_item.job_title): logger.info('[%s] skipping loading details as job matches rejection pattern. job_title: %s' % (self.name, job_item.job_title)) return False return True
def test_remove_blocked_records(self): for i in range(0, 20): job_item = JobItem() job_item.job_title=u'人员_%d' % i job_item.contact = str(random.randint(90000000, 99999999)) job_item.save() # mark the contact as blocked BlockedContact(job_item.contact, u'人员').save() # run the remove action JobItem.remove_blocked_records() conn = self.connect_db() try: c = conn.cursor() c.execute('SELECT COUNT(*) FROM ' + JobItem.table_name) self.assertEqual(c.fetchone()[0], 0, 'Count of job items should be 0') except: pass finally: conn.close()
def process_item(self, item, spider): # check by contact if BlockedContact.is_contact_blocked(item.contact): raise DropItem('Job is posted by blocked contact. Removing...') return item
def test_find(self): self.blocked_contact.save() result = BlockedContact.find(self.blocked_contact) self.assertEqual(self.blocked_contact.contact, result.contact, 'Item found should be the same as saved')
def setUp(self): self.clean_db() self.blocked_contact = BlockedContact('8888888', u'中介')
def test_find(self): self.blocked_contact.save() result = BlockedContact.find(self.blocked_contact) self.assertEqual(self.blocked_contact.contact, result.contact, "Item found should be the same as saved")
def test_is_contact_blocked(self): self.blocked_contact.save() self.assertTrue(BlockedContact.is_contact_blocked(self.blocked_contact.contact), "Contact should been blocked")
def test_is_contact_blocked(self): self.blocked_contact.save() self.assertTrue(BlockedContact.is_contact_blocked(self.blocked_contact.contact), 'Contact should been blocked')
def setUp(self): self.clean_db() self.blocked_contact = BlockedContact("8888888", u"中介")
class BlockedContactTest(BaseTestCase): def setUp(self): self.clean_db() self.blocked_contact = BlockedContact("8888888", u"中介") def tearDown(self): pass def test_save(self): self.blocked_contact.save() conn = self.connect_db() try: c = conn.cursor() c.execute("SELECT COUNT(*) FROM " + BlockedContact.table_name) self.assertEqual(c.fetchone()[0], 1, "Count of blocked contacts should be 1") except: pass finally: conn.close() def test_find_all(self): self.blocked_contact.save() another_blocked_contact = BlockedContact("99999999", u"中介") another_blocked_contact.save() records = BlockedContact.findall() print "BlockedContacts", records self.assertEqual(2, len(records)) def test_find(self): self.blocked_contact.save() result = BlockedContact.find(self.blocked_contact) self.assertEqual(self.blocked_contact.contact, result.contact, "Item found should be the same as saved") def test_remove(self): self.blocked_contact.save() self.blocked_contact.remove() conn = self.connect_db() try: c = conn.cursor() c.execute("SELECT COUNT(*) FROM " + BlockedContact.table_name) self.assertEqual(c.fetchone()[0], 0, "Count of blocked contacts should be 0 after removing") except: pass finally: conn.close() def test_is_contact_blocked(self): self.blocked_contact.save() self.assertTrue(BlockedContact.is_contact_blocked(self.blocked_contact.contact), "Contact should been blocked") def test_find_with_pagination(self): for i in range(0, 20): BlockedContact("%d" % i, "").save() records = BlockedContact.find_with_pagination(page_request={"page_no": 2, "size": 10}) print "items", records self.assertEqual(10, len(records))
class BlockedContactTest(BaseTestCase): def setUp(self): self.clean_db() self.blocked_contact = BlockedContact('8888888', u'中介') def tearDown(self): pass def test_save(self): self.blocked_contact.save() conn = self.connect_db() try: c = conn.cursor() c.execute('SELECT COUNT(*) FROM ' + BlockedContact.table_name) self.assertEqual(c.fetchone()[0], 1, 'Count of blocked contacts should be 1') except: pass finally: conn.close() def test_find_all(self): self.blocked_contact.save() another_blocked_contact = BlockedContact('99999999', u'中介') another_blocked_contact.save() records = BlockedContact.findall() print 'BlockedContacts', records self.assertEqual(2, len(records)) def test_find(self): self.blocked_contact.save() result = BlockedContact.find(self.blocked_contact) self.assertEqual(self.blocked_contact.contact, result.contact, 'Item found should be the same as saved') def test_remove(self): self.blocked_contact.save() self.blocked_contact.remove() conn = self.connect_db() try: c = conn.cursor() c.execute('SELECT COUNT(*) FROM ' + BlockedContact.table_name) self.assertEqual(c.fetchone()[0], 0, 'Count of blocked contacts should be 0 after removing') except: pass finally: conn.close() def test_is_contact_blocked(self): self.blocked_contact.save() self.assertTrue(BlockedContact.is_contact_blocked(self.blocked_contact.contact), 'Contact should been blocked') def test_find_with_pagination(self): for i in range(0, 20): BlockedContact('%d' % i, '').save() records = BlockedContact.find_with_pagination(page_request={'page_no': 2, 'size': 10}) print 'items', records self.assertEqual(10, len(records))