Example #1
0
 def test_with_context_when_error(self):
     settings.TEST = 'first'
     try:
         with setting('TEST', 'second'):
             self.assertEqual('second', settings.TEST)
             raise ValueError('Test error')
     except ValueError:
         self.assertEqual('first', settings.TEST)
Example #2
0
    def test_restrict_by_ip_fail(self):
        payload = {}
        auth = generate_test_authorization(json.dumps(payload))

        self._create_node(auth['public_address'])

        ips = [
            '1.1.1.1',
            '2.2.2.2',
        ]
        with setting('RESTRICT_BY_IP_ENABLED', True), \
                setting('ALLOWED_IP_ADDRESSES', ips):
            re = self._post('/v1/ping_proposal',
                            payload,
                            headers=auth['headers'])

        self.assertEqual(403, re.status_code)
        self.assertEqual({'error': 'resource is forbidden'}, re.json)
Example #3
0
 def test_with_context_when_successful(self):
     settings.TEST = 'first'
     with setting('TEST', 'second'):
         self.assertEqual('second', settings.TEST)
     self.assertEqual('first', settings.TEST)