Esempio n. 1
0
def cleanup():
    ''' cleanup:
    Helper function used for testing, cleans up the app's database and
    environment during a testing.
    '''
    from .decorators import cache
    cache.clear()
    database.cleanup()
Esempio n. 2
0
 def test_show_rentals(self):
     """tests show rentals function"""
     cleanup()
     import_data('csvfiles', 'products.csv', 'customers.csv', 'rentals.csv')
     actual = show_rentals('prd001')
     expected = {"user001": {"name": "Elisa Miles", "address": "4490 Union Street",
                             "phone_number": "206-922-0882",
                             "email": "*****@*****.**"}}
     self.assertEqual(actual, expected)
Esempio n. 3
0
 def test_show_available_products(self):
     """test show available products function"""
     cleanup()
     import_data('csvfiles', 'products.csv', 'customers.csv', 'rentals.csv')
     actual = show_available_products()
     expected = {"prd001": {"description": "60-in tv",
                            "product_type": "livingroom",
                            "quantity_available": "3"}}
     self.assertEqual(actual, expected)
Esempio n. 4
0
def mongo_database():
    """
    Creates a MongoDB.
    :return:
    """
    mongo = d.MongoDBConnection()
    with mongo:
        db = mongo.connection.media

        yield db

        d.cleanup()
Esempio n. 5
0
def get_shop_review(shop_id):
    result = {}
    tmp_list = []
    page = 1
    counter = 0
    try:
        while True:
            review_page = BASE_URL + '/shop/' + str(shop_id) + '/comments?p=' + str(page)
            comment = requests.get(review_page)
            soup = BeautifulSoup(comment.content, PARSER)

            review_list = soup.find('section', class_="review-list")

            articles = review_list.find_all('article', attrs={'itemprop': "review"})
            if len(articles) is 0:
                break
            print(">>Getting review : ", shop_id)
            print(">>Page:", page)
            for article in articles:
                review_url = BASE_URL + article.a['href']
                review_datetime = str(article.find('time')['datetime'])
                review_reply_count = extract_int(article.find(attrs={'data-label': "X則回應"}).text)
                try:
                    review_thumbs_up = extract_int(article.find(attrs={'data-label': "X人好評"}).text)
                except:
                    review_thumbs_up = '0'
                    print('No tag found')
                review_watch = extract_int(article.find(class_='extended').span.text)
                review_author = article.find('span', attrs={'itemprop': "author"}).text

                print(">>Reading review link:", review_url)

                result['shop_id'] = shop_id
                review = get_review_content(review_url, review_datetime, review_reply_count, review_thumbs_up,
                                            review_watch,
                                            review_author)
                tmp_list.append(review)

                counter += 1
            result['review_detail'] = tmp_list
            time.sleep(2)
            page += 1
        print(">>total:", counter)
        print(">>Get review url finish")
        # print(result)
    except:
        print('FAIL TO GET SHOP REVIEW ' + str(shop_id) + 'AT PAGE' + str(page))
        database.shop_is_fetch_reset(shop_id)
        database.cleanup(shop_id)
    if len(result) is 0:
        return None
    return result
Esempio n. 6
0
def cleanup():
    ''' cleanup:
    Helper function used for testing, cleans up the app's database and
    environment during a testing.
    '''
    database.cleanup()
Esempio n. 7
0
def cleanup():
    from .database import Forum
    database.cleanup()
    app.endpoint('root', '/forum/' + str(Forum.get_root()))
Esempio n. 8
0
 def test_import_data_success(self):
     """tests successful import of data"""
     cleanup()
     actual = import_data('csvfiles', 'products.csv', 'customers.csv', 'rentals.csv')
     self.assertEqual(actual, ((4, 4, 5), (0, 0, 0)))
Esempio n. 9
0
 def test_import_data_fails(self):
     """test failed import of data"""
     cleanup()
     actual = import_data('csvfiles', 'product.csv', 'customer.csv', 'rental.csv')
     self.assertEqual(actual, ((0, 0, 0), (1, 1, 1)))
Esempio n. 10
0
def cleanup():
    ''' cleanup:
    Helper function used for testing, cleans up the app's database and
    environment during a testing.
    '''
    database.cleanup()