Exemple #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")
     self.email = Email(purpose="verify")
     self.user.active_emails.append(self.email)
     db.session.add(self.user)
     db.session.add(self.another_user)
     db.session.commit()
     self.sender = Mock()
     self.trader = Mock()
     self.responder = Responder(self.sender, self.trader)
Exemple #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")
   self.email = Email(purpose = "verify")
   self.user.active_emails.append(self.email)
   db.session.add(self.user)
   db.session.add(self.another_user)
   db.session.commit()
   self.sender = Mock()
   self.trader = Mock()
   self.responder = Responder(self.sender, self.trader)
Exemple #3
0
class TestResponder(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")
    self.email = Email(purpose = "verify")
    self.user.active_emails.append(self.email)
    db.session.add(self.user)
    db.session.add(self.another_user)
    db.session.commit()
    self.sender = Mock()
    self.trader = Mock()
    self.responder = Responder(self.sender, self.trader)

  def tearDown(self):
    delete_schema()

  def test_accept_invitation(self):
    self.responder.process_email(self.user.address_hash + "@example.com", "JOIN OZAUR; %s" % (self.email.email_hash), "JOIN OZAUR")
    db.session.refresh(self.user)
    self.assertEqual(self.user.active, True)
    self.assertEqual(Email.query.filter(Email.id == self.email.id).first(), None)
    archive = EmailArchive.query.filter(EmailArchive.email_id_old == self.email.id).first()
    self.assertNotEqual(archive, None)
    self.assertEqual(archive.email_hash, self.email.email_hash)
    self.assertEqual(len(self.sender.send_welcome_email.call_args_list), 1)

  def test_ignore_invalid_address(self):
    self.responder.process_email("*****@*****.**", "JOIN OZAUR; %s" % (self.email.email_hash), "JOIN OZAUR")
    db.session.refresh(self.user)
    self.assertEqual(self.user.active, False)

  def test_ignore_invalid_hash(self):
    self.responder.process_email(self.user.address_hash + "@example.com", "JOIN OZAUR; without code", "JOIN OZAUR")
    db.session.refresh(self.user)
    self.assertEqual(self.user.active, False)

  def test_ignore_invalid_invalid_word(self):
    self.responder.process_email(self.user.address_hash + "@example.com", "JOIN OZAUR; without code", "not joining")
    db.session.refresh(self.user)
    self.assertEqual(self.user.active, False)

  def test_got_question(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")
    email = Email(to_user_id = self.user.id, purpose = "ask")
    transaction.active_emails.append(email)
    db.session.add(transaction)
    db.session.commit()
   
    self.responder.process_email(self.user.address_hash + "@example.com",
        "Hash: %s ..." % (email.email_hash), "Some question?")

    db.session.refresh(transaction)
    db.session.refresh(self.user)

    self.assertEqual(len(self.user.active_emails), 1) # We still have verification left
    self.trader.question_asked.assert_called_with(self.user, transaction, "Some question?")

  def test_got_question_twice(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")
    email = Email(to_user_id = self.user.id, purpose = "ask")
    transaction.active_emails.append(email)
    db.session.add(transaction)
    db.session.commit()
   
    from_email = self.user.address_hash + "@example.com"
    self.responder.process_email(from_email,
        "Hash: %s ..." % (email.email_hash), "Some question?\n%s" % (from_email))

    db.session.refresh(transaction)
    db.session.refresh(self.user)

    self.assertEqual(len(self.user.active_emails), 1) # We still have verification left
    self.trader.question_asked.assert_called_with(self.user, transaction, "Some question?")


  def test_got_answer(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")
    email = Email(to_user_id = self.another_user.id, purpose = "answer")
    transaction.active_emails.append(email)
    db.session.add(transaction)
    db.session.commit()
   
    self.responder.process_email(self.another_user.address_hash + "@example.com",
        "Hash: %s ..." % (email.email_hash), "Some answer")

    db.session.refresh(transaction)
    db.session.refresh(self.another_user)

    self.assertEqual(len(self.another_user.active_emails), 0)
    self.trader.question_answered.assert_called_with(self.another_user, transaction, "Some answer")

  def test_got_answer_twice(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")
    email = Email(to_user_id = self.another_user.id, purpose = "answer")
    transaction.active_emails.append(email)
    db.session.add(transaction)
    db.session.commit()
   
    from_email = self.another_user.address_hash + "@example.com"
    self.responder.process_email(from_email,
        "Hash: %s ..." % (email.email_hash), "Some answer\n%s" % (from_email))

    db.session.refresh(transaction)
    db.session.refresh(self.another_user)

    self.assertEqual(len(self.another_user.active_emails), 0)
    self.trader.question_answered.assert_called_with(self.another_user, transaction, "Some answer")
Exemple #4
0
class TestResponder(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")
        self.email = Email(purpose="verify")
        self.user.active_emails.append(self.email)
        db.session.add(self.user)
        db.session.add(self.another_user)
        db.session.commit()
        self.sender = Mock()
        self.trader = Mock()
        self.responder = Responder(self.sender, self.trader)

    def tearDown(self):
        delete_schema()

    def test_accept_invitation(self):
        self.responder.process_email(
            self.user.address_hash + "@example.com",
            "JOIN OZAUR; %s" % (self.email.email_hash), "JOIN OZAUR")
        db.session.refresh(self.user)
        self.assertEqual(self.user.active, True)
        self.assertEqual(
            Email.query.filter(Email.id == self.email.id).first(), None)
        archive = EmailArchive.query.filter(
            EmailArchive.email_id_old == self.email.id).first()
        self.assertNotEqual(archive, None)
        self.assertEqual(archive.email_hash, self.email.email_hash)
        self.assertEqual(len(self.sender.send_welcome_email.call_args_list), 1)

    def test_ignore_invalid_address(self):
        self.responder.process_email(
            "*****@*****.**", "JOIN OZAUR; %s" % (self.email.email_hash),
            "JOIN OZAUR")
        db.session.refresh(self.user)
        self.assertEqual(self.user.active, False)

    def test_ignore_invalid_hash(self):
        self.responder.process_email(self.user.address_hash + "@example.com",
                                     "JOIN OZAUR; without code", "JOIN OZAUR")
        db.session.refresh(self.user)
        self.assertEqual(self.user.active, False)

    def test_ignore_invalid_invalid_word(self):
        self.responder.process_email(self.user.address_hash + "@example.com",
                                     "JOIN OZAUR; without code", "not joining")
        db.session.refresh(self.user)
        self.assertEqual(self.user.active, False)

    def test_got_question(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")
        email = Email(to_user_id=self.user.id, purpose="ask")
        transaction.active_emails.append(email)
        db.session.add(transaction)
        db.session.commit()

        self.responder.process_email(self.user.address_hash + "@example.com",
                                     "Hash: %s ..." % (email.email_hash),
                                     "Some question?")

        db.session.refresh(transaction)
        db.session.refresh(self.user)

        self.assertEqual(len(self.user.active_emails),
                         1)  # We still have verification left
        self.trader.question_asked.assert_called_with(self.user, transaction,
                                                      "Some question?")

    def test_got_question_twice(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")
        email = Email(to_user_id=self.user.id, purpose="ask")
        transaction.active_emails.append(email)
        db.session.add(transaction)
        db.session.commit()

        from_email = self.user.address_hash + "@example.com"
        self.responder.process_email(from_email,
                                     "Hash: %s ..." % (email.email_hash),
                                     "Some question?\n%s" % (from_email))

        db.session.refresh(transaction)
        db.session.refresh(self.user)

        self.assertEqual(len(self.user.active_emails),
                         1)  # We still have verification left
        self.trader.question_asked.assert_called_with(self.user, transaction,
                                                      "Some question?")

    def test_got_answer(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")
        email = Email(to_user_id=self.another_user.id, purpose="answer")
        transaction.active_emails.append(email)
        db.session.add(transaction)
        db.session.commit()

        self.responder.process_email(
            self.another_user.address_hash + "@example.com",
            "Hash: %s ..." % (email.email_hash), "Some answer")

        db.session.refresh(transaction)
        db.session.refresh(self.another_user)

        self.assertEqual(len(self.another_user.active_emails), 0)
        self.trader.question_answered.assert_called_with(
            self.another_user, transaction, "Some answer")

    def test_got_answer_twice(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")
        email = Email(to_user_id=self.another_user.id, purpose="answer")
        transaction.active_emails.append(email)
        db.session.add(transaction)
        db.session.commit()

        from_email = self.another_user.address_hash + "@example.com"
        self.responder.process_email(from_email,
                                     "Hash: %s ..." % (email.email_hash),
                                     "Some answer\n%s" % (from_email))

        db.session.refresh(transaction)
        db.session.refresh(self.another_user)

        self.assertEqual(len(self.another_user.active_emails), 0)
        self.trader.question_answered.assert_called_with(
            self.another_user, transaction, "Some answer")