示例#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))
示例#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))
示例#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
示例#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
示例#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
示例#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)
示例#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)
示例#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')
示例#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')
示例#10
0
 async def test_default(self, loop):
     async with API(SPEC, loop=loop) as api:
         with coserver():
             await api.getDefault()
示例#11
0
 def test_bad_status(self):
     with coserver():
         api = API('http://localhost:8888/api.yaml', verbose=True)
         self.assertRaises(AssertionError, api.getBadStatus)
示例#12
0
    def test_default(self):
        api = API(SPEC)

        with coserver():
            api.getDefault()