Exemple #1
0
    def test_system(self):
        with served_api(words, 5000):

            class WordsClient(APIClient):
                base_url = 'http://127.0.0.1:5000'

            c = WordsClient()
            self.assertEqual(APISpec.to_json(c.spec), APISpec.to_json(words.spec))
Exemple #2
0
    def test_multi_thread(self):
        with served_api(words, 5002, threaded=True):

            class WordsClient(APIClient):
                base_url = 'http://127.0.0.1:5002'

            c = WordsClient()
            p = Process(target=c.actions.lock_thread, args=(1,))
            p.start()
            self.assertEqual(c.actions.count_letters((None, {"letters": "rabbit"})), 6)
            p.terminate()
Exemple #3
0
    def test_logging(self):
        with served_api(words, 5001):

            class WordsClient(ClientLoggingMixin, APIClient):
                base_url = 'http://127.0.0.1:5001'

            c = WordsClient()
            c.actions.pluralize('pencil')
            self.assertEqual(c.log[-1][0], {
                'method': 'POST',
                'data': '"pencil"',
                'headers': [('Content-Type', 'application/json')],
                'url': u'/actions/pluralize'
            })
            self.assertEqual(c.log[-1][1], {
                'status_code': 200,
                'data': u'"pencils"',
                'headers': [
                    ('Content-Length', '9'),
                    ('Content-Type', 'application/json'),
                    ('Date', Wildcard),
                    ('Server', Wildcard),
                ]
            })