@@ -372,7 +372,7 @@ def setUp(self):
372372 super (RevisionTest , self ).setUp ()
373373
374374 def test_get_revision (self ):
375- """Should get an existing branch """
375+ """Should get an existing revision """
376376 response = self .client .get ('/api/v1/revision/1/' )
377377 self .assertEquals (response .status_code , 200 )
378378 self .assertEqual (json .loads (response .content )['commitid' ], "1" )
@@ -411,7 +411,7 @@ def test_post(self):
411411 self .assertEquals (response .status_code , 204 )
412412
413413 def test_put (self ):
414- """Should modify an existing environment """
414+ """Should modify an existing revision """
415415 modified_data = copy .deepcopy (self .revision2_data )
416416 modified_data ['tag' ] = "v0.9.1"
417417 response = self .client .put ('/api/v1/revision/1/' ,
@@ -437,7 +437,7 @@ def test_delete(self):
437437
438438
439439class ExecutableTest (FixtureTestCase ):
440- """Test Branch () API"""
440+ """Test Executable () API"""
441441
442442 def setUp (self ):
443443 self .executable1 = Executable .objects .get (pk = 1 )
@@ -514,13 +514,157 @@ def test_delete(self):
514514
515515
516516class BenchmarkTest (FixtureTestCase ):
517- """Test Branch() API"""
518- pass
517+ """Test Benchmark() API"""
518+
519+ def setUp (self ):
520+ self .benchmark1 = Benchmark .objects .get (pk = 1 )
521+ self .benchmark2_data = dict (
522+ name = "sleep" ,
523+ benchmark_type = 'C' ,
524+ description = 'fast faster fastest' ,
525+ units_title = 'Time' ,
526+ units = 'seconds' ,
527+ lessisbetter = True ,
528+ default_on_comparison = True ,
529+ )
530+ self .benchmark2 = Benchmark (** self .benchmark2_data )
531+ self .benchmark2 .save ()
532+ self .client = Client ()
533+ super (BenchmarkTest , self ).setUp ()
534+
535+ def test_get_benchmark (self ):
536+ """Should get an existing benchmark"""
537+ response = self .client .get ('/api/v1/benchmark/1/' )
538+ self .assertEquals (response .status_code , 200 )
539+ self .assertEqual (json .loads (response .content )['name' ],
540+ 'float' )
541+ self .assertEqual (json .loads (response .content )['units' ],
542+ "seconds" )
543+
544+ def test_get_benchmark_all_fields (self ):
545+ """Should get all fields for an benchmark"""
546+ response = self .client .get ('/api/v1/benchmark/{0}/' .format (
547+ self .benchmark2 .id ,))
548+ self .assertEquals (response .status_code , 200 )
549+ for k , v in self .benchmark2_data .items ():
550+ self .assertEqual (json .loads (response .content )[k ], v )
551+
552+ def test_post (self ):
553+ """Should save a new benchmark"""
554+ modified_data = copy .deepcopy (self .benchmark2_data )
555+ modified_data ['name' ] = 'wake'
556+ response = self .client .post ('/api/v1/benchmark/' ,
557+ data = json .dumps (modified_data ),
558+ content_type = 'application/json' )
559+ self .assertEquals (response .status_code , 201 )
560+ id = response ['Location' ].rsplit ('/' , 2 )[- 2 ]
561+ response = self .client .get ('/api/v1/benchmark/{0}/' .format (id ))
562+ for k , v in modified_data .items ():
563+ self .assertEqual (
564+ json .loads (response .content )[k ], v )
565+ response = self .client .delete ('/api/v1/benchmark/{0}/' .format (id ),
566+ content_type = 'application/json' )
567+ self .assertEquals (response .status_code , 204 )
568+
569+ def test_put (self ):
570+ """Should modify an existing benchmark"""
571+ modified_data = copy .deepcopy (self .benchmark2_data )
572+ modified_data ['name' ] = "django"
573+ response = self .client .put ('/api/v1/benchmark/1/' ,
574+ data = json .dumps (modified_data ),
575+ content_type = 'application/json' )
576+ self .assertEquals (response .status_code , 204 )
577+ response = self .client .get ('/api/v1/benchmark/1/' )
578+ for k , v in modified_data .items ():
579+ self .assertEqual (
580+ json .loads (response .content )[k ], v )
581+
582+ def test_delete (self ):
583+ """Should delete a benchmark"""
584+ response = self .client .get ('/api/v1/benchmark/1/' )
585+ self .assertEquals (response .status_code , 200 )
586+ # from fixture
587+ response = self .client .delete ('/api/v1/benchmark/1/' ,
588+ content_type = 'application/json' )
589+ self .assertEquals (response .status_code , 204 )
590+
591+ response = self .client .get ('/api/v1/benchmark/1/' )
592+ self .assertEquals (response .status_code , 404 )
519593
520594
521595class ReportTest (FixtureTestCase ):
522- """Test Branch() API"""
523- pass
596+ """Test Report() API"""
597+
598+ def setUp (self ):
599+ self .report1 = Report .objects .get (pk = 1 )
600+ self .revision1 = Revision .objects .get (pk = 1 )
601+ self .executable1 = Executable .objects .get (pk = 1 )
602+ self .environment1 = Environment .objects .get (pk = 1 )
603+ self .executable2_data = dict (
604+ name = "Fibo" ,
605+ description = "Fibonacci the Lame" ,
606+ )
607+ self .project = Project .objects .get (pk = 1 )
608+ self .executable2 = Executable (project = self .project ,
609+ ** self .executable2_data )
610+ self .executable2 .save ()
611+ self .report2_data = dict (
612+ revision = self .revision1 ,
613+ environment = self .environment1 ,
614+ executable = self .executable2 ,
615+ )
616+ self .report2 = Report (** self .report2_data )
617+ self .report2 .save ()
618+ self .report2_data = dict (
619+ revision = '/api/v1/revision/{0}/' .format (self .revision1 .id ),
620+ environment = '/api/v1/environment/{0}/' .format (self .environment1 .id ),
621+ executable = '/api/v1/executable/{0}/' .format (self .executable2 .id ),
622+ )
623+ self .client = Client ()
624+ super (ReportTest , self ).setUp ()
625+
626+ def test_get_report (self ):
627+ """Should get an existing report"""
628+ response = self .client .get ('/api/v1/report/1/' )
629+ self .assertEquals (response .status_code , 200 )
630+ self .assertEqual (json .loads (response .content )['summary' ],
631+ 'float -50.0%' )
632+ self .assertEqual (json .loads (response .content )['colorcode' ],
633+ "green" )
634+
635+ def test_get_report_all_fields (self ):
636+ """Should get all fields for an report"""
637+ response = self .client .get ('/api/v1/report/{0}/' .format (
638+ self .report2 .id ,))
639+ self .assertEquals (response .status_code , 200 )
640+ for k , v in self .report2_data .items ():
641+ self .assertEqual (json .loads (response .content )[k ], v )
642+
643+ def test_post (self ):
644+ """Should save a new report"""
645+ modified_data = copy .deepcopy (self .report2_data )
646+ response = self .client .post ('/api/v1/report/' ,
647+ data = json .dumps (modified_data ),
648+ content_type = 'application/json' )
649+ # next has to be 405, otherwise would raise IntegrityError
650+ self .assertEquals (response .status_code , 405 )
651+
652+ def test_put (self ):
653+ """Should modify an existing report"""
654+ modified_data = copy .deepcopy (self .report2_data )
655+ response = self .client .put ('/api/v1/report/1/' ,
656+ data = json .dumps (modified_data ),
657+ content_type = 'application/json' )
658+ self .assertEquals (response .status_code , 405 )
659+
660+ def test_delete (self ):
661+ """Should delete a report"""
662+ response = self .client .get ('/api/v1/report/1/' )
663+ self .assertEquals (response .status_code , 200 )
664+ # from fixture
665+ response = self .client .delete ('/api/v1/report/1/' ,
666+ content_type = 'application/json' )
667+ self .assertEquals (response .status_code , 405 )
524668
525669
526670class UserTest (FixtureTestCase ):
0 commit comments