示例#1
0
 def setUp(self):
     self.api = API(mode='test', auto_login=False)
     responses.add(
         responses.POST, self.get_api_url('API/fundingList/'),
         body=self.load_xml_response('200_funding_list_page_0.xml'),
         status=200, content_type='application/xml')
     self.funding_list = FundingList(api=self.api)
示例#2
0
 def setUp(self):
     self.api = API(mode='test', auto_login=False)
     self.response_as_str = self.load_xml_response(
         '200_callback_multiple.xml')
     self.response_as_etree = ElementTree.XML(self.response_as_str)
     self.response_single_as_str = self.load_xml_response(
         '200_callback_single.xml')
示例#3
0
 def setUp(self):
     self.api = API(mode='test', auto_login=False)
     url = '{}?id={}&from_date={}&to_date={}'.format(
         self.get_api_url('API/getCustomReport'),
         'ABCDEF',
         '2016-01-01',
         '2016-01-05')
     # Use the standard funding file response, any CSV could go here
     responses.add(
         responses.GET, url,
         body=self.load_xml_response('200_funding.csv'),
         status=200, content_type='text/plain',
         match_querystring=True)
     self.report = CustomReport(
         'ABCDEF', self.api, from_date='2016-01-01', to_date='2016-01-05')
示例#4
0
    def test_login_successful(self):
        "Mocks a login response to be successful to test authentication state"
        responses.add(responses.POST,
                      self.get_api_url('API/login'),
                      body=self.load_xml_response('200_login.xml'),
                      status=200,
                      content_type='application/xml')
        api = API(mode='test',
                  account='test',
                  password='******',
                  auto_login=False)
        # Before login is called state should be not authenticated
        self.assertEqual(api._is_authenticated, False)
        api.login()
        # State should be authenticated after the login
        self.assertEqual(api._is_authenticated, True)

        # Use a response callback to assert whether or not login attempts
        # to log in again even if the object is already in an authenticated
        # state. This is done by setting a state in thread locals, if we ever
        # reach this point in the code. Bit of a hack.
        def http_callback(request):
            content = self.load_xml_response('200_login.xml')
            headers = {
                'content-type': 'application/xml',
            }
            DATA.callback_reached = True
            return (200, headers, content)

        responses.reset()
        responses.add_callback(responses.POST,
                               self.get_api_url('API/login'),
                               callback=http_callback,
                               content_type='application/xml')
        api.login()
        self.assertEqual(getattr(DATA, 'callback_reached', None), None)
示例#5
0
 def setUp(self):
     self.api = API(mode='test', auto_login=False)
示例#6
0
 def test_production_shop_name(self):
     api = API(auto_login=False, mode='production', shop_name='test-shop')
     self.assertIn('test-shop', api.url)
示例#7
0
 def test_production_missing_shop_name(self):
     with self.assertRaises(exceptions.APIError):
         API(auto_login=False, mode='production')
示例#8
0
 def test_missing_url(self):
     with self.assertRaises(exceptions.APIError):
         API(auto_login=False, mode='notworking')
示例#9
0
 def test_auto_login(self):
     with self.assertRaises(exceptions.UnauthorizedAccessError):
         API()