Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 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)))
Exemplo n.º 6
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)))
Exemplo n.º 7
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 10
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)
Exemplo n.º 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])
Exemplo n.º 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)