Exemple #1
0
    def test_build_from_good_json(self):
        """ Tests that sample JSON results in a valid Build object that is
            correctly inserted into the database """
        # this is a fake build
        # it doesn't actually point to anything useful :P
        json_build = Build.new_from_json(self.json)

        self.assertEqual(json_build.status, 0)
        self.assertEqual(json_build.url, self.json['url'])
Exemple #2
0
    def test_build_insertion(self):
        """ Tests that a build is successfully inserted
	    and returns an ID correctly """
        test_build = Build.new_from_json(self.json)
        test_build.save()

        count = 0
        for b in Build.find():
            count += 1

        self.assertEqual(count, 1)
        self.assertIsInstance(test_build._id, ObjectId)
Exemple #3
0
    def test_multiple_build_retrieval(self):
         """ Tests that retrieving multiple builds works correctly """
         # should not be smart enough to tell that matching json is the same build,
         # so we can populate the database with multiple copies of the same build :P
         pass
         save1 = Build.new_from_json(self.json)
	 save1.save()
         save2 = Build.new_from_json(self.json)
	 save2.save()
         Build.new_from_json(self.json).save()
         Build.new_from_json(self.json).save()
         Build.new_from_json(self.json).save()
         Build.new_from_json(self.json).save()

         test_build1_id = save1['_id']
	 test_build2_id = save2['_id']

         # test that we get the right ones
         get_build1 = Build.load_from_database(test_build1_id)
         get_build2 = Build.load_from_database(test_build2_id)
         self.assertNotEqual(get_build1['_id'], get_build2['_id'])
         self.assertEqual(get_build1['_id'], test_build1_id)
         self.assertEqual(get_build2['_id'], test_build2_id)
Exemple #4
0
    def test_build_retrieval(self):
         """ Tests that Build objects are correctly retrieved from the
             database given an ID (as would be used by the BuildQueue)
             checks for:
                 correct Document retrieved
                 valid JSON returned """

         test_build = Build.new_from_json(self.json)
         test_build.save()

         get_build = Build.load_from_database(test_build._id)

         # check that they got the same thing
         self.assertEqual(get_build._id, test_build._id)
Exemple #5
0
    def test_update_existing_build(self):
         """ Tests that updating a build with build results works correctly
             checks for:
                 correct retrieval of guild
                 correct update """
         pass
         test_build = Build.new_from_json(self.json)
	 test_build.save()
         test_build_id = test_build['_id']

         error_msg = "this is an error message"

         test_build.update_with_results(1)
         check = Build.load_from_database(test_build_id)
         self.assertEqual(check['status'],1)

	 test_build.update_with_results(2, errmsg=error_msg)
	 check = Build.load_from_database(test_build_id)
	 self.assertEqual(check['status'],2)
         self.assertEqual(check['error'],error_msg)
Exemple #6
0
    def test_failed_build_retrieval(self):
        """ Tests that bad retrieves fail reasonably
            checks for:
                reasonable error given invalid ID
                reasonable errors for database errors """

    	with self.assertRaises(BuildErrorException):
    	    test_build  = Build()
    	    test_build.load_from_database(id=ObjectId())
    	    # should raise an error because it does
    	    # not exist (database is empty)

        # put in a test object
    	insert_build = Build.new_from_json(self.json)
    	inserted_id = insert_build.save()

    	# check for incorrect ID type
    	with self.assertRaises(BuildErrorException):
    	    test_build = Build()
    	    test_build.load_from_database(id=3)
Exemple #7
0
    def test_build_from_bad_json(self):
        """ Tests that bad JSON results in a reasonable response
            checks for: reasonable errors """
        json_build = Build.new_from_json({'fake':'haha'})
        with self.assertRaises(StructureError):
	       json_build.validate()