コード例 #1
0
ファイル: tests.py プロジェクト: noushadali/zjobs
    def test_update(self):
        User('username', 'password', '*****@*****.**').save()
        User('username', 'another', '*****@*****.**').update()

        user = User.find(User(username='******'))
        print user
        self.assertEqual('*****@*****.**', user.email)
コード例 #2
0
ファイル: tests.py プロジェクト: noushadali/zjobs
    def test_find_with_pagination(self):
        for i in range(0, 20):
            User('User_%d' % i, '').save()

        records = User.find_with_pagination(page_request={'page_no': 2, 'size': 10})

        print 'items', records
        self.assertEqual(10, len(records))
コード例 #3
0
ファイル: jobboard.py プロジェクト: peisam/zjobs
def login():
    user_name = request.form.get("username", "")
    user_password = request.form.get("password", "")
    redirect_url = request.form.get("next", url_for("index"))
    if user_name != "" and user_password != "":
        if User.validate(User(user_name, user_password)):
            user = User.find(User(user_name))
            user.last_login_date = datetime.datetime.now()
            user.save()
            login_user(user)
            return redirect(redirect_url)
        else:
            return redirect(url_for("index"))
    else:
        return redirect(url_for("index"))
コード例 #4
0
def login():
    user_name = request.form.get('username', '')
    user_password = request.form.get('password', '')
    redirect_url = request.form.get('next', url_for('index'))
    if user_name != '' and user_password != '':
        if User.validate(User(user_name, user_password)):
            user = User.find(User(user_name))
            user.last_login_date = datetime.datetime.now()
            user.save()
            login_user(user)
            return redirect(redirect_url)
        else:
            return redirect(url_for('index'))
    else:
        return redirect(url_for('index'))
コード例 #5
0
def register_user():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    email = request.form.get('email', '')

    if User.find(User(username=username)) is not None:
        response = make_response('internal error - User %s already exists' %
                                 username)
        response.status = 'internal error - User %s already exists' % username
        response.status_code = 500
        return response
    else:
        User(username=username, password=password, email=email).save()

    return redirect(url_for('index'))
コード例 #6
0
ファイル: tests.py プロジェクト: peisam/zjobs
    def test_update(self):
        User("username", "password", "*****@*****.**").save()
        User("username", "another", "*****@*****.**").update()

        user = User.find(User(username="******"))
        print user
        self.assertEqual("*****@*****.**", user.email)
コード例 #7
0
ファイル: tests.py プロジェクト: peisam/zjobs
    def test_find_with_pagination(self):
        for i in range(0, 20):
            User("User_%d" % i, "").save()

        records = User.find_with_pagination(page_request={"page_no": 2, "size": 10})

        print "items", records
        self.assertEqual(10, len(records))
コード例 #8
0
    def run_emailer(cls):
        from email.mime.base import MIMEBase
        from email.mime.multipart import MIMEMultipart
        from email.mime.text import MIMEText
        from email import Encoders
        import smtplib

        logger.info('start sending email to subscribers...')
        smtp = smtplib.SMTP(host=config.SMTP_HOST, port=config.SMTP_PORT)

        try:
            smtp.set_debuglevel(4)
            smtp.ehlo()
            smtp.starttls()
            smtp.ehlo()
            smtp.login(user=config.SMTP_USER, password=config.SMTP_PASSWORD)

            logger.info('established secure connection to smtp server...')

            toaddrs = [
                user.email for user in User.findall()
                if user.subscription_status == 'subscribed'
            ]
            print toaddrs
            fromaddr = config.FROM_ADDR

            current_date_string = datetime.datetime.now().strftime('%Y-%m-%d')
            message_subject = "%s:%s" % (config.APP_NAME, current_date_string)
            message_text = "Thank you for subscribing %s. Please find the newly posted jobs as of %s" % (
                config.APP_NAME, current_date_string)

            msg = MIMEMultipart()
            msg['From'] = fromaddr
            msg['To'] = ''
            msg['Cc'] = ','.join(toaddrs)
            msg['Subject'] = message_subject
            msg.attach(MIMEText(message_text))

            part = MIMEBase('application', "octet-stream")
            file_format = 'xlsx'
            part.set_payload(JobItem.extract_records_as_bytes(file_format))
            logger.info(
                'attached extracted files to the mail...waiting to be sent..')
            Encoders.encode_base64(part)
            part.add_header(
                'Content-Disposition',
                'attachment; filename="extracted_jobs_%s.%s"' %
                (current_date_string, file_format))
            msg.attach(part)

            smtp.sendmail(fromaddr, toaddrs, msg.as_string())
            logger.info('done sending email to subscribers...')
        except Exception as e:
            logger.error(e)
        finally:
            smtp.quit()
