def test_position_list_limit(self):
        """Test that position_list returns positions using the limit argument"""

        # now look at the limit argument
        positions = interface.position_list(self.db, limit=3)
        self.assertEqual(3, len(positions))

        positions = interface.position_list(self.db, limit=1)
        self.assertEqual(1, len(positions))

        # limit higher than number of positions
        positions = interface.position_list(self.db, limit=100)
        self.assertEqual(50, len(positions))
Ejemplo n.º 2
0
def index(db):

    # Get the top 10 users
    job_id = interface.position_list(db, 10)
    info = {'positions': job_id}
    name = users.session_user(db)
    if users.session_user(db):
        nick = {'nick': name}
        return template('index_login.html', nick)
    else:
        return template('index.html', info)
Ejemplo n.º 3
0
    def test_position_add_bad_usernick(self):
        """Test adding new positions"""

        usernick = 'Nonexistant'
        title = "Sample Job Ad"
        location = "Sydney"
        company = "ACME Widgets"
        description = "This is the description"

        # get an initial count of positions
        positioncount = len(interface.position_list(self.db, limit=1000))

        result = interface.position_add(self.db, usernick, title, location, company, description)

        # should have returned False because the user nick does not exist
        self.assertFalse(result)

        # should have the same number of positions
        positions = interface.position_list(self.db, limit=1000)
        self.assertEqual(positioncount, len(positions))
Ejemplo n.º 4
0
def index(db):
    poslist = interface.position_list(db, 10)
    name = users.session_user(db)

    info = {
        'title': 'The Chalkboard',
        'message': 'Welcome to Jobs!',
        'name': name
    }

    return template('index', info, jobs=poslist)
Ejemplo n.º 5
0
def index(db):
    """Computes the recent 10 job postings and displays it on mainpage"""
    data = interface.position_list(db, 10)
    info['rows'] = data

    user = request.get_cookie('sessionid')

    #if session  already exist display customized homepage else display mainpage
    if user == None:
        return template('index', info)
    else:
        info['message'] = 'Logged in as ' + users.session_user(db)
        return template('index_logout', info)
    def test_position_list(self):
        """Test that position_list returns positions"""

        # first get all positions
        positions = interface.position_list(self.db, limit=1000)

        self.assertEqual(len(self.positions), len(positions))

        # validate the returned values

        self.assertEqual(1, positions[0][0])
        self.assertEqual('2018-03-07 22:36:19', positions[0][1])
        # can't check owner as it is randomly assigned
        self.assertEqual('Staff Site Reliability Engineer ', positions[0][3])
Ejemplo n.º 7
0
    def test_position_add(self):
        """Test adding new positions"""

        usernick = 'Bean'
        title = "Sample Job Ad"
        location = "Sydney"
        company = "ACME Widgets"
        description = "This is the description"

        # get an initial count of positions
        positioncount = len(interface.position_list(self.db, limit=1000))

        result = interface.position_add(self.db, usernick, title, location, company, description)

        # should have returned True for succesful insertion
        self.assertTrue(result)

        # should now have one more position
        positions = interface.position_list(self.db, limit=1000)
        self.assertEqual(1, len(positions)-positioncount)

        # check the latest one is the one we added
        self.assertEqual(title, positions[0][3])
Ejemplo n.º 8
0
def index(db):
    """
    index method for routing on index.html and homepage '/'
    :param db: Accepts db conncetion
    :return: index page template
    """
    positions = interface.position_list(db,10) # Calling position_list method which returns list of tuples - positions
    # method returns most recent 10 positions ordered by date which is then passed to the view for displaying

    active_user = users.session_user(db) # Fetching active user name
    message = dict() #Creating dictionary entry for message passing.
    message["positions"] = positions
    message["user"] = active_user
    message["title"] = "Jobs Home"
    return template("index" , message = message)
Ejemplo n.º 9
0
def index(db):
    """Passing positions data to the index.html page by calling the position_list function from interface.py
    sending that info to the index.html where it is separated and displayed accordingly.
    Returns the template along with the most recent 10 positions to be displayed in the homepage"""
    position = interface.position_list(db, 10)
    info = {
                'positions': position
            }
    if users.session_user(db):
        """If the user has logged in, then render "login_index" template. 
        Pass the username and avatar of the user to display in the template"""
        return template('login_index', info, user=users.session_user(db),
                        avatar=users.get_avatar(db, users.session_user(db)))
    else:
        return template('index.html', info)
Ejemplo n.º 10
0
def login_req(db):
    """Authenticate user. If it is a valid user redirect to customized home page else redirect to mainpage"""

    #get post parameter
    username = request.forms.get("nick")
    password = request.forms.get("password")

    #check if user is valid if yes append username to greeting message else indicate login error message
    if (users.check_login(db, username, password)):
        users.generate_session(db, username)
        info['message'] = 'Logged in as ' + str(username)
        redirect('/')
    else:
        data = interface.position_list(db, 10)
        info['rows'] = data
        info['message'] = 'Login Failed, please try again'
        return template("index", info)
Ejemplo n.º 11
0
def index(db):
    position_list_ = [(position[0], position[1], position[2], position[3],
                       str(str(position[6])[:100]))
                      for position in position_list(db)]
    form_data = '''
            <form action="/login" method="post" id="loginform">
                Nick: <input name="nick" type="text" />
                Password: <input name="password" type="password" />
                <input value="Login" type="submit" />
            </form>
        '''
    user = session_user(db)
    if user:

        form_data = '''
        Logged in as Bobalooba
        <br>
        

        <form action="/post" method="post" id="postform">
                company: <input name="company" type="text" />
                title: <input name="title" type="text" />
                location: <input name="location" type="text" />
                description: <input name="description" type="text" />
                
                <input value="Login" type="submit" />
            </form>

            <br>
            <form action="/logout" method="post" id="logoutform">
               
                <button name='logout' value="Login" type="submit" >logout </but
            </form>
        '''
    info = {
        'title': 'Home',
        'position_list': position_list_,
        'form_data': form_data,
        'fail': ''
    }

    return template('index', info)
Ejemplo n.º 12
0
def index(db, page=1):
    PAGE_SIZE = 12              # Number of positions to display per page
    end = int(page) * PAGE_SIZE      # The last positions
    start = end - PAGE_SIZE     #

    list = interface.position_list(db, limit=1)


    i = 0
    position_list = list[start:end]
    positions = []
    for position in position_list:
        # Convert the tuple to a dictionary and Add a random color for displaying the position
        obj = {
            "id": position[0],
            "color": COLOR_CHOICES[random.randint(0, len(COLOR_CHOICES)-1)],
            "timestamp": position[1],
            "owner": position[2],
            "title": position[3],
            "location": position[4],
            "company": position[5],
            "description": position[6]
        }
        positions.append(obj)




    info = {
        'title': 'My Website',
        'positions': positions,
        'next': "/positions/page=" + str(int(page)+1),
        'previous': "/positions/page=" + str(int(page) - 1)
    }

    return template('index', info)