Пример #1
0
 def setUp(self):
     create_schema()
     self.user = User(email="*****@*****.**", display_name="First Last")
     self.another_user = User(email="*****@*****.**",
                              display_name="Yet another User")
     db.session.add(self.user)
     db.session.add(self.another_user)
     db.session.commit()
     self.sender = Sender()
     self.sender._send_email = Mock()
Пример #2
0
 def setUp(self):
   create_schema()
   self.user = User(email = "*****@*****.**", display_name = "First Last")
   self.another_user = User(email = "*****@*****.**", display_name = "Yet another User")
   db.session.add(self.user)
   db.session.add(self.another_user)
   db.session.commit()
   self.sender = Sender()
   self.sender._send_email = Mock()
Пример #3
0
def create_account():
  linkedin_oauth_token = request.form["linkedin_oauth_token"]
  r = requests.get("https://api.linkedin.com/v1/people::(~):(id,first-name,last-name,headline,location,industry,num-connections,summary,specialties,positions,picture-url,public-profile-url,email-address,associations,interests,publications,patents,languages,skills,certifications,educations,courses,volunteer,num-recommenders,honors-awards)",
      headers={"oauth_token": linkedin_oauth_token,
        "x-li-format": "json"})

  app.logger.info("Creating an account LinkedIn response: %s" % (r.text))

  user_json = r.json()["values"][0]

  user = User(email = user_json["emailAddress"],
      display_name = "%s %s" % (user_json["firstName"], user_json["lastName"]),
      headline = user_json["headline"],
      industry = user_json["industry"],
      location = user_json["location"]["name"],
      interested_in = "",
      photo_url = user_json["pictureUrl"]
      )

  profile = Profile(external_key = user_json["id"],
      data_json = json.dumps(user_json))

  user.profiles.append(profile)

  db.session.add(user)
  db.session.add(profile)

  try:
    db.session.commit()

    sender = Sender()
    sender.send_invitation_email(user)

    flash("To activate your account you need to respond to invitation email. Please reply JOIN OZAUR.")
  except IntegrityError, e:
    db.session.rollback()
    user = User.query.filter(User.email == user_json["emailAddress"]).first()
Пример #4
0
class TestSender(unittest.TestCase):
  def setUp(self):
    create_schema()
    self.user = User(email = "*****@*****.**", display_name = "First Last")
    self.another_user = User(email = "*****@*****.**", display_name = "Yet another User")
    db.session.add(self.user)
    db.session.add(self.another_user)
    db.session.commit()
    self.sender = Sender()
    self.sender._send_email = Mock()

  def tearDown(self):
    delete_schema()

  def test_invitation_email(self):
    self.sender.send_invitation_email(self.user)
    self.assertEqual(len(self.user.active_emails), 1)
    self.assertEqual(len(self.sender._send_email.call_args_list), 1)
    email = self.user.active_emails[0]
    args, kwargs = self.sender._send_email.call_args
    self.assertIn(email.email_hash, args[-1])

  def test_welcome_email(self):
    self.sender.send_welcome_email(self.user)
    self.assertEqual(len(self.user.active_emails), 0)
    self.assertEqual(len(self.sender._send_email.call_args_list), 1)
    args, kwargs = self.sender._send_email.call_args
    self.assertIn("welcome", args[-2].lower())

  def test_question_email(self):
    transaction = Transaction(bid_id_old = 42,
        bid_created_at = self.user.created_at,
        buyer_user_id = self.user.id,
        seller_user_id = self.another_user.id,
        value_satoshi = 100,
        coinbase_order = "unknown",
        status = "wait_for_question")
    db.session.add(transaction)
    db.session.commit()
    self.sender.send_question_email(transaction)
    self.assertEqual(len(self.user.active_emails), 1)
    self.assertEqual(len(self.another_user.active_emails), 0)
    self.assertEqual(len(self.sender._send_email.call_args_list), 1)
    email = self.user.active_emails[0]
    args, kwargs = self.sender._send_email.call_args
    self.assertIn(email.email_hash, args[-1])
    self.assertEqual(args[0], self.user)
    self.assertEqual(email.transaction_id, transaction.id)

  def test_answer_email(self):
    transaction = Transaction(bid_id_old = 42,
        bid_created_at = self.user.created_at,
        buyer_user_id = self.user.id,
        seller_user_id = self.another_user.id,
        value_satoshi = 100,
        coinbase_order = "unknown",
        status = "wait_for_answer")
    db.session.add(transaction)
    db.session.commit()
    self.sender.send_answer_email(transaction, "Why?")
    self.assertEqual(len(self.user.active_emails), 0)
    self.assertEqual(len(self.another_user.active_emails), 1)
    self.assertEqual(len(self.sender._send_email.call_args_list), 1)
    email = self.another_user.active_emails[0]
    args, kwargs = self.sender._send_email.call_args
    self.assertIn(email.email_hash, args[-1])
    self.assertIn("Why?", args[-1])
    self.assertEqual(args[0], self.another_user)
    self.assertEqual(email.transaction_id, transaction.id)

  def test_result_email(self):
    transaction = Transaction(bid_id_old = 42,
        bid_created_at = self.user.created_at,
        buyer_user_id = self.user.id,
        seller_user_id = self.another_user.id,
        value_satoshi = 100,
        coinbase_order = "unknown",
        status = "success")
    db.session.add(transaction)
    db.session.commit()
    self.sender.send_result_email(transaction, "42")
    self.assertEqual(len(self.user.active_emails), 0)
    self.assertEqual(len(self.another_user.active_emails), 0)
    self.assertEqual(len(self.sender._send_email.call_args_list), 1)
    args, kwargs = self.sender._send_email.call_args
    self.assertIn("42", args[-1])
    self.assertEqual(args[0], self.user)
