Beispiel #1
0
    def test_update(self):
        User('username', 'password', '*****@*****.**').save()
        User('username', 'another', '*****@*****.**').update()

        user = User.find(User(username='******'))
        print user
        self.assertEqual('*****@*****.**', user.email)
Beispiel #2
0
    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))
Beispiel #3
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"))
Beispiel #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'))
Beispiel #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'))
Beispiel #6
0
    def test_update(self):
        User("username", "password", "*****@*****.**").save()
        User("username", "another", "*****@*****.**").update()

        user = User.find(User(username="******"))
        print user
        self.assertEqual("*****@*****.**", user.email)
Beispiel #7
0
    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))
Beispiel #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()
Beispiel #9
0
 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()
Beispiel #10
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"))
Beispiel #11
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()
Beispiel #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()
Beispiel #13
0
def load_user(id):
    return User.find(User(username=id))
Beispiel #14
0
 def test_findall(self):
     User('username', 'password', '*****@*****.**', role='admin').save()
     self.assertEqual(1, len(User.findall()), 'Count of users should be 1')
Beispiel #15
0
def load_user(id):
    return User.find(User(username=id))
Beispiel #16
0
 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')
Beispiel #17
0
    def test_find(self):
        user = User("username", "password", "*****@*****.**")
        user.save()

        print User.find(user)
Beispiel #18
0
 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")
Beispiel #19
0
 def test_findall(self):
     User("username", "password", "*****@*****.**", role="admin").save()
     self.assertEqual(1, len(User.findall()), "Count of users should be 1")
Beispiel #20
0
    def test_find(self):
        user = User('username', 'password', '*****@*****.**')
        user.save()

        print User.find(user)