示例#1
0
 def setUp(self):
     load_dotenv('.env')
     self.browser = Browser(os.environ.get('LINUX'))
     self.nairaland = Nairaland(self.browser)
     self.user = User(self.browser)
     self.category = 'politics'
     self.topic = '5460114'
     self.search = 'buhari'
     self.username = os.environ.get('NL_USERNAME')
     self.password = os.environ.get('NL_PASSWORD')
     self.logged_in = self.browser.login(self.username, self.password)
示例#2
0
def user_post_share():
    if not request.form.get('post_slug'):
        return jsonify({'error': 'Post Slug is required!'}), 422
    # load browser for current request
    browser = Browser(os.environ.get('LINUX'))
    user = User(browser)

    # login first
    if not browser.login(username=os.environ.get('NL_USERNAME'),
                         user_pass=os.environ.get('NL_PASSWORD')):
        browser.driver.quit()
        return jsonify({'error': 'Login failed'})

    response = jsonify(
        user.like_post(request.form.get('post_slug'),
                       request.form.get('unshare')))
    browser.driver.quit()
    return response
示例#3
0
def user_topic_new(board):
    if not request.form.get('title') or not request.form.get('content'):
        return jsonify({'error': 'Title and Content are required!'}), 422
    # load browser for current request
    browser = Browser(os.environ.get('LINUX'))
    user = User(browser)

    # login first
    if not browser.login(username=os.environ.get('NL_USERNAME'),
                         user_pass=os.environ.get('NL_PASSWORD')):
        browser.driver.quit()
        return jsonify({'error': 'Login failed'})

    response = jsonify(
        user.new_topic(board, request.form.get('title'),
                       request.form.get('content')))
    browser.driver.quit()
    return response
示例#4
0
def user_post_new(topic):
    if not request.form.get('content'):
        return jsonify({'error': 'Content is required!'}), 422
    # load browser for current request
    browser = Browser(os.environ.get('LINUX'))
    user = User(browser)

    # login first
    if not browser.login(username=os.environ.get('NL_USERNAME'),
                         user_pass=os.environ.get('NL_PASSWORD')):
        browser.driver.quit()
        return jsonify({'error': 'Login failed'})

    response = jsonify(
        user.new_post(topic, request.form.get('content'),
                      request.form.get('post_id'), request.form.get('follow')))
    browser.driver.quit()
    return response
示例#5
0
def user_shared_with():
    # load browser for current request
    browser = Browser(os.environ.get('LINUX'))
    user = User(browser)

    # login first
    if not browser.login(username=os.environ.get('NL_USERNAME'),
                         user_pass=os.environ.get('NL_PASSWORD')):
        browser.driver.quit()
        return jsonify({'error': 'Login failed'})

    if request.args.get('page'):
        try:
            page = int(request.args.get('page'))
        except:
            page = 0
    else:
        page = 0
    response = jsonify(user.shared_with(page))
    browser.driver.quit()
    return response
示例#6
0
def category_topics(category):
    if request.args.get('page'):
        try:
            page = int(request.args.get('page'))
        except:
            page = 0
    else:
        page = 0

    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)
    response = jsonify(nairaland.category_topics(category, page))
    browser.driver.quit()
    return response
示例#7
0
def user_posts(user):
    if request.args.get('page'):
        try:
            page = int(request.args.get('page'))
        except:
            page = 0
    else:
        page = 0

    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)
    response = jsonify(nairaland.user_posts(user, page))
    browser.driver.quit()
    return response
示例#8
0
def topics_trending():
    if request.args.get('page'):
        try:
            page = int(request.args.get('page'))
        except:
            page = 0
    else:
        page = 0

    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)
    response = jsonify(nairaland.trending_topics(page))
    browser.driver.quit()
    return response
示例#9
0
def categories():
    if request.args.get('depth'):
        try:
            depth = int(request.args.get('depth'))
        except:
            depth = 0
    else:
        depth = 0

    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)

    response = jsonify(nairaland.categories(depth))
    browser.driver.quit()
    return response
示例#10
0
def search():
    if not request.form.get('term'):
        return jsonify({'error': 'term is required!'}), 422
    if request.args.get('page'):
        try:
            page = int(request.args.get('page'))
        except:
            page = 0
    else:
        page = 0

    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)

    board = request.form.get('board') if request.form.get('board') else 0
    response = jsonify(nairaland.search(request.form.get('term'), board, page))
    browser.driver.quit()
    return response
示例#11
0
class TestCase(unittest.TestCase):
    def setUp(self):
        load_dotenv('.env')
        self.browser = Browser(os.environ.get('LINUX'))
        self.nairaland = Nairaland(self.browser)
        self.user = User(self.browser)
        self.category = 'politics'
        self.topic = '5460114'
        self.search = 'buhari'
        self.username = os.environ.get('NL_USERNAME')
        self.password = os.environ.get('NL_PASSWORD')
        self.logged_in = self.browser.login(self.username, self.password)

    def tearDown(self):
        self.browser.driver.quit()

    def test_front_page_topics(self):
        assert type(self.nairaland.front_page_topics()) == dict

    def test_categories(self):
        assert type(self.nairaland.categories()) == dict

    def test_trending_topics(self):
        assert type(self.nairaland.trending_topics()) == dict

    def test_new_topics(self):
        assert type(self.nairaland.new_topics()) == dict

    def test_recent_posts(self):
        assert type(self.nairaland.recent_posts()) == dict

    def test_user(self):
        assert type(self.nairaland.user(self.username)) == dict

    def test_user_posts(self):
        assert type(self.nairaland.user_posts(self.username)) == dict

    def test_user_topics(self):
        assert type(self.nairaland.user_topics(self.username)) == dict

    def test_category_topics(self):
        assert type(self.nairaland.category_topics(self.category)) == dict

    def test_topic_posts(self):
        assert type(self.nairaland.topic_posts(self.topic)) == dict

    def test_search(self):
        assert type(self.nairaland.search(self.search)) == dict

    def test_login(self):
        if not self.logged_in:
            assert self.browser.login(self.username, self.password) == True
        else:
            assert self.logged_in == True


# Authenticated methods

    def test_user_followed_topics(self):
        assert type(self.user.followed_topics()) == dict

    def test_user_followed_boards(self):
        assert type(self.user.followed_boards()) == dict

    def test_user_likes_and_shares(self):
        assert type(self.user.likes_and_shares()) == dict

    def test_user_mentions(self):
        assert type(self.user.mentions()) == dict

    def test_user_following_posts(self):
        assert type(self.user.following_posts()) == dict

    def test_user_shared_with(self):
        assert type(self.user.shared_with()) == dict
示例#12
0
def home_route():
    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)
    response = jsonify(nairaland.front_page_topics())
    browser.driver.quit()
    return response
示例#13
0
def user_profile(user):
    browser = Browser(os.environ.get('LINUX'))
    nairaland = Nairaland(browser)
    response = jsonify(nairaland.user(user))
    browser.driver.quit()
    return response