def test_insert_results(mock_data_client): out_mock = mock.Mock() mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name'}} insert_results(mock_data_client, out_mock, 'g-cloud-7', 'tests/fixtures/framework_results.csv', 'user') mock_data_client.set_framework_result.assert_has_calls( [ call(123, 'g-cloud-7', True, 'user'), call(234, 'g-cloud-7', False, 'user'), call(345, 'g-cloud-7', True, 'user'), call(456, 'g-cloud-7', False, 'user'), call(678, 'g-cloud-7', True, 'user') ], any_order=False ) out_mock.write.assert_has_calls( [ call("OK: 123\n"), call("OK: 234\n"), call("OK: 345\n"), call("OK: 456\n"), call("Error: Result must be 'pass' or 'fail', not 'yes'; Bad line: 5\n"), call("Error: invalid literal for int() with base 10: 'Company Name'; Bad line: 6\n"), call("OK: 678\n") ], any_order=False )
def test_insert_results(mock_data_client): out_mock = mock.Mock() mock_data_client.get_supplier.return_value = {'suppliers': {'name': 'Supplier Name'}} insert_results(mock_data_client, out_mock, 'g-cloud-7', 'tests/fixtures/framework_results.csv', 'user') mock_data_client.set_framework_result.assert_has_calls([ call(123, 'g-cloud-7', True, 'user'), call(234, 'g-cloud-7', False, 'user'), call(345, 'g-cloud-7', True, 'user'), call(456, 'g-cloud-7', False, 'user'), call(678, 'g-cloud-7', True, 'user') ], any_order=False ) out_mock.write.assert_has_calls([ call("OK: 123\n"), call("OK: 234\n"), call("OK: 345\n"), call("OK: 456\n"), call("Error: Result must be 'pass' or 'fail', not 'yes'; Bad line: 5\n"), call("Error: invalid literal for int() with base 10: 'Company Name'; Bad line: 6\n"), call("OK: 678\n") ], any_order=False )
""" Takes a CSV file with rows in the format: Supplier ID, Supplier Name, Result e.g: 123456, Supplier name 1, pass 123212, Supplier name 2, fail 234567, Supplier name 3, pass Usage: scripts/insert-framework-results.py <framework_slug> <data_api_url> <data_api_token> <filename> """ import getpass import sys sys.path.insert(0, '.') from docopt import docopt from dmutils.apiclient import DataAPIClient from dmscripts.insert_framework_results import insert_results if __name__ == '__main__': arguments = docopt(__doc__) client = DataAPIClient(arguments['<data_api_url>'], arguments['<data_api_token>']) output = sys.stdout framework_slug = arguments['<framework_slug>'] filename = arguments['<filename>'] user = getpass.getuser() insert_results(client, output, framework_slug, filename, user)
234567, Supplier name 3, pass The supplier name is cross-referenced against the supplier name in the Digital Marketplace for that supplier ID, as a sanity check against sloppy CSV creation. If the names don't match then the script will not update the framework status. Usage: scripts/insert-framework-results.py <framework_slug> <stage> <data_api_token> <filename> [<user>] """ import getpass import sys sys.path.insert(0, '.') from docopt import docopt from dmapiclient import DataAPIClient from dmscripts.insert_framework_results import insert_results from dmutils.env_helpers import get_api_endpoint_from_stage if __name__ == '__main__': arguments = docopt(__doc__) client = DataAPIClient(get_api_endpoint_from_stage(arguments['<stage>']), arguments['<data_api_token>']) output = sys.stdout framework_slug = arguments['<framework_slug>'] filename = arguments['<filename>'] user = arguments['<user>'] or getpass.getuser() insert_results(client, output, framework_slug, filename, user)