Exemplo n.º 1
0
    async def test_names(self, loop):
        async with API(SPEC, verbose=True, loop=loop) as api:
            with coserver():
                await api.getHeartbeat()

            for attr in ('getHeartbeat', 'addUserToCohort',
                         'returnCohortSettings'):
                self.assertTrue(hasattr(api, attr))
Exemplo n.º 2
0
    def test_names(self):
        api = API(SPEC, verbose=True)

        with coserver():
            api.getHeartbeat()

        for attr in ('getHeartbeat', 'addUserToCohort',
                     'returnCohortSettings'):
            self.assertTrue(hasattr(api, attr))
Exemplo n.º 3
0
 async def test_bad_status(self, loop):
     with coserver():
         async with API('http://localhost:8888/api.yaml',
                        verbose=True,
                        loop=loop) as api:
             try:
                 await api.getBadStatus()
                 raise AssertionError("WAT")
             except AssertionError:
                 pass
Exemplo n.º 4
0
 async def test_bad_status2(self, loop):
     with coserver():
         async with API('http://localhost:8888/api.yaml',
                        verbose=True,
                        loop=loop) as api:
             try:
                 await api.getHeartbeat(response={'status': 209})
                 raise AssertionError("WAT")
             except AssertionError:
                 pass
Exemplo n.º 5
0
    async def test_bad_headers(self, loop):
        headers = {'Content-Type': 'nevergonnahappen'}

        with coserver():
            async with API('http://localhost:8888/api.yaml',
                           verbose=True,
                           loop=loop) as api:
                try:
                    await api.getHeartbeat(response={'headers': headers})
                    raise AssertionError("WAT")
                except AssertionError:
                    pass
Exemplo n.º 6
0
    def test_scenario(self):
        options = ('smwogger', '--test', _SCENARIO,
                   'http://localhost:8888/api.json')

        with coserver(), set_args(*options) as out:
            try:
                main()
            except SystemExit:
                pass

        stdout = out[0].read().strip()
        self.assertEqual(stdout, WANTED2)
Exemplo n.º 7
0
    def test_main(self):

        options = 'smwogger', 'http://localhost:8888/api.json', '--verbose'

        with coserver(), set_args(*options) as out:
            try:
                main()
            except SystemExit:
                pass

        stdout = out[0].read().strip()
        self.assertEqual(stdout, WANTED)
        stderr = out[1].read().strip()
        self.assertTrue("Content-Type: application/json" in stderr)
Exemplo n.º 8
0
    def test_read_spec_from_url(self):
        headers = {'Something': 'here'}

        with coserver():
            api = API('http://localhost:8888/api.yaml', verbose=True)
            api.getDefault()

            api = API('http://localhost:8888/api.json', verbose=True)
            api.getDefault()

            res = api.getHeartbeat(request={'headers': headers})

        echoed_headers = res.json()['headers']
        self.assertEqual(echoed_headers['Something'], 'here')
Exemplo n.º 9
0
    async def test_read_spec_from_url(self, loop):
        headers = {'Something': 'here'}

        with coserver():
            async with API('http://localhost:8888/api.yaml',
                           verbose=True,
                           loop=loop) as api:
                await api.getDefault()

            async with API('http://localhost:8888/api.json',
                           verbose=True,
                           loop=loop) as api:
                await api.getDefault()
                res = await api.getHeartbeat(request={'headers': headers})

        data = await res.json()
        echoed_headers = data['headers']
        self.assertEqual(echoed_headers['Something'], 'here')
Exemplo n.º 10
0
 async def test_default(self, loop):
     async with API(SPEC, loop=loop) as api:
         with coserver():
             await api.getDefault()
Exemplo n.º 11
0
 def test_bad_status(self):
     with coserver():
         api = API('http://localhost:8888/api.yaml', verbose=True)
         self.assertRaises(AssertionError, api.getBadStatus)
Exemplo n.º 12
0
    def test_default(self):
        api = API(SPEC)

        with coserver():
            api.getDefault()