コード例 #1
0
 def test_find_by_id(self):
     ''' Test selection of specific data from pages table by id '''
     DB.setup()
     DB.seed()
     value = self.exec.find_by_id(1)
     self.assertIsNotNone(value)
     self.assertEqual(type(value), tuple)
コード例 #2
0
 def test_get_url(self):
     ''' Test selection of specific url by id'''
     DB.setup()
     DB.seed()
     value = self.exec.get_url(1)
     self.assertIsNotNone(value)
     self.assertEqual(type(value), tuple)
コード例 #3
0
 def test_select_by_id(self):
     ''' Test selection of specific data from links table by id '''
     DB.setup()
     DB.seed()
     self.exec.insert(1, 'https://www.google.com/')
     value = self.exec.select_by_id(1)
     self.assertIsNotNone(value)
     self.assertEqual(type(value), tuple)
コード例 #4
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
コード例 #5
0
ファイル: test_db.py プロジェクト: Rafiatu/spider-pyapp
class TestDatabase(TestCase):
    '''Class to test the database (db) functions'''
    def setUp(self):
        self.db = DB()

    def test_connection(self):
        '''tests that the connection function does it's work.'''
        connection = self.db.connect()
        self.assertIsNotNone(connection)

    def test_setup(self):
        '''tests that the setup function does what it was designed to do.'''
        self.db.setup()
        self.assertIsNone(self.db.setup())

    def test_seed(self):
        '''tests that the seed function does what it was designed to do.'''
        self.db.connect()
        self.db.setup()
        self.db.seed()
        self.assertIsNone(self.db.seed())

    def test_pages(self):
        '''tests that the pages function does what it was designed to do.'''
        self.db.connect()
        self.db.setup()
        self.db.seed()
        selecter = self.db.pages().select()
        self.assertIsNotNone(selecter)

    def test_links(self):
        '''tests that the links function does what it was designed to do.'''
        self.db.connect()
        self.db.setup()
        select_link = self.db.links().select()
        self.assertIsNotNone(select_link)

    def TearDown(self):
        '''the teardown function for all the tests.'''
        self.db.connect().close()
コード例 #6
0
 def test_select(self):
     ''' Test selection  of entire pages table '''
     DB.setup()
     DB.seed()
     value = self.exec.select()
     self.assertIsNotNone(value)
コード例 #7
0
 def test_delete_by_id(self):
     ''' Test selection from pages table '''
     DB.setup()
     DB.seed()
     value = self.exec.delete_by_id(1)
     self.assertEqual(value, None)
コード例 #8
0
 def test_update_by_id(self):
     ''' Test update is_scraping value by id '''
     DB.setup()
     DB.seed()
     value = self.exec.update_by_id(False, 1)
     self.assertEqual(value, None)
コード例 #9
0
 def test_seed(self):
     ''' Test table insertion '''
     self.assertEqual(DB.seed(), None)
コード例 #10
0
 def test_find_url(self):
     # Test the find_url method of Pages class in pages.py
     DB.seed()
     self.assertIsNotNone(self.exec.find_url(1))
コード例 #11
0
 def test_insert(self):
     ''' Test insert into links table '''
     DB.setup()
     DB.seed()
     value = self.exec.insert(1, 'https://www.google.com/')
     self.assertEqual(value, None)
コード例 #12
0
 def test_delete_by_page_id(self):
     ''' Test deletion of specific data in links table by page_id'''
     DB.setup()
     DB.seed()
     value = self.exec.delete_by_page_id(1)
     self.assertEqual(value, None)
コード例 #13
0
 def test_insert(self):
     DB().setup()
     DB.seed()
     self.assertEqual(self.links.insert(2, 'https://www.wikipedia.com'),
                      None)
コード例 #14
0
 def test_select(self):
     # Test the select method of the Links class in links.py
     DB.setup()
     DB.seed()
     self.assertIsNotNone(self.exec.select())
コード例 #15
0
 def test_insert(self):
     # Test the insert method of the Links class in links.py
     DB.setup()
     DB.seed()
     self.assertIsNone(self.exec.insert(1, 'https://facebook.com'))
コード例 #16
0
 def test_seed(self):
     self.assertEqual(DB.seed(), None)
コード例 #17
0
 def test_find(self):
     # Test the find method of Pages class in pages.py
     DB.seed()
     result = self.exec.find(2)
     self.assertIsNotNone(result)
コード例 #18
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)
コード例 #19
0
 def test_update(self):
     # Test the update method of Pages class in pages.py
     DB.seed()
     self.assertIsNone(self.exec.update(False, 1))
コード例 #20
0
 def test_select_urls(self):
     ''' Test selection of urls from pages table '''
     DB.setup()
     DB.seed()
     value = self.exec.select_urls()
     self.assertIsNotNone(value)