예제 #1
0
파일: test_util.py 프로젝트: v1cker/bridgy
    def test_maybe_add_or_delete_source(self):
        auth_entity = FakeAuthEntity(id='x',
                                     user_json=json.dumps({
                                         'url': 'http://foo.com/',
                                         'name': UNICODE_STR
                                     }))
        auth_entity.put()
        src = self.handler.maybe_add_or_delete_source(
            FakeSource, auth_entity,
            self.handler.construct_state_param_for_add(feature='publish'))
        self.assertEquals(['publish'], src.features)

        self.assertEquals(302, self.response.status_int)
        parsed = urlparse.urlparse(self.response.headers['Location'])
        self.assertIn(
            UNICODE_STR,
            urllib.unquote_plus(str(parsed.fragment)).decode('utf-8'))
        self.assertEquals(
            'logins="/fake/%s?%s"; expires=2001-12-31 00:00:00; Path=/' %
            (src.key.id(), urllib.quote_plus(UNICODE_STR.encode('utf-8'))),
            self.response.headers['Set-Cookie'])

        for feature in None, '':
            src = self.handler.maybe_add_or_delete_source(
                FakeSource, auth_entity,
                self.handler.construct_state_param_for_add(feature))
            self.assertEquals([], src.features)
예제 #2
0
파일: test_util.py 프로젝트: snarfed/bridgy
  def test_maybe_add_or_delete_without_web_site_redirects_to_edit_websites(self):
    for bad_url in None, 'not>a<url', 'http://fa.ke/xyz':
      auth_entity = FakeAuthEntity(id='x', user_json=json.dumps({'url': bad_url}))
      auth_entity.put()
      source = self.handler.maybe_add_or_delete_source(FakeSource, auth_entity, '{}')

      self.assertEquals(302, self.handler.response.status_code)
      self.assert_equals(
        'http://localhost/edit-websites?source_key=%s' % source.key.urlsafe(),
        self.handler.response.headers['Location'])
예제 #3
0
    def test_add_to_logins_cookie(self):
        listen = self.handler.construct_state_param_for_add(feature="listen")
        auth_entity = FakeAuthEntity(id="x", user_json="{}")
        auth_entity.put()

        self.request.headers["Cookie"] = "logins=/other/1?bob"
        src1 = self.handler.maybe_add_or_delete_source(FakeSource, auth_entity, listen)
        cookie = 'logins="/fake/%s?fake|/other/1?bob"; expires=2001-12-31 00:00:00; Path=/'
        self.assertEquals(cookie % src1.key.id(), self.response.headers["Set-Cookie"])

        src2 = self.handler.maybe_add_or_delete_source(FakeSource, auth_entity, listen)
        self.request.headers["Cookie"] = 'logins="/fake/%s?fake|/other/1?bob"' % src2.key.id()
        self.assertEquals(cookie % src2.key.id(), self.response.headers["Set-Cookie"])
예제 #4
0
파일: test_util.py 프로젝트: v1cker/bridgy
    def test_maybe_add_or_delete_without_web_site_redirects_to_edit_websites(
            self):
        for bad_url in None, 'not>a<url', 'http://fa.ke/xyz':
            auth_entity = FakeAuthEntity(id='x',
                                         user_json=json.dumps({'url':
                                                               bad_url}))
            auth_entity.put()
            source = self.handler.maybe_add_or_delete_source(
                FakeSource, auth_entity, '{}')

            self.assertEquals(302, self.handler.response.status_code)
            self.assert_equals(
                'http://localhost/edit-websites?source_key=%s' %
                source.key.urlsafe(),
                self.handler.response.headers['Location'])
예제 #5
0
    def test_add_to_logins_cookie(self):
        listen = self.handler.construct_state_param_for_add(feature='listen')
        auth_entity = FakeAuthEntity(id='x', user_json='{}')
        auth_entity.put()

        self.request.headers['Cookie'] = 'logins=/other/1?bob'
        src1 = self.handler.maybe_add_or_delete_source(FakeSource, auth_entity,
                                                       listen)
        cookie = 'logins="/fake/%s?fake|/other/1?bob"; expires=2001-12-31 00:00:00; Path=/'
        self.assertEquals(cookie % src1.key.id(),
                          self.response.headers['Set-Cookie'])

        src2 = self.handler.maybe_add_or_delete_source(FakeSource, auth_entity,
                                                       listen)
        self.request.headers['Cookie'] = \
          'logins="/fake/%s?fake|/other/1?bob"' % src2.key.id()
        self.assertEquals(cookie % src2.key.id(),
                          self.response.headers['Set-Cookie'])
