@@ -1191,12 +1191,12 @@ class ResultBundleTestCase(FixtureTestCase):
11911191 def setUp (self ):
11921192 super (ResultBundleTestCase , self ).setUp ()
11931193 self .data1 = {
1194- 'commitid' : '2 ' ,
1195- 'branch' : 'default ' , # Always use default for trunk/master/tip
1196- 'project' : 'MyProject ' ,
1197- 'executable' : 'myexe O3 64bits ' ,
1198- 'benchmark' : 'float ' ,
1199- 'environment' : "Bulldozer" ,
1194+ 'commitid' : '/api/v1/revision/2/ ' ,
1195+ 'branch' : '/api/v1/branch/1/ ' , # Always use default for trunk/master/tip
1196+ 'project' : '/api/v1/project/2/ ' ,
1197+ 'executable' : '/api/v1/executable/1/ ' ,
1198+ 'benchmark' : '/api/v1/benchmark/1/ ' ,
1199+ 'environment' : '/api/v1/environment/2/' ,
12001200 'result_value' : 4000 ,
12011201 }
12021202 DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
@@ -1223,23 +1223,24 @@ def test_populate_and_save(self):
12231223 bundle = ResultBundle (** self .data1 )
12241224 bundle ._populate_obj_by_data ()
12251225 # should raise exception if not OK
1226- bundle .save ()
1226+ bundle .hydrate_and_save ()
12271227 self .assert_ (True )
12281228
12291229 def test_save_same_result_again (self ):
12301230 """Save a previously saved result. Expected is an IntegrityError"""
12311231 modified_data = copy .deepcopy (self .data1 )
1232- modified_data ['environment' ] = "Dual Core"
1232+ modified_data ['environment' ] = '/api/v1/environment/1/'
1233+ modified_data ['project' ] = '/api/v1/project/1/'
12331234 bundle = ResultBundle (** modified_data )
12341235 bundle ._populate_obj_by_data ()
1235- self .assertRaises (IntegrityError , bundle .save )
1236+ self .assertRaises (IntegrityError , bundle .hydrate_and_save )
12361237
12371238 def test_for_nonexistent_environment (self ):
12381239 """Save data using non existing environment. Expected is an
12391240 ImmediateHttpResponse
12401241 """
12411242 modified_data = copy .deepcopy (self .data1 )
1242- modified_data ['environment' ] = "Foo the Bar"
1243+ modified_data ['environment' ] = '/api/v1/environment/3/'
12431244 self .assertRaises (ImmediateHttpResponse , ResultBundle , ** modified_data )
12441245
12451246 def test_insufficient_data (self ):
@@ -1253,7 +1254,7 @@ def test_date_attr_set(self):
12531254 # date is set automatically
12541255 modified_data = copy .deepcopy (self .data1 )
12551256 bundle = ResultBundle (** modified_data )
1256- bundle .save ()
1257+ bundle .hydrate_and_save ()
12571258 self .assertIsInstance (bundle .obj .date , datetime )
12581259 # date set by value
12591260 modified_data ['date' ] = '2011-05-05 03:01:45'
@@ -1266,7 +1267,7 @@ def test_optional_data(self):
12661267 """Should save optional data."""
12671268 data = dict (self .data1 .items () + self .data_optional .items ())
12681269 bundle = ResultBundle (** data )
1269- bundle .save ()
1270+ bundle .hydrate_and_save ()
12701271 self .assertIsInstance (bundle .obj .date , datetime )
12711272 self .assertEqual (bundle .obj .std_dev ,
12721273 float (self .data_optional ['std_dev' ]))
@@ -1275,22 +1276,6 @@ def test_optional_data(self):
12751276 self .assertEqual (bundle .obj .val_min ,
12761277 float (self .data_optional ['val_min' ]))
12771278
1278- def test_overwrite_exiting_items (self ):
1279- """Should overwrite existing attributes"""
1280- modified_data = copy .deepcopy (self .data1 )
1281- modified_data ['commitid' ] = '0b31bf33a469ac2cb1949666eea54d69a36c3724'
1282- modified_data ['project' ] = 'Cython'
1283- modified_data ['benchmark' ] = 'Django Template'
1284- modified_data ['executable' ] = 'pypy-jit'
1285- bundle = ResultBundle (** modified_data )
1286- bundle .save ()
1287- self .assertEqual (bundle .obj .revision .commitid ,
1288- modified_data ['commitid' ])
1289- self .assertEqual (bundle .obj .benchmark .name ,
1290- modified_data ['benchmark' ])
1291- self .assertEqual (bundle .obj .project .name ,
1292- modified_data ['project' ])
1293-
12941279
12951280class ResultBundleResourceTestCase (FixtureTestCase ):
12961281 """Submitting new benchmark results"""
@@ -1308,12 +1293,12 @@ def setUp(self):
13081293 'delete_result' , 'codespeed' , 'result' )
13091294
13101295 self .data1 = {
1311- 'commitid' : '2 ' ,
1312- 'branch' : 'default ' , # Always use default for trunk/master/tip
1313- 'project' : 'MyProject ' ,
1314- 'executable' : 'myexe O3 64bits ' ,
1315- 'benchmark' : 'float ' ,
1316- 'environment' : "Bulldozer" ,
1296+ 'commitid' : '/api/v1/revision/2/ ' ,
1297+ 'branch' : '/api/v1/branch/1/ ' , # Always use default for trunk/master/tip
1298+ 'project' : '/api/v1/project/2/ ' ,
1299+ 'executable' : '/api/v1/executable/1/ ' ,
1300+ 'benchmark' : '/api/v1/benchmark/1/ ' ,
1301+ 'environment' : '/api/v1/environment/2/' ,
13171302 'result_value' : 4000 ,
13181303 }
13191304 self .data_optional = {
@@ -1375,6 +1360,22 @@ def test_post_all_data(self):
13751360 ** self .post_auth )
13761361 self .assertEquals (response .status_code , 201 )
13771362
1363+ def test_post_invalid_data (self ):
1364+ """Should save a new result with mandatory and optional data"""
1365+ request = HttpRequest ()
1366+ request .user = self .api_user
1367+
1368+ request .user .user_permissions .add (self .add )
1369+
1370+ modified_data = copy .deepcopy (self .data1 )
1371+ # environment does not exist
1372+ modified_data ['environment' ] = '/api/v1/environment/5/'
1373+ response = self .client .post ('/api/v1/benchmark-result/' ,
1374+ data = json .dumps (modified_data ),
1375+ content_type = 'application/json' ,
1376+ ** self .post_auth )
1377+ self .assertEquals (response .status_code , 400 )
1378+
13781379 def test_get_one (self ):
13791380 """Should get a result bundle"""
13801381 response = self .client .get ('/api/v1/benchmark-result/1/' ,
0 commit comments