Beispiel #1
0
def test_login_failed(monkeypatch):
    app = BetterTestApp(server.app)
    from chatty.util import fb
    mocksend = MagicMock()
    monkeypatch.setattr(fb, "send_data", mocksend)
    uid = uidcrypt.encryptuid("1878285869108664")
    app.get("/bot/fb/signin_redirect?uid={}&state={}#tototoken".format(
        uid, "dummy"),
            status=400)
    assert mocksend.call_count == 0

    s = Session()
    s.add(User(1878285869108664))
    s.commit()
    s.close()

    app.get("/bot/fb/signin_redirect?uid={}&state={}#tototoken".format(
        uid, "dummy"),
            status=400)

    assert mocksend.call_count == 1
    assert_button(
        mocksend.call_args_list[0][0][0], "1878285869108664",
        "Please log in with",
        [fb.web_button("", "www.facebook.com/v2.8/dialog/oauth", "", "")])
Beispiel #2
0
def test_login_redirect(monkeypatch):
    app = BetterTestApp(server.app)
    from chatty.util import fb
    mocktokencheck = MagicMock(return_value=({
        "app_id": "dummy",
        "user_id": 123456
    }, "tokentoken"))
    monkeypatch.setattr(fb, "login_redirect_token_check", mocktokencheck)
    monkeypatch.setattr(
        fb, "profile_detail",
        MagicMock(return_value={'age_range': {
            "min": 18,
            "max": 21
        }}))
    uidenc = uidcrypt.encryptuid("1878285869108664")
    s = Session()
    s.add(User(1878285869108664))
    s.commit()
    s.close()
    tok = tokener.gen_token("1878285869108664", tokener.NS_LOGIN)
    r = app.get("/bot/fb/signin_redirect?uid={}&state={}#tototoken".format(
        uidenc, tok))

    assert r.status_int == 200
    u = User.get("1878285869108664")
    assert u.id == "1878285869108664"
    assert u.fb_id == "123456"
    assert u.age_min == 18
    assert u.age_max == 21
    assert u.signup_date is not None
Beispiel #3
0
def test_payments_invalid_menu(monkeypatch):
    app = BetterTestApp(server.app)
    from chatty.libs import slack
    import stripe
    slackpost = MagicMock()
    mock_customer_create = MagicMock(return_value=MagicMock(id="customerid"))
    mock_charge_create = MagicMock(return_value=MagicMock(id="chargeid"))
    monkeypatch.setattr(slack, "post", slackpost)
    monkeypatch.setattr(stripe.Customer, "create", mock_customer_create)
    monkeypatch.setattr(stripe.Charge, "create", mock_charge_create)
    User.create("1878285869108664", fb_id="testfbid")
    uidenc = uidcrypt.encryptuid("1878285869108664")
    tok = tokener.gen_token("1878285869108664", tokener.NS_PAYMENT_SECOND)
    r = app.post_json("/" + uidenc + "/payments?access_token=" + tok,
                      {"token": "stripetoken",
                       "points": 500, "price": 5, "currency": "USD"},
                      status=400)
    assert slackpost.call_count == 0
    assert mock_customer_create.call_count == 0
    assert mock_charge_create.call_count == 0
    assert User.get("1878285869108664").points == 20

    assert PaymentSource.get("testfbid") is None
    assert len(Payment.get("testfbid")) == 0
    assert r.status == "400 Bad Request"
    assert "expiration" in r.json['text']
Beispiel #4
0
 def do_action(self, message, event=action.NO_SIGN_UP_IDLE_ACTION):
     uidc = uidcrypt.encryptuid(self.user.id)
     url = fb.FB_LOGIN_URL.format(
         state=tokener.gen_token(self.user.id, tokener.NS_LOGIN),
         uid=uidc)
     buttons = [
         fb.web_button(self._("LOG IN WITH FACEBOOK"), url, url, "compact")]
     self.send_btn(
         self._(
             "Please sign in with Facebook. We don't post anything to Facebook."
         ),
         buttons, event)
     self.user.version = "2.0"
Beispiel #5
0
def test_payments_invalid_token(monkeypatch):
    app = BetterTestApp(server.app)
    User.create("1878285869108664", fb_id="testfbid")
    uidenc = uidcrypt.encryptuid("1878285869108664")
    tok = tokener.gen_token("1878285869108664", tokener.NS_PAYMENT_SECOND)
    r = app.post_json(
        "/" + uidenc + "/payments?access_token=" + "invalidtoken",
        {"token": "stripetoken",
         "points": 500, "price": 5, "currency": "USD"},
        status=400)
    assert User.get("1878285869108664").points == 20

    assert PaymentSource.get("testfbid") is None
    assert len(Payment.get("testfbid")) == 0
    assert r.status == "400 Bad Request"
    assert "expiration of token" in r.json['text']
Beispiel #6
0
 def purchase_points_button(self):
     url = fb.PAYMENT_LOGIN_URL.format(
         state=tokener.gen_token(self.user.id,
                                 tokener.NS_PAYMENT),
         uid=uidcrypt.encryptuid(self.user.id))
     return fb.web_button(self._("Purchase Points"), url, url, "full")
Beispiel #7
0
 def langb(self):
     uid = uidcrypt.encryptuid(self.user.id)
     url = "{url}/{uid}/settings".format(url=config.HEROKU_URL, uid=uid)
     return fb.web_button(self._("Discovery Settings"), url, url, "tall")
Beispiel #8
0
def test_crypt():
    enc = uidcrypt.encryptuid("12345")
    assert enc != "12345"
    assert isinstance(enc, str)
    dec = uidcrypt.decryptuid(enc)
    assert dec == "12345"