コード例 #1
0
    def test_hashed_url_for_only_runs_for_static_asset_routes(self):
        # with app.test_request_context('/'):
        #     output = render_template_string("{{ url_for('index.index_page') }}")
        with app.test_request_context('/worklist'):
            output = render_template_string(
                "{{ url_for('verification.get_worklist') }}")

        self.assertNotIn('?cache', output)
コード例 #2
0
 def test_get_verification_api(self):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             verification_api = VerificationAPI()
             resp_data = verification_api.get_worklist()
             self.assertIsNotNone(resp_data)
コード例 #3
0
    def test_url_for_adds_cache_query_string(self):
        filename = 'verification_ui/assets/dist/test.txt'
        with open(filename, 'w+') as file:
            file.write('Hello')

        with app.test_request_context('/'):
            output = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")

        md5_value = md5_for_file(filename, hexdigest=True)

        self.assertIn('?cache={}'.format(md5_value), output)

        os.remove(filename)
コード例 #4
0
    def test_repeated_url_for_calls_hits_cache_not_disk(
            self, mock_md5_for_file):
        filename = 'verification_ui/assets/dist/test.txt'
        with open(filename, 'w+') as file:
            file.write('Hello')

        with app.test_request_context('/'):
            hash_one = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")
            hash_two = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")
            hash_three = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")

            self.assertEqual(mock_md5_for_file.call_count, 1)

        self.assertEqual(hash_one, hash_two)
        self.assertEqual(hash_two, hash_three)

        os.remove(filename)
コード例 #5
0
def create_personal_worklist_item():
    with app.app_context() as ac:
        ac.g.requests = requests.Session()
        base_url = current_app.config['VERIFICATION_API_URL']
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json"
        }

        with app.test_request_context():
            post_url = "{}/case".format(base_url)
            post_response = g.requests.post(post_url,
                                            data=personal_item_json,
                                            headers=headers)
            data = post_response.json()
            item_id = data['case_id']

            get_url = '{}/case/{}'.format(base_url, item_id)
            get_response = g.requests.get(get_url, headers=headers)
            return get_response.json()
 def run_with_context(*args, **kwargs):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             return func(*args, **kwargs)
    def request(self, **kwargs):
        self.ctx = app.test_request_context('/', **kwargs)
        self.ctx.push()

        self.form = ExampleForm()
        self.form.validate_on_submit()
    def test_build_personal_worklist_item_info(self, mock_name, mock_address,
                                               mock_acc_type):
        mock_name.return_value = 'Mr Test User'
        mock_address.return_value = '1 Test Street<br>Testyton<br>TE5 T3R5<br>UK<br>'
        mock_acc_type.return_value = 'UK Personal'
        phone_no = self.test_personal_item['registration_data'][
            'telephone_number']
        email = self.test_personal_item['registration_data']['email']
        status = 'Pending'

        with app.test_request_context():
            worklist_item_info = build_details_table(self.test_personal_item)
            self.assertEqual(worklist_item_info, [{
                'key': {
                    'text': 'Full Name'
                },
                'value': {
                    'text': 'Mr Test User'
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Status'
                },
                'value': {
                    'html': format_status(status)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Address'
                },
                'value': {
                    'html': '1 Test Street<br>Testyton<br>TE5 T3R5<br>UK<br>'
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Telephone Number'
                },
                'value': {
                    'text': phone_no
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Email'
                },
                'value': {
                    'text': email
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Contactable'
                },
                'value': {
                    'html': format_contactable(self.test_personal_item)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Contact by'
                },
                'value': {
                    'html': format_contact_by(self.test_personal_item)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Account Type'
                },
                'value': {
                    'text': 'UK Personal'
                },
                'actions': {
                    'items': []
                }
            }])
    def test_build_overseas_org_worklist_item_info(self, mock_name,
                                                   mock_address,
                                                   mock_acc_type):
        mock_name.return_value = 'Madame Testy Userre'
        mock_address.return_value = '1 Rue de Test<br>Testyville<br>75001<br>'
        mock_acc_type.return_value = 'Overseas Organisation'
        phone_no = self.test_overseas_org_item['registration_data'][
            'telephone_number']
        email = self.test_overseas_org_item['registration_data']['email']
        org_name = self.test_overseas_org_item['registration_data'][
            'organisation_name']
        country_incorp = self.test_overseas_org_item['registration_data'][
            'country_of_incorporation']
        status = 'Pending'

        with app.test_request_context():
            worklist_item_info = build_details_table(
                self.test_overseas_org_item)
            self.assertEqual(worklist_item_info, [{
                'key': {
                    'text': 'Full Name'
                },
                'value': {
                    'text': 'Madame Testy Userre'
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Status'
                },
                'value': {
                    'html': format_status(status)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Address'
                },
                'value': {
                    'html': '1 Rue de Test<br>Testyville<br>75001<br>'
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Telephone Number'
                },
                'value': {
                    'text': phone_no
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Email'
                },
                'value': {
                    'text': email
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Contactable'
                },
                'value': {
                    'html': format_contactable(self.test_overseas_org_item)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Contact by'
                },
                'value': {
                    'html': format_contact_by(self.test_overseas_org_item)
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Account Type'
                },
                'value': {
                    'text': 'Overseas Organisation'
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Organisation Name'
                },
                'value': {
                    'text': org_name
                },
                'actions': {
                    'items': []
                }
            }, {
                'key': {
                    'text': 'Country of Incorporation'
                },
                'value': {
                    'text': country_incorp
                },
                'actions': {
                    'items': []
                }
            }])
コード例 #10
0
    def test_populate_username(self):
        test_username = '******'
        with app.test_request_context():
            result = verification.get_user_name()

        self.assertEqual(result, test_username)
コード例 #11
0
 def check_rendering(self, markdown_to_html):
     for markdown in markdown_to_html:
         with app.test_request_context('/'):
             assert render_template_string('{{contents|markdown}}',
                                           contents=markdown).strip() == markdown_to_html.get(markdown)
    def test_gzip_cache_key_format(self):
        with app.test_request_context('/foo?cachebuster=123'):
            response = mock.MagicMock(headers=Headers([('ETag', 'bar')]))
            key = gzip_cache_key(response)

        self.assertEqual(key, '/foobar')