Ejemplo n.º 1
0
    def test_get_resource_repr(self):
        resources = GenericResourceIterable(None, {
            'resource_count': 21,
            'currentPage': 1,
        })
        Client.configure(page_size=20)
        self.assertEquals(str(resources), '<Page 1 of 2>')

        resources_2 = GenericResourceIterable(None, {})
        self.assertEquals(str(resources_2), '<Page 0 of 0>')
Ejemplo n.º 2
0
    def test_should_list_resources(self):
        response_body_1 = {
            'id': '1',
            'slug': '1/resource-slug',
        }
        response_body_2 = {
            'id': '1',
            'slug': '1/resource-slug',
            'pagination': {
                'next': {
                    'page': 1,
                    'active': False,
                }
            },
            'currentPage': 1,
            'resource_count': 30,
        }

        httpretty.register_uri(
            httpretty.GET,
            'http://localhost:4567/api/resource/id/1',
            body=json.dumps(response_body_1),
            status=200, content_type='application/json'
        )
        httpretty.register_uri(
            httpretty.GET,
            'http://localhost:4567/api/resource/1/resource-slug',
            body=json.dumps(response_body_2),
            status=200, content_type='application/json'
        )

        Client.configure(page_size=20)
        status_code, resources = self.resources.list(1)
        self.assertEquals(status_code, 200)
        self.assertEquals(resources.current_page, 1)
        self.assertEquals(resources.num_pages, 2)
Ejemplo n.º 3
0
    def test_get_page_err(self):
        client = Client('http://localhost:4567', 'master_token123')
        resources = GenericResourceIterable(client.http_client, {
            'resource_count': 21,
            'currentPage': 1,
            'slug': '1/resource-slug',
        })

        page_number = 2
        endpoint = 'http://localhost:4567/api/resource/1/resource-slug?page=%d' % page_number
        httpretty.register_uri(
            httpretty.GET, endpoint,
            body='{"code":"bad-request","message":"..."}',
            status=408, content_type='application/json'
        )
        self.assertRaises(InvalidPage, resources.page, page_number)
Ejemplo n.º 4
0
    def test_num_pages(self):
        resources = GenericResourceIterable(None, {
            'resource_count': 21,
        })
        Client.configure(page_size=20)
        self.assertEquals(resources.num_pages, 2)

        Client.configure(page_size=10)
        self.assertEquals(resources.num_pages, 3)

        Client.configure(page_size=30)
        self.assertEquals(resources.num_pages, 1)
Ejemplo n.º 5
0
    def test_next_http_error(self):
        client = Client('http://localhost:4567', 'master_token123')
        resources = GenericResourceIterable(client.http_client, {
            'resources': [1, 2, 3, 4, 5],
            'pagination': {
                'next': {
                    'active': True,
                    'qs': 'page=2',
                },
            },
            'slug': '1/resource-slug',
        })

        # 2nd page of resource items (NodeBB pagination) - timeout.
        endpoint = 'http://localhost:4567/api/resource/1/resource-slug?page=2'
        httpretty.register_uri(
            httpretty.GET, endpoint,
            body='{"code":"bad-request","message":"..."}',
            status=408, content_type='application/json'
        )
        self.assertEquals(len([r for r in resources]), 5)
Ejemplo n.º 6
0
 def setUp(self):
     self.client = Client('http://localhost:4567', 'master_token123')
     self.resources = GenericResource(self.client.http_client)
Ejemplo n.º 7
0
 def test_client_configure_force(self):
     Client.configure(master_token=None, force=True)
     self.assertIsNone(settings['master_token'])
Ejemplo n.º 8
0
 def test_client_configure(self):
     Client.configure(master_token='abc123', force=True)
     self.assertEquals(settings['master_token'], 'abc123')
Ejemplo n.º 9
0
 def test_should_set_bearer_headers(self):
     client = Client('http://localhost:4567', 'master_tokenxxx')
     self.assertEquals(client.http_client.headers,
                       {'Authorization': 'Bearer %s' % 'master_tokenxxx'})
Ejemplo n.º 10
0
 def test_should_set_default_admin_uid(self):
     client = Client('http://localhost:4567', 'master_tokenxxx')
     self.assertEquals(client.http_client.admin_uid, settings['admin_uid'])
Ejemplo n.º 11
0
 def setUp(self):
     self.client = Client('http://localhost:4567', 'master_token123')
Ejemplo n.º 12
0
from __future__ import print_function
from pynodebb import Client
from token import *
import pyotherside

client = Client('https://sailfishos.club', token)
client.configure(**{'page_size': 20})


def login(user, password):
    status_code, userInfo = client.users.login(user, password)
    if not status_code:
        return False
    return userInfo


def post(title, content, uid, cid):
    status_code, response = client.topics.create(uid, cid, title, content)
    if not status_code or status_code != 200:
        return False
    return True


def getrecent():
    status_code, topics = client.topics.get_recent()


def listcategory():
    status_code, categories = client.categories.list()
    for category in categories:
        print(category["cid"], category["name"])
Ejemplo n.º 13
0
 def test_client_configure_force(self):
     Client.configure(master_token=None, force=True)
     self.assertIsNone(settings['master_token'])
Ejemplo n.º 14
0
 def test_client_configure(self):
     Client.configure(master_token='abc123', force=True)
     self.assertEquals(settings['master_token'], 'abc123')