コード例 #9
0
ファイル: tests.py プロジェクト: noushadali/zjobs
 def test_save(self):
     User('username', 'password', '*****@*****.**').save()
     conn = self.connect_db()
     try:
         c = conn.cursor()
         c.execute('SELECT COUNT(*) FROM ' + User.table_name)
         self.assertEqual(c.fetchone()[0], 1, 'Count of rejection_pattern should be 1')
     except:
         pass
     finally:
         conn.close()
コード例 #10
0
ファイル: jobboard.py プロジェクト: peisam/zjobs
def register_user():
    username = request.form.get("username", "")
    password = request.form.get("password", "")
    email = request.form.get("email", "")

    if User.find(User(username=username)) is not None:
        response = make_response("internal error - User %s already exists" % username)
        response.status = "internal error - User %s already exists" % username
        response.status_code = 500
        return response
    else:
        User(username=username, password=password, email=email).save()

    return redirect(url_for("index"))
コード例 #11
0
ファイル: run.py プロジェクト: dolphin93/zjobs
    def run_emailer(cls):
        from email.mime.base import MIMEBase
        from email.mime.multipart import MIMEMultipart
        from email.mime.text import MIMEText
        from email import Encoders
        import smtplib

        logger.info('start sending email to subscribers...')
        smtp = smtplib.SMTP(host=config.SMTP_HOST, port=config.SMTP_PORT)

        try:
            smtp.set_debuglevel(4)
            smtp.ehlo()
            smtp.starttls()
            smtp.ehlo()
            smtp.login(user=config.SMTP_USER, password=config.SMTP_PASSWORD)

            logger.info('established secure connection to smtp server...')

            toaddrs = [user.email for user in User.findall() if user.subscription_status == 'subscribed']
            print toaddrs
            fromaddr = config.FROM_ADDR

            current_date_string = datetime.datetime.now().strftime('%Y-%m-%d')
            message_subject = "%s:%s" % (config.APP_NAME, current_date_string)
            message_text = "Thank you for subscribing %s. Please find the newly posted jobs as of %s" % (
                config.APP_NAME, current_date_string)

            msg = MIMEMultipart()
            msg['From'] = fromaddr
            msg['To'] = ''
            msg['Cc'] = ','.join(toaddrs)
            msg['Subject'] = message_subject
            msg.attach(MIMEText(message_text))

            part = MIMEBase('application', "octet-stream")
            file_format = 'xlsx'
            part.set_payload(JobItem.extract_records_as_bytes(file_format))
            logger.info('attached extracted files to the mail...waiting to be sent..')
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition',
                            'attachment; filename="extracted_jobs_%s.%s"' % (current_date_string, file_format))
            msg.attach(part)

            smtp.sendmail(fromaddr, toaddrs, msg.as_string())
            logger.info('done sending email to subscribers...')
        except Exception as e:
            logger.error(e)
        finally:
            smtp.quit()
コード例 #12
0
    def migrate_db(cls):
        """
        place holder for putting the migrate db scripts -- need to be updated before every release
        :return:
        """

        cls.create_db()
        conn = cls.datasource.get_connection()
        try:
            logger.info('start migrating database')
            User('meng', 'meng123', '*****@*****.**', 'admin').save()
            logger.info('done migrating database')
        except Exception as e:
            logger.error('Unable to run migrate_db')
            logger.error(e)

        finally:
            conn.close()
コード例 #13
0
def load_user(id):
    return User.find(User(username=id))
コード例 #14
0
ファイル: tests.py プロジェクト: noushadali/zjobs
 def test_findall(self):
     User('username', 'password', '*****@*****.**', role='admin').save()
     self.assertEqual(1, len(User.findall()), 'Count of users should be 1')
コード例 #15
0
ファイル: jobboard.py プロジェクト: peisam/zjobs
def load_user(id):
    return User.find(User(username=id))
コード例 #16
0
ファイル: tests.py プロジェクト: noushadali/zjobs
 def test_validate(self):
     user = User('username', 'password', '*****@*****.**')
     user.save()
     self.assertFalse(User.validate(User('invalid_user', 'pass')), 'user should not be valid')
     self.assertTrue(User.validate(user), 'user should be valid')
コード例 #17
0
ファイル: tests.py プロジェクト: peisam/zjobs
    def test_find(self):
        user = User("username", "password", "*****@*****.**")
        user.save()

        print User.find(user)
コード例 #18
0
ファイル: tests.py プロジェクト: peisam/zjobs
 def test_validate(self):
     user = User("username", "password", "*****@*****.**")
     user.save()
     self.assertFalse(User.validate(User("invalid_user", "pass")), "user should not be valid")
     self.assertTrue(User.validate(user), "user should be valid")
コード例 #19
0
ファイル: tests.py プロジェクト: peisam/zjobs
 def test_findall(self):
     User("username", "password", "*****@*****.**", role="admin").save()
     self.assertEqual(1, len(User.findall()), "Count of users should be 1")
コード例 #20
0
ファイル: tests.py プロジェクト: noushadali/zjobs
    def test_find(self):
        user = User('username', 'password', '*****@*****.**')
        user.save()

        print User.find(user)