예제 #6
0
  def test_maybe_add_or_delete_source(self):
    # profile url with valid domain is required for publish
    for bad_url in None, 'not>a<url', 'http://fa.ke/xyz':
      auth_entity = FakeAuthEntity(id='x', user_json=json.dumps({'url': bad_url}))
      auth_entity.put()
      self.assertIsNone(self.handler.maybe_add_or_delete_source(
        FakeSource, auth_entity,
        self.handler.construct_state_param_for_add(feature='publish')))

    auth_entity = FakeAuthEntity(id='x', user_json=json.dumps(
        {'url': 'http://foo.com/', 'name': UNICODE_STR}))
    auth_entity.put()
    src = self.handler.maybe_add_or_delete_source(
      FakeSource, auth_entity,
      self.handler.construct_state_param_for_add(feature='publish'))
    self.assertEquals(['publish'], src.features)

    self.assertEquals(302, self.handler.response.status_int)
    parsed = urlparse.urlparse(self.handler.response.headers['Location'])
    self.assertIn(UNICODE_STR, urllib.unquote_plus(parsed.fragment).decode('utf-8'))

    for feature in None, '':
      src = self.handler.maybe_add_or_delete_source(
        FakeSource, auth_entity,
        self.handler.construct_state_param_for_add(feature))
      self.assertEquals([], src.features)
예제 #7
0
    def test_maybe_add_or_delete_source(self):
        # profile url with valid domain is required for publish
        for bad_url in None, "not>a<url", "http://fa.ke/xyz":
            auth_entity = FakeAuthEntity(id="x", user_json=json.dumps({"url": bad_url}))
            auth_entity.put()
            self.assertIsNone(
                self.handler.maybe_add_or_delete_source(
                    FakeSource, auth_entity, self.handler.construct_state_param_for_add(feature="publish")
                )
            )

        auth_entity = FakeAuthEntity(id="x", user_json=json.dumps({"url": "http://foo.com/", "name": UNICODE_STR}))
        auth_entity.put()
        src = self.handler.maybe_add_or_delete_source(
            FakeSource, auth_entity, self.handler.construct_state_param_for_add(feature="publish")
        )
        self.assertEquals(["publish"], src.features)

        self.assertEquals(302, self.response.status_int)
        parsed = urlparse.urlparse(self.response.headers["Location"])
        self.assertIn(UNICODE_STR, urllib.unquote_plus(parsed.fragment).decode("utf-8"))
        self.assertEquals(
            'logins="/fake/%s?%s"; expires=2001-12-31 00:00:00; Path=/'
            % (src.key.id(), urllib.quote_plus(UNICODE_STR.encode("utf-8"))),
            self.response.headers["Set-Cookie"],
        )

        for feature in None, "":
            src = self.handler.maybe_add_or_delete_source(
                FakeSource, auth_entity, self.handler.construct_state_param_for_add(feature)
            )
            self.assertEquals([], src.features)
예제 #8
0
파일: test_util.py 프로젝트: snarfed/bridgy
  def test_maybe_add_or_delete_source(self):
    auth_entity = FakeAuthEntity(id='x', user_json=json.dumps(
        {'url': 'http://foo.com/', 'name': UNICODE_STR}))
    auth_entity.put()
    src = self.handler.maybe_add_or_delete_source(
      FakeSource, auth_entity,
      self.handler.construct_state_param_for_add(feature='publish'))
    self.assertEquals(['publish'], src.features)

    self.assertEquals(302, self.response.status_int)
    parsed = urlparse.urlparse(self.response.headers['Location'])
    self.assertIn(UNICODE_STR,
                  urllib.unquote_plus(str(parsed.fragment)).decode('utf-8'))
    self.assertEquals(
      'logins="/fake/%s?%s"; expires=2001-12-31 00:00:00; Path=/' %
        (src.key.id(), urllib.quote_plus(UNICODE_STR.encode('utf-8'))),
      self.response.headers['Set-Cookie'])

    for feature in None, '':
      src = self.handler.maybe_add_or_delete_source(
        FakeSource, auth_entity,
        self.handler.construct_state_param_for_add(feature))
      self.assertEquals([], src.features)
예제 #9
0
 def test_maybe_add_or_delete_source_bad_state(self):
     auth_entity = FakeAuthEntity(id='x', user_json='{}')
     auth_entity.put()
     with self.assertRaises(exc.HTTPBadRequest):
         self.handler.maybe_add_or_delete_source(FakeSource, auth_entity,
                                                 'bad')
예제 #10
0
 def test_maybe_add_or_delete_source_bad_state(self):
   auth_entity = FakeAuthEntity(id='x', user_json='{}')
   auth_entity.put()
   with self.assertRaises(exc.HTTPBadRequest):
     self.handler.maybe_add_or_delete_source(FakeSource, auth_entity, 'bad')