Пример #5
0
class TestSender(unittest.TestCase):
    def setUp(self):
        create_schema()
        self.user = User(email="*****@*****.**", display_name="First Last")
        self.another_user = User(email="*****@*****.**",
                                 display_name="Yet another User")
        db.session.add(self.user)
        db.session.add(self.another_user)
        db.session.commit()
        self.sender = Sender()
        self.sender._send_email = Mock()

    def tearDown(self):
        delete_schema()

    def test_invitation_email(self):
        self.sender.send_invitation_email(self.user)
        self.assertEqual(len(self.user.active_emails), 1)
        self.assertEqual(len(self.sender._send_email.call_args_list), 1)
        email = self.user.active_emails[0]
        args, kwargs = self.sender._send_email.call_args
        self.assertIn(email.email_hash, args[-1])

    def test_welcome_email(self):
        self.sender.send_welcome_email(self.user)
        self.assertEqual(len(self.user.active_emails), 0)
        self.assertEqual(len(self.sender._send_email.call_args_list), 1)
        args, kwargs = self.sender._send_email.call_args
        self.assertIn("welcome", args[-2].lower())

    def test_question_email(self):
        transaction = Transaction(bid_id_old=42,
                                  bid_created_at=self.user.created_at,
                                  buyer_user_id=self.user.id,
                                  seller_user_id=self.another_user.id,
                                  value_satoshi=100,
                                  coinbase_order="unknown",
                                  status="wait_for_question")
        db.session.add(transaction)
        db.session.commit()
        self.sender.send_question_email(transaction)
        self.assertEqual(len(self.user.active_emails), 1)
        self.assertEqual(len(self.another_user.active_emails), 0)
        self.assertEqual(len(self.sender._send_email.call_args_list), 1)
        email = self.user.active_emails[0]
        args, kwargs = self.sender._send_email.call_args
        self.assertIn(email.email_hash, args[-1])
        self.assertEqual(args[0], self.user)
        self.assertEqual(email.transaction_id, transaction.id)

    def test_answer_email(self):
        transaction = Transaction(bid_id_old=42,
                                  bid_created_at=self.user.created_at,
                                  buyer_user_id=self.user.id,
                                  seller_user_id=self.another_user.id,
                                  value_satoshi=100,
                                  coinbase_order="unknown",
                                  status="wait_for_answer")
        db.session.add(transaction)
        db.session.commit()
        self.sender.send_answer_email(transaction, "Why?")
        self.assertEqual(len(self.user.active_emails), 0)
        self.assertEqual(len(self.another_user.active_emails), 1)
        self.assertEqual(len(self.sender._send_email.call_args_list), 1)
        email = self.another_user.active_emails[0]
        args, kwargs = self.sender._send_email.call_args
        self.assertIn(email.email_hash, args[-1])
        self.assertIn("Why?", args[-1])
        self.assertEqual(args[0], self.another_user)
        self.assertEqual(email.transaction_id, transaction.id)

    def test_result_email(self):
        transaction = Transaction(bid_id_old=42,
                                  bid_created_at=self.user.created_at,
                                  buyer_user_id=self.user.id,
                                  seller_user_id=self.another_user.id,
                                  value_satoshi=100,
                                  coinbase_order="unknown",
                                  status="success")
        db.session.add(transaction)
        db.session.commit()
        self.sender.send_result_email(transaction, "42")
        self.assertEqual(len(self.user.active_emails), 0)
        self.assertEqual(len(self.another_user.active_emails), 0)
        self.assertEqual(len(self.sender._send_email.call_args_list), 1)
        args, kwargs = self.sender._send_email.call_args
        self.assertIn("42", args[-1])
        self.assertEqual(args[0], self.user)