コード例 #1
0
  def test_site_lookup_fails(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      'my resp body', status=402)
    self.mox.ReplayAll()

    with self.assertRaises(urllib.error.HTTPError):
      WordPress.new(auth_entity=self.auth_entity)
コード例 #2
0
  def test_new_site_domain_same_gr_blog_url(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      json.dumps({'ID': 123, 'URL': 'http://my.wp.com/'}))
    self.mox.ReplayAll()

    w = WordPress.new(self.handler, auth_entity=self.auth_entity)
    self.assertEquals(['http://my.wp.com/'], w.domain_urls)
    self.assertEquals(['my.wp.com'], w.domains)
コード例 #3
0
ファイル: test_wordpress_rest.py プロジェクト: snarfed/bridgy
  def test_new_site_domain_same_gr_blog_url(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      json.dumps({'ID': 123, 'URL': 'http://my.wp.com/'}))
    self.mox.ReplayAll()

    w = WordPress.new(self.handler, auth_entity=self.auth_entity)
    self.assertEquals(['http://my.wp.com/'], w.domain_urls)
    self.assertEquals(['my.wp.com'], w.domains)
コード例 #4
0
ファイル: test_wordpress_rest.py プロジェクト: tantek/bridgy
    def test_new_site_domain_same_gr_blog_url(self):
        self.expect_urlopen(
            "https://public-api.wordpress.com/rest/v1/sites/123?pretty=true",
            json.dumps({"ID": 123, "URL": "http://my.wp.com/"}),
        )
        self.mox.ReplayAll()

        w = WordPress.new(self.handler, auth_entity=self.auth_entity)
        self.assertEquals(["http://my.wp.com/"], w.domain_urls)
        self.assertEquals(["my.wp.com"], w.domains)
コード例 #5
0
  def test_site_lookup_api_disabled_error_start(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      '{"error": "unauthorized",'
      ' "message": "API calls to this blog have been disabled."}',
      status=403)
    self.mox.ReplayAll()

    self.assertIsNone(WordPress.new(self.handler, auth_entity=self.auth_entity))
    self.assertIsNone(WordPress.query().get())
    self.assertIn('enable the Jetpack JSON API', next(iter(self.handler.messages)))
コード例 #6
0
ファイル: test_wordpress_rest.py プロジェクト: snarfed/bridgy
  def test_site_lookup_api_disabled_error_start(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      '{"error": "unauthorized",'
      ' "message": "API calls to this blog have been disabled."}',
      status=403)
    self.mox.ReplayAll()

    self.assertIsNone(WordPress.new(self.handler, auth_entity=self.auth_entity))
    self.assertIsNone(WordPress.query().get())
    self.assertIn('enable the Jetpack JSON API', next(iter(self.handler.messages)))
コード例 #7
0
ファイル: test_wordpress_rest.py プロジェクト: tantek/bridgy
    def test_new(self):
        self.expect_urlopen("https://public-api.wordpress.com/rest/v1/sites/123?pretty=true", json.dumps({}))
        self.mox.ReplayAll()

        w = WordPress.new(self.handler, auth_entity=self.auth_entity)
        self.assertEquals(self.auth_entity.key, w.auth_entity)
        self.assertEquals("my.wp.com", w.key.id())
        self.assertEquals("Ryan", w.name)
        self.assertEquals(["http://my.wp.com/"], w.domain_urls)
        self.assertEquals(["my.wp.com"], w.domains)
        self.assertEquals("http://ava/tar", w.picture)
コード例 #8
0
  def test_new_with_site_domain(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      json.dumps({'ID': 123, 'URL': 'https://vanity.domain/'}))
    self.mox.ReplayAll()

    w = WordPress.new(self.handler, auth_entity=self.auth_entity)
    self.assertEquals('vanity.domain', w.key.id())
    self.assertEquals('https://vanity.domain/', w.url)
    self.assertEquals(['https://vanity.domain/', 'http://my.wp.com/'],
                      w.domain_urls)
    self.assertEquals(['vanity.domain', 'my.wp.com'], w.domains)
コード例 #9
0
  def test_new_with_site_domain(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      json.dumps({'ID': 123, 'URL': 'https://vanity.domain/'}))
    self.mox.ReplayAll()

    w = WordPress.new(self.handler, auth_entity=self.auth_entity)
    self.assertEquals('vanity.domain', w.key.id())
    self.assertEquals('https://vanity.domain/', w.url)
    self.assertEquals(['https://vanity.domain/', 'http://my.wp.com/'],
                      w.domain_urls)
    self.assertEquals(['vanity.domain', 'my.wp.com'], w.domains)
コード例 #10
0
ファイル: test_wordpress_rest.py プロジェクト: tantek/bridgy
    def test_new_with_site_domain(self):
        self.expect_urlopen(
            "https://public-api.wordpress.com/rest/v1/sites/123?pretty=true",
            json.dumps({"ID": 123, "URL": "https://vanity.domain/"}),
        )
        self.mox.ReplayAll()

        w = WordPress.new(self.handler, auth_entity=self.auth_entity)
        self.assertEquals("vanity.domain", w.key.id())
        self.assertEquals("https://vanity.domain/", w.url)
        self.assertEquals(["https://vanity.domain/", "http://my.wp.com/"], w.domain_urls)
        self.assertEquals(["vanity.domain", "my.wp.com"], w.domains)
コード例 #11
0
  def test_site_lookup_api_disabled_error_start(self):
    self.expect_urlopen(
      'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
      '{"error": "unauthorized", "message": "API calls to this blog have been disabled."}',
      status=403)
    self.mox.ReplayAll()

    with app.test_request_context():
      with self.assertRaises(RequestRedirect):
        self.assertIsNone(WordPress.new(auth_entity=self.auth_entity))
      self.assertIsNone(WordPress.query().get())
      self.assertIn('enable the Jetpack JSON API', get_flashed_messages()[0])
コード例 #12
0
    def test_new(self):
        self.expect_urlopen(
            'https://public-api.wordpress.com/rest/v1/sites/123?pretty=true',
            json_dumps({}))
        self.mox.ReplayAll()

        w = WordPress.new(self.handler, auth_entity=self.auth_entity)
        self.assertEquals(self.auth_entity.key, w.auth_entity)
        self.assertEquals('my.wp.com', w.key.id())
        self.assertEquals('Ryan', w.name)
        self.assertEquals(['http://my.wp.com/'], w.domain_urls)
        self.assertEquals(['my.wp.com'], w.domains)
        self.assertEquals('http://ava/tar', w.picture)