class WordPressTest(unittest.TestCase): def setUp(self): self.blog_url = os.environ.get('WORDPRESS_BLOG_URL', 'http://localhost:8888/wordpress') self.http = httplib2.Http() self.wp = WordPress(self.blog_url, cache=None) def check_response(self, result, url): "Check that the parsed result matches the given URL" r, c = self.http.request(url) c = json.loads(c) self.assertEqual(c, result) def test_get_info(self): "Test basic info" result = self.wp.info() self.check_response(result, '%s/?dev=1&json=info' % self.blog_url) def test_get_recent_posts(self): "Test getting recent posts" result = self.wp.get_recent_posts() self.check_response(result, '%s/api/get_recent_posts/?dev=1' % self.blog_url) def test_get_post(self): """Test getting a single post""" # don't assume there's a post with ID 1 # this assumes get_recent_posts works, will raise KeyError if not results = self.wp.get_recent_posts(count=3) for post in results['posts']: ID = post['id'] post = self.wp.get_post(id=ID) self.check_response(post, '%s/?json=get_post&id=%s&dev=1' % (self.blog_url, ID)) def test_get_categories(self): """Test getting all active categories""" result = self.wp.get_category_index() self.check_response(result, '%s/?json=get_category_index&dev=1' % self.blog_url) def test_bad_method(self): """Trying to call something that isn't a real method should raise AttributeError""" # for the record, this is an odd way to test this with self.assertRaises(AttributeError): self.wp.do_something_bad
class WordPressTest(unittest.TestCase): def setUp(self): self.blog_url = "http://localhost:8888/wordpress" self.wp = WordPress(self.blog_url, cache=None) def check_response(self, result, url): "Check that the parsed result matches the given URL" r, c = http.request(url) c = json.loads(c) self.assertEqual(c, result) def test_get_info(self): "Test basic info" result = self.wp.info() self.check_response(result, 'http://localhost:8888/wordpress/?dev=1&json=info') def test_get_recent_posts(self): "Test getting recent posts" result = self.wp.get_recent_posts() self.check_response(result, 'http://localhost:8888/wordpress/api/get_recent_posts/?dev=1') def test_get_post(self): """Test getting a single post""" result = self.wp.get_post(id=1) self.check_response(result, 'http://localhost:8888/wordpress/?json=get_post&id=1&dev=1') def test_get_categories(self): """Test getting all active categories""" result = self.wp.get_category_index() self.check_response(result, 'http://localhost:8888/wordpress/?json=get_category_index&dev=1') def test_bad_method(self): """Trying to call something that isn't a real method should raise AttributeError""" # for the record, this is an odd way to test this try: self.wp.do_something_bad self.fail() except AttributeError: pass
class WordPressTest(unittest.TestCase): def setUp(self): self.blog_url = os.environ.get('WORDPRESS_BLOG_URL', 'http://localhost:8888/wordpress') self.http = httplib2.Http() self.wp = WordPress(self.blog_url, cache=None) def check_response(self, result, url): "Check that the parsed result matches the given URL" r, c = self.http.request(url) c = json.loads(c) self.assertEqual(c, result) def test_get_info(self): "Test basic info" result = self.wp.info() self.check_response(result, '%s/?dev=1&json=info' % self.blog_url) def test_get_recent_posts(self): "Test getting recent posts" result = self.wp.get_recent_posts() self.check_response(result, '%s/api/get_recent_posts/?dev=1' % self.blog_url) def test_get_post(self): """ Test getting a single post """ # don't assume there's a post with ID 1 # this assumes get_recent_posts works, will raise KeyError if not results = self.wp.get_recent_posts(count=3) for post in results['posts']: ID = post['id'] post = self.wp.get_post(id=ID) self.check_response( post, '%s/?json=get_post&id=%s&dev=1' % (self.blog_url, ID)) def test_get_categories(self): """ Test getting all active categories """ result = self.wp.get_category_index() self.check_response( result, '%s/?json=get_category_index&dev=1' % self.blog_url) def test_bad_method(self): """ Trying to call something that isn't a real method should raise AttributeError """ # for the record, this is an odd way to test this with self.assertRaises(AttributeError): self.wp.do_something_bad def test_proxy(self): """ WordPress should return the JSON version of any path. """ result = self.wp.proxy('/') self.check_response(result, '%s/?json=1' % self.blog_url)
""" News views: - blog index - individual posts - category views """ from coffin.shortcuts import render from django.conf import settings from django.core.cache import cache from django.http import Http404 from wordpress import WordPress, WordPressError wp = WordPress(settings.WORDPRESS_BLOG_URL, cache) def wp_proxy(request, **kwargs): """ Proxy request to WordPress. """ try: resp = wp.proxy(request.path) except WordPressError, e: if 'Not found' in e.args: raise Http404 else: raise # get a template name, using an index by default template = kwargs.pop('template', 'news/blog_index.html')
def setUp(self): self.wp = WordPress('http://demo.wp-api.org/')
class TestWordPress(unittest.TestCase): def setUp(self): self.wp = WordPress('http://demo.wp-api.org/') def test_get_404(self): with self.assertRaises(Exception): self.wp._get('404') def test_post_404(self): with self.assertRaises(Exception): self.wp._post('404') def test_delete_404(self): with self.assertRaises(Exception): self.wp._delete('404') def test_list_posts(self): posts = self.wp.list_posts() posts.ids() def test_list_posts_after(self): posts = self.wp.list_posts(after=datetime.datetime.now()) self.assertFalse(posts) def test_list_posts_before(self): posts = self.wp.list_posts(before=datetime.datetime.now()) self.assertTrue(posts) def test_list_posts_context(self): with self.assertRaises(ValueError): self.wp.list_posts(context='test') def test_list_posts_order(self): with self.assertRaises(ValueError): self.wp.list_posts(order='test') def test_list_posts_orderby(self): with self.assertRaises(ValueError): self.wp.list_posts(orderby='test') def test_list_posts_status(self): with self.assertRaises(ValueError): self.wp.list_posts(status='test') def test_get_post(self): post = self.wp.get_post(470) post.id self.assertTrue(post) def test_list_categories(self): categories = self.wp.list_categories() self.assertTrue(categories)
def setUp(self): self.blog_url = os.environ.get('WORDPRESS_BLOG_URL', 'http://localhost:8888/wordpress') self.http = httplib2.Http() self.wp = WordPress(self.blog_url, cache=None)
import logging import urllib2 import urlparse import pytz from dateutil.parser import parse from django.conf import settings from django.template.defaultfilters import slugify from wordpress import WordPress, WordPressError from .models import Method, Race, Incident, Victim log = logging.getLogger('colorado.apps.gundeaths') # create a wordpress object, sans cache wp = WordPress(settings.WORDPRESS_BLOG_URL, None) def load_victims(file, public=False): """ Load Victim records from an open CSV file. Expects the following case-sensitive fields: Name Full name of victim. Not always published. Published Name (optional) Alternate name for publishing. Useful for "unnamed" victims. Incident date When the incident occurred, which may not be the date of death.
def setUp(self): super(WordPressBaseTest, self).setUp() self.transport = self.mox.CreateMock(xmlrpclib.Transport) WordPress.transport = self.transport self.wp = WordPress('http://my/xmlrpc', 999, 'me', 'passwd') self.result = [{'foo': 0}, {'bar': 1}]
def setUp(self): self.blog_url = "http://localhost:8888/wordpress" self.wp = WordPress(self.blog_url, cache=None)
curindx = 0 if len(tasks) >= settings['threads']: await asyncio.gather(*tasks) tasks = [] if len(tasks) != 0: await asyncio.gather(*tasks) if __name__ == "__main__": modules = { '0': DLE(), '1': Drupal(), '2': Joomla(), '3': Magento(), '4': WordPress() } settings = loads(open('settings.json', 'r', encoding="utf-8").read()) timeout = ClientTimeout(total=settings['timeout']) module = modules[input('Modules:\n' + '0 - DLE\n' + '1 - Drupal\n' + '2 - Joomla\n' + '3 - Magento\n' + '4 - WordPress\n' + 'Select: ')] loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close()