def test_make_doc(self): build_info = make_build_info() test = {'date': '1'} job_name = 'cwr-test' artifacts = ['foo', 'bar'] svg_path = 'path/to/svg' key = FakeKey(name='foo') doc = import_data.make_doc(build_info, test, job_name, key, artifacts, svg_path) expected = { 'bundle_name': 'git', 'test_plan': 'git.yaml', 'bundle_file': 'bundle.yaml', 'callback_url': '', 'parent_build': '', 'model': 'default-aws default-joyent', 'build_info': build_info, 'test': test, 'date': test['date'], 'job_name': 'cwr-test', 'etag': key.etag, 'artifacts': artifacts, 'svg_path': 'path/to/svg', } self.assertEqual(doc, expected)
def test_make_doc(self): build_info = make_build_info() test = {'date': '1', 'test_id': '1234'} job_name = 'cwr-test' artifacts = ['foo', 'bar'] svg_path = 'path/to/svg' html_path = 'example.com/html' json_path = 'exaple.com/json' key = FakeKey(name='foo') doc = import_data.make_doc( build_info, test, job_name, key, artifacts, svg_path, html_path, json_path) expected = { 'bundle_name': 'git', 'test_plan': 'git.yaml', 'bundle_file': 'bundle.yaml', 'callback_url': '', 'parent_build': '', 'model': 'default-aws default-joyent', 'build_info': build_info, 'test': test, 'date': test['date'], 'job_name': 'cwr-test', 'etag': key.etag, 'artifacts': artifacts, 'svg_path': 'path/to/svg', 'test_id': '1234', 'html_path': html_path, 'json_path': json_path, } self.assertEqual(doc, expected)
def test_get_parameters(self): build_info = make_build_info() output = import_data.get_parameters({"actions": build_info['actions']}) expected = { 'test_plan': 'git.yaml', 'parent_build': '', 'bundle_name': 'git', 'bundle_file': 'bundle.yaml', 'callback_url': '', 'model': 'default-aws default-joyent'} self.assertEqual(output, expected)
def test_get_artifacts(self): expected = [ "git-result.json", "git-result.svg" ] build_info = make_build_info() output = import_data.get_artifacts(build_info) self.assertItemsEqual(output, expected)
def test_doc_needs_update_returns_false(self): build_info = make_build_info() test = {'date': '1'} job_name = 'cwr-test' key = FakeKey(name='cwr/cwr-test/1/1234-result-results.json') doc = import_data.make_doc(build_info, test, job_name, key, None, None) self.ds.db.cwr.update( {'_id': import_data._get_id(key)}, doc, upsert=True) needs_update = import_data.doc_needs_update(key) self.assertFalse(needs_update)
def test_doc_needs_update_returns_false(self): build_info = make_build_info() test = {'date': '1'} job_name = 'cwr-test' key = FakeKey(name='cwr/cwr-test/1/1234-result-results.json') doc = import_data.make_doc(build_info, test, job_name, key, None, None) self.ds.db.cwr.update({'_id': import_data._get_id(key)}, doc, upsert=True) needs_update = import_data.doc_needs_update(key) self.assertFalse(needs_update)
def test_get_parameters(self): build_info = make_build_info() output = import_data.get_parameters({"actions": build_info['actions']}) expected = { 'test_plan': 'git.yaml', 'parent_build': '', 'bundle_name': 'git', 'bundle_file': 'bundle.yaml', 'callback_url': '', 'model': 'default-aws default-joyent' } self.assertEqual(output, expected)
def test_from_s3(self): cred = ('fake_user', 'fake_pass') s3conn_cxt = patch('cwrstatus.datastore.S3Connection', autospec=True) with s3conn_cxt as s3_mock: s3_mock.return_value.get_bucket.return_value = FakeBucket() with patch('cwrstatus.datastore.get_s3_access', return_value=cred, autospec=True) as g_mock: import_data.from_s3() s3_mock.assert_called_once_with(cred[0], cred[1]) s3_mock.return_value.get_bucket.assert_called_once_with('juju-qa-data') g_mock.assert_called_once_with() docs = list(self.ds.db.cwr.find()) self.assertEqual(len(docs), 2) ids = [x['_id'] for x in docs] self.assertItemsEqual(ids, ['cwr-test-1', 'cwr-test-2']) self.assertEqual(docs[0]['build_info'], make_build_info()) self.assertEqual(docs[1]['build_info'], make_build_info()) self.assertEqual(docs[0]['bundle_name'], "git") self.assertEqual(docs[1]['bundle_name'], "git") self.assertEqual(docs[0]['etag'], "AB123") self.assertEqual(docs[1]['etag'], "AB123")
def test_from_s3(self): cred = ('fake_user', 'fake_pass') s3conn_cxt = patch( 'cwrstatus.datastore.S3Connection', autospec=True) with s3conn_cxt as s3_mock: s3_mock.return_value.get_bucket.return_value = FakeBucket() with patch('cwrstatus.datastore.get_s3_access', return_value=cred, autospec=True) as g_mock: import_data.from_s3() s3_mock.assert_called_once_with(cred[0], cred[1]) s3_mock.return_value.get_bucket.assert_called_once_with('juju-qa-data') g_mock.assert_called_once_with() docs = list(self.ds.db.cwr.find()) self.assertEqual(len(docs), 2) ids = [x['_id'] for x in docs] self.assertItemsEqual(ids, ['cwr-test-1', 'cwr-test-2']) self.assertEqual(docs[0]['build_info'], make_build_info()) self.assertEqual(docs[1]['build_info'], make_build_info()) self.assertEqual(docs[0]['bundle_name'], "git") self.assertEqual(docs[1]['bundle_name'], "git") self.assertEqual(docs[0]['etag'], "AB123") self.assertEqual(docs[1]['etag'], "AB123")
def test_get_artifacts_empty(self): input_data = make_build_info() del input_data['artifacts'] expected = [] output = import_data.get_artifacts(input_data) self.assertItemsEqual(output, expected)
def get_contents_as_string(self): return json.dumps(make_build_info())
def test_get_artifacts(self): expected = ["git-result.json", "git-result.svg"] build_info = make_build_info() output = import_data.get_artifacts(build_info) self.assertItemsEqual(output, expected)