示例#1
0
class TestDb(unittest.TestCase):
    '''class that tests db class in _init_.py'''
    def setUp(self):
        '''function that sets up for testing '''
        self.db = DB()

    def test_connect(self):
        '''function that tests the connect function'''
        connection_object = self.db.connect()
        self.assertIsNotNone(connection_object)

    def test_new_connect(self):
        '''function that tests the new_connect function'''
        connection_object = self.db.new_connect()
        self.assertIsNotNone(connection_object)

    def test_setup(self):
        '''function that tests the setup function'''
        self.assertEqual(self.db.setup(), None)
        cursor = self.db.new_connect().cursor()
        query = cursor.execute('SELECT url FROM pages WHERE id=1 ')
        self.assertEqual(query, None)

    def test_seed(self):
        '''function that tests the seed function'''
        self.db.setup()
        seed = self.db.seed()
        self.assertIsNone(seed)

    def tearDown(self):
        self.db = None
示例#2
0
文件: main.py 项目: Remi288/Spiderapp
# Show examples of how you would use ALL your implementations here
from src.db import DB
from src.spider import spider_scrap
from celery import Celery
from decouple import config
#
db = DB()
db.connect()
db.new_connect()
db.setup()
db.seed()
dd = DB.new_connect()
pages = DB.pages()
# pages.fetch_url(2)
print(pages.fetch_url(2))
print(pages.select())
print(pages.find(2))
# print(pages.update_id(1))
links = DB.links()
print(links.insert(1, 'www.goggle.com'))
print(links.delete(1))
print(links.select(1))
# #
# app = Celery('main', broker=config('CELERY_BROKER'), backend=config('CELERY_BACKEND'))
#
#
# @app.task
# def scrap_url():
#   return spider_scrap(1)

# spider_scrap(1)
示例#3
0
 def setUp(self) -> None:
     self.links = Links(DB.new_connect())
示例#4
0
 def setUp(self) -> None:
     self.pages = Pages(DB.new_connect())