From a2584b024912578225f2fec004de8ddcca522f1b Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 27 Dec 2013 15:14:42 +0400 Subject: [PATCH] Added API tests for companies endpoint Change-Id: Ib750a15527f4a0caef72f3977043e3cd091b138b --- tests/api/test_companies.py | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/api/test_companies.py diff --git a/tests/api/test_companies.py b/tests/api/test_companies.py new file mode 100644 index 000000000..271c31595 --- /dev/null +++ b/tests/api/test_companies.py @@ -0,0 +1,79 @@ +# Copyright (c) 2013 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json + +from tests.api import test_api + + +class TestAPICompanies(test_api.TestAPI): + + def test_get_companies(self): + with test_api.make_runtime_storage( + {'repos': [{'module': 'nova', 'project_type': 'openstack', + 'organization': 'openstack', + 'uri': 'git://github.com/openstack/nova.git'}, + {'module': 'glance', 'project_type': 'openstack', + 'organization': 'openstack', + 'uri': 'git://github.com/openstack/glance.git'}]}, + test_api.make_records(record_type=['commit'], + loc=[10, 20, 30], + module=['glance'], + company_name=['NEC', 'IBM', 'NTT']), + test_api.make_records(record_type=['review'], + primary_key=['0123456789', '9876543210'], + company_name=['IBM']), + test_api.make_records(record_type=['mark'], + review_id=['0123456789', '9876543210'], + company_name=['IBM']), + test_api.make_records(record_type=['mark'], + review_id=['0123456789'], + company_name=['NEC'])): + + response = self.app.get('/api/1.0/companies?metric=commits') + companies = json.loads(response.data)['companies'] + self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, + {'id': 'nec', 'text': 'NEC'}, + {'id': 'ntt', 'text': 'NTT'}], companies) + + response = self.app.get('/api/1.0/companies?metric=marks') + companies = json.loads(response.data)['companies'] + self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, + {'id': 'nec', 'text': 'NEC'}], companies) + + response = self.app.get('/api/1.0/companies?metric=commits&' + 'company_name=ib') + companies = json.loads(response.data)['companies'] + self.assertEqual([{'id': 'ibm', 'text': 'IBM'}], companies) + + def test_get_company(self): + with test_api.make_runtime_storage( + {'repos': [{'module': 'nova', 'project_type': 'openstack', + 'organization': 'openstack', + 'uri': 'git://github.com/openstack/nova.git'}, + {'module': 'glance', 'project_type': 'openstack', + 'organization': 'openstack', + 'uri': 'git://github.com/openstack/glance.git'}]}, + test_api.make_records(record_type=['commit'], + loc=[10, 20, 30], + module=['glance'], + company_name=['NEC', 'IBM', 'NTT'])): + + response = self.app.get('/api/1.0/companies/nec') + company = json.loads(response.data)['company'] + self.assertEqual({'id': 'nec', 'text': 'NEC'}, company) + + response = self.app.get('/api/1.0/companies/google') + self.assertEqual(404, response.status_code)