class ProjectTest(FixtureTestCase): """Test Project() API""" def setUp(self): self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project_data2 = dict( name="project alpha", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.client = Client() super(ProjectTest, self).setUp() def test_get_project(self): """Should get an existing project""" response = self.client.get('/api/v1/project/{0}/'.format( self.project.id, )) self.assertEquals(response.status_code, 200) self.assertEqual( json.loads(response.content)['name'], "{0}".format(self.project_data['name'])) def test_get_project_all_fields(self): """Should get all fields for a project""" response = self.client.get('/api/v1/project/%s/' % (self.project.id, )) self.assertEquals(response.status_code, 200) for k in self.project_data.keys(): self.assertEqual( json.loads(response.content)[k], getattr(self.project, k)) def test_post(self): """Should save a new project""" response = self.client.post('/api/v1/project/', data=json.dumps(self.project_data2), content_type='application/json') self.assertEquals(response.status_code, 201) response = self.client.get('/api/v1/project/{0}/'.format( self.project.id)) for k, v in self.project_data.items(): self.assertEqual(json.loads(response.content)[k], v) def test_delete(self): """Should delete an project""" response = self.client.delete('/api/v1/project/{0}/'.format( self.project.id, ), content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/project/{0}/'.format( self.project.id, )) self.assertEquals(response.status_code, 404)
def setUp(self): self.github_project = Project( name='Some Project', repo_type='H', repo_path='https://github.com/tobami/codespeed.git') self.git_project = Project(repo_type='G', repo_path='/home/foo/codespeed')
def setUp(self): self.data1 = { 'commitid': '2', 'branch': 'default', # Always use default for trunk/master/tip 'project': 'MyProject', 'executable': 'myexe O3 64bits', 'benchmark': 'float', 'environment': "Bulldozer", 'result_value': 4000, } self.data_optional = { 'std_dev': 0.2, 'val_min': 2.23, 'val_max': 3.42, 'date': datetime.now().strftime(self.DATETIME_FORMAT), } project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**project_data) self.project.save() self.env1 = Environment(name='Bulldozer') self.env1.save()
def setUp(self): self.branch1 = Branch.objects.get(pk=1) self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.branch2_data = dict(name="master2", project='/api/v1/project/{0}/'.format( self.project.id)) self.client = Client() super(BranchTest, self).setUp()
def setUp(self): self.github_project = Project( name='Some Project', repo_type='H', repo_path='https://github.com/tobami/codespeed.git' ) self.git_project = Project( repo_type='G', repo_path='/home/foo/codespeed' )
def setUp(self): self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project_data2 = dict( name="project alpha", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.client = Client() super(ProjectTest, self).setUp()
class TestProject(TestCase): def setUp(self): self.github_project = Project( name='Some Project', repo_type='H', repo_path='https://github.com/tobami/codespeed.git' ) self.git_project = Project( repo_type='G', repo_path='/home/foo/codespeed' ) def test_str(self): self.assertEqual(str(self.github_project), 'Some Project') def test_repo_name(self): """Test that only projects with local repositories have a repo_name attribute """ self.assertEqual(self.git_project.repo_name, 'codespeed') self.assertRaises(AttributeError, getattr, self.github_project, 'repo_name') def test_working_copy(self): """Test that only projects with local repositories have a working_copy attribute """ self.assertEqual(self.git_project.working_copy, os.path.join(settings.REPOSITORY_BASE_PATH, self.git_project.repo_name)) self.assertRaises( AttributeError, getattr, self.github_project, 'working_copy') def test_github_browsing_url(self): """If empty, the commit browsing url will be filled in with a default value when using github repository. """ # It should work with https:// as well as git:// urls self.github_project.save() self.assertEquals(self.github_project.commit_browsing_url, 'https://github.com/tobami/codespeed.git/' 'commit/{commitid}') self.github_project.repo_path = 'git://github.com/tobami/codespeed.git' self.github_project.save() self.assertEquals(self.github_project.commit_browsing_url, 'https://github.com/tobami/codespeed.git/' 'commit/{commitid}') # If filled in, commit browsing url should not change self.github_project.commit_browsing_url = 'https://example.com/{commitid}' self.github_project.save() self.assertEquals(self.github_project.commit_browsing_url, 'https://example.com/{commitid}')
class TestProject(TestCase): def setUp(self): self.github_project = Project( name='Some Project', repo_type='H', repo_path='https://github.com/tobami/codespeed.git') self.git_project = Project(repo_type='G', repo_path='/home/foo/codespeed') def test_str(self): self.assertEqual(str(self.github_project), 'Some Project') def test_repo_name(self): """Test that only projects with local repositories have a repo_name attribute """ self.assertEqual(self.git_project.repo_name, 'codespeed') self.assertRaises(AttributeError, getattr, self.github_project, 'repo_name') def test_working_copy(self): """Test that only projects with local repositories have a working_copy attribute """ self.assertEqual( self.git_project.working_copy, os.path.join(settings.REPOSITORY_BASE_PATH, self.git_project.repo_name)) self.assertRaises(AttributeError, getattr, self.github_project, 'working_copy') def test_github_browsing_url(self): """If empty, the commit browsing url will be filled in with a default value when using github repository. """ # It should work with https:// as well as git:// urls self.github_project.save() self.assertEquals( self.github_project.commit_browsing_url, 'https://github.com/tobami/codespeed.git/' 'commit/{commitid}') self.github_project.repo_path = 'git://github.com/tobami/codespeed.git' self.github_project.save() self.assertEquals( self.github_project.commit_browsing_url, 'https://github.com/tobami/codespeed.git/' 'commit/{commitid}') # If filled in, commit browsing url should not change self.github_project.commit_browsing_url = 'https://example.com/{commitid}' self.github_project.save() self.assertEquals(self.github_project.commit_browsing_url, 'https://example.com/{commitid}')
def setUp(self): self.branch1 = Branch.objects.get(pk=1) self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.branch2_data = dict( name="master2", project='/api/v1/project/{0}/'.format(self.project.id) ) self.client = Client() super(BranchTest, self).setUp()
def setUp(self): self.days = 0 self.starttime = datetime.now() + timedelta(days=-100) Project(repo_type='G', name='pro', repo_path='/home/foo/codespeed').save() self.pro = Project.objects.get(name='pro') Branch(project=self.pro, name='branch').save() self.b = Branch.objects.get(name='branch') Environment(name='Walden Pond').save() Executable(name='walden', project=self.pro).save() Benchmark(name='TestBench').save() self.env = Environment.objects.get(name='Walden Pond') self.exe = Executable.objects.get(name='walden') self.bench = Benchmark.objects.get(name='TestBench')
def setUp(self): self.github_project = Project( name="Some Project", repo_type="H", repo_path="https://github.com/tobami/codespeed.git" ) self.git_project = Project(repo_type="G", repo_path="/home/foo/codespeed")
class ResultBundleResourceTestCase(FixtureTestCase): """Submitting new benchmark results""" DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S' def setUp(self): self.data1 = { 'commitid': '2', 'branch': 'default', # Always use default for trunk/master/tip 'project': 'MyProject', 'executable': 'myexe O3 64bits', 'benchmark': 'float', 'environment': "Bulldozer", 'result_value': 4000, } self.data_optional = { 'std_dev': 0.2, 'val_min': 2.23, 'val_max': 3.42, 'date': datetime.now().strftime(self.DATETIME_FORMAT), } project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**project_data) self.project.save() self.env1 = Environment(name='Bulldozer') self.env1.save() def test_post_mandatory(self): """Should save a new result with only mandatory data""" response = self.client.post('/api/v1/benchmark-result/', data=json.dumps(self.data1), content_type='application/json') self.assertEquals(response.status_code, 201) id = response['Location'].rsplit('/', 2)[-2] result = Result.objects.get(pk=int(id)) # just to make the point self.assertIsInstance(result, Result) self.assertEqual(result.value, self.data1['result_value']) def test_post_all_data(self): """Should save a new result with mandatory and optional data""" data = dict(self.data1, **self.data_optional) response = self.client.post('/api/v1/benchmark-result/', data=json.dumps(data), content_type='application/json') self.assertEquals(response.status_code, 201) def test_get_one(self): """Should get a result bundle""" response = self.client.get('/api/v1/benchmark-result/1/', content_type='application/json') self.assertEquals(response.status_code, 200) response_data = json.loads(response.content) for k in ('project', 'result', 'branch', 'benchmark', 'environment', 'executable', 'revision'): self.assertEqual(response_data[k], '/api/v1/{0}/1/'.format(k, ))
class ResultBundleTestCase(FixtureTestCase): def setUp(self): self.data1 = { 'commitid': '2', 'branch': 'default', # Always use default for trunk/master/tip 'project': 'MyProject', 'executable': 'myexe O3 64bits', 'benchmark': 'float', 'environment': "Bulldozer", 'result_value': 4000, } DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S' self.data_optional = { 'std_dev': 0.2, 'val_min': 2.23, 'val_max': 3.42, 'date': datetime.now().strftime(DATETIME_FORMAT), } project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**project_data) self.project.save() self.env1 = Environment(name='Bulldozer') self.env1.save() def test_populate_and_save(self): bundle = ResultBundle(**self.data1) bundle._populate_obj_by_data() # should raise exception if not OK bundle.save() self.assert_(True) def test_save_same_result_again(self): """Save a previously saved result. Expected is an IntegrityError""" modified_data = copy.deepcopy(self.data1) modified_data['environment'] = "Dual Core" bundle = ResultBundle(**modified_data) bundle._populate_obj_by_data() self.assertRaises(IntegrityError, bundle.save) def test_for_nonexistent_environment(self): """Save data using non existing environment. Expected is an ImmediateHttpResponse """ modified_data = copy.deepcopy(self.data1) modified_data['environment'] = "Foo the Bar" self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data) def test_insufficient_data(self): """See if Result() is saved w/ insufficient data""" modified_data = copy.deepcopy(self.data1) modified_data.pop('environment') self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data) def test_date_attr_set(self): """Check if date attr of Result() is set if not given""" # date is set automatically modified_data = copy.deepcopy(self.data1) bundle = ResultBundle(**modified_data) bundle.save() self.assertIsInstance(bundle.obj.date, datetime) # date set by value modified_data['date'] = '2011-05-05 03:01:45' ResultBundle(**modified_data) # wrong date string modified_data['date'] = '2011-05-05T03:01:45' self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data) def test_optional_data(self): """Check handling of optional data""" data = dict(self.data1.items() + self.data_optional.items()) bundle = ResultBundle(**data) bundle.save() self.assertIsInstance(bundle.obj.date, datetime) self.assertEqual(bundle.obj.std_dev, float(self.data_optional['std_dev'])) self.assertEqual(bundle.obj.val_max, float(self.data_optional['val_max'])) self.assertEqual(bundle.obj.val_min, float(self.data_optional['val_min'])) def test_non_exiting_items(self): """Check handling of optional data""" modified_data = copy.deepcopy(self.data1) modified_data['commitid'] = '0b31bf33a469ac2cb1949666eea54d69a36c3724' modified_data['project'] = 'Cython' modified_data['benchmark'] = 'Django Template' modified_data['executable'] = 'pypy-jit' bundle = ResultBundle(**modified_data) bundle.save() self.assertEqual(bundle.obj.revision.commitid, modified_data['commitid']) self.assertEqual(bundle.obj.benchmark.name, modified_data['benchmark']) self.assertEqual(bundle.obj.project.name, modified_data['project'])
class BranchTest(FixtureTestCase): """Test Branch() API""" def setUp(self): self.branch1 = Branch.objects.get(pk=1) self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.branch2_data = dict(name="master2", project='/api/v1/project/{0}/'.format( self.project.id)) self.client = Client() super(BranchTest, self).setUp() def test_get_branch(self): """Should get an existing branch""" response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 200) self.assertEqual(json.loads(response.content)['name'], "default") self.assertEqual( json.loads(response.content)['project'], "/api/v1/project/1/") def test_get_branch_all_fields(self): """Should get all fields for an branch""" response = self.client.get('/api/v1/branch/%s/' % (self.branch1.id, )) self.assertEquals(response.status_code, 200) self.assertEquals( json.loads(response.content)['name'], self.branch1.name) self.assertEquals( json.loads(response.content)['project'], '/api/v1/project/1/') self.assertEquals( json.loads(response.content)['resource_uri'], '/api/v1/branch/%s/' % (self.branch1.id, )) def test_post(self): """Should save a new branch""" modified_data = copy.deepcopy(self.branch2_data) response = self.client.post('/api/v1/branch/', data=json.dumps(modified_data), content_type='application/json') self.assertEquals(response.status_code, 201) id = response['Location'].rsplit('/', 2)[-2] response = self.client.get('/api/v1/branch/{0}/'.format(id)) for k, v in self.branch2_data.items(): self.assertEqual(json.loads(response.content)[k], v) response = self.client.delete('/api/v1/branch/{0}/'.format(id), content_type='application/json') self.assertEquals(response.status_code, 204) def test_put(self): """Should modify an existing environment""" modified_data = copy.deepcopy(self.branch2_data) modified_data['name'] = "tip" response = self.client.put('/api/v1/branch/1/', data=json.dumps(modified_data), content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/branch/1/') for k, v in modified_data.items(): self.assertEqual(json.loads(response.content)[k], v) def test_delete(self): """Should delete a branch""" response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 200) # from fixture response = self.client.delete('/api/v1/branch/1/', content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 404)
class BranchTest(FixtureTestCase): """Test Branch() API""" def setUp(self): self.branch1 = Branch.objects.get(pk=1) self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.branch2_data = dict( name="master2", project='/api/v1/project/{0}/'.format(self.project.id) ) self.client = Client() super(BranchTest, self).setUp() def test_get_branch(self): """Should get an existing branch""" response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 200) self.assertEqual(json.loads(response.content)['name'], "default") self.assertEqual(json.loads(response.content)['project'], "/api/v1/project/1/") def test_get_branch_all_fields(self): """Should get all fields for an branch""" response = self.client.get('/api/v1/branch/%s/' % (self.branch1.id,)) self.assertEquals(response.status_code, 200) self.assertEquals(json.loads(response.content)['name'], self.branch1.name) self.assertEquals(json.loads(response.content)['project'], '/api/v1/project/1/') self.assertEquals(json.loads(response.content)['resource_uri'], '/api/v1/branch/%s/' %(self.branch1.id,)) def test_post(self): """Should save a new branch""" modified_data = copy.deepcopy(self.branch2_data) response = self.client.post('/api/v1/branch/', data=json.dumps(modified_data), content_type='application/json') self.assertEquals(response.status_code, 201) id = response['Location'].rsplit('/', 2)[-2] response = self.client.get('/api/v1/branch/{0}/'.format(id)) for k, v in self.branch2_data.items(): self.assertEqual( json.loads(response.content)[k], v) response = self.client.delete('/api/v1/branch/{0}/'.format(id), content_type='application/json') self.assertEquals(response.status_code, 204) def test_put(self): """Should modify an existing environment""" modified_data = copy.deepcopy(self.branch2_data) modified_data['name'] = "tip" response = self.client.put('/api/v1/branch/1/', data=json.dumps(modified_data), content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/branch/1/') for k, v in modified_data.items(): self.assertEqual( json.loads(response.content)[k], v) def test_delete(self): """Should delete a branch""" response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 200) # from fixture response = self.client.delete('/api/v1/branch/1/', content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/branch/1/') self.assertEquals(response.status_code, 404)
class ResultBundleResourceTestCase(FixtureTestCase): """Submitting new benchmark results""" DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S' def setUp(self): self.data1 = { 'commitid': '2', 'branch': 'default', # Always use default for trunk/master/tip 'project': 'MyProject', 'executable': 'myexe O3 64bits', 'benchmark': 'float', 'environment': "Bulldozer", 'result_value': 4000, } self.data_optional = { 'std_dev': 0.2, 'val_min': 2.23, 'val_max': 3.42, 'date': datetime.now().strftime(self.DATETIME_FORMAT), } project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**project_data) self.project.save() self.env1 = Environment(name='Bulldozer') self.env1.save() def test_post_mandatory(self): """Should save a new result with only mandatory data""" response = self.client.post('/api/v1/benchmark-result/', data=json.dumps(self.data1), content_type='application/json') self.assertEquals(response.status_code, 201) id = response['Location'].rsplit('/', 2)[-2] result = Result.objects.get(pk=int(id)) # just to make the point self.assertIsInstance(result, Result) self.assertEqual(result.value, self.data1['result_value']) def test_post_all_data(self): """Should save a new result with mandatory and optional data""" data = dict(self.data1, **self.data_optional) response = self.client.post('/api/v1/benchmark-result/', data=json.dumps(data), content_type='application/json') self.assertEquals(response.status_code, 201) def test_get_one(self): """Should get a result bundle""" response = self.client.get('/api/v1/benchmark-result/1/', content_type='application/json') self.assertEquals(response.status_code, 200) response_data = json.loads(response.content) for k in ('project', 'result', 'branch', 'benchmark', 'environment', 'executable', 'revision'): self.assertEqual( response_data[k], '/api/v1/{0}/1/'.format(k,))
class ProjectTest(FixtureTestCase): """Test Project() API""" def setUp(self): self.project_data = dict( name="PyPy", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project_data2 = dict( name="project alpha", repo_type="M", repo_path="ssh://[email protected]/pypy/pypy", repo_user="******", repo_pass="******", ) self.project = Project(**self.project_data) self.project.save() self.client = Client() super(ProjectTest, self).setUp() def test_get_project(self): """Should get an existing project""" response = self.client.get('/api/v1/project/{0}/'.format( self.project.id,)) self.assertEquals(response.status_code, 200) self.assertEqual(json.loads(response.content)['name'], "{0}".format( self.project_data['name'])) def test_get_project_all_fields(self): """Should get all fields for a project""" response = self.client.get('/api/v1/project/%s/' % (self.project.id,)) self.assertEquals(response.status_code, 200) for k in self.project_data.keys(): self.assertEqual( json.loads(response.content)[k], getattr(self.project, k)) def test_post(self): """Should save a new project""" response = self.client.post('/api/v1/project/', data=json.dumps(self.project_data2), content_type='application/json') self.assertEquals(response.status_code, 201) response = self.client.get('/api/v1/project/{0}/'.format( self.project.id)) for k, v in self.project_data.items(): self.assertEqual( json.loads(response.content)[k], v) def test_delete(self): """Should delete an project""" response = self.client.delete('/api/v1/project/{0}/'.format( self.project.id,), content_type='application/json') self.assertEquals(response.status_code, 204) response = self.client.get('/api/v1/project/{0}/'.format( self.project.id,)) self.assertEquals(response.status_code, 404)