Пример #1
0
    def test_api_build_id_returns_corrent_information(self):
        """ Verifies that when a build is running, returns the status of that
        build and otherwise returns clear."""

        build = Build()
        build.save()

        response = self.client.get('/builds/%s' % str(build._id))

        self.assertEqual(build._id, ObjectId(response.json['_id']['$oid']))
Пример #2
0
    def test_api_build_status_wrong_id(self):
        """ Verifies that an error is returned if an invalid ID is passed to
        the build_status endpoint """


        build = Build()
        build.save()

        response = self.client.get('/builds/%s' % '1234')

        self.assertEqual(response.json['error'], 'Invalid Build ID')
Пример #3
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)
Пример #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)
Пример #5
0
    def test_api_builds_returned_corrent(self):
        """ Verifies that build statuses returned match initial set."""

        builds = []
        for i in range(5):
            build = Build()
            build.save()
            builds.append(str(build._id))

        response = self.client.get('/builds')

        self.assertEqual(len(response.json), 5)

        for b in response.json:
            self.assertTrue(builds.count(json.loads(b)['_id']['$oid']) == 1)
Пример #6
0
    def test_post_to_github_without_credentials_returns_false(self):
        configs = dict()

        build = Build()
        build.error = "error string"
        build.ref = 'build_ref'

        build.repository.name = 'test_repo'
        build.repository.owner.name = 'jesse'

        self.thread = WorkerThread(self.queue, configs)

        with patch.object(requests, 'post') as mock:
            mock.return_value = True

            self.assertFalse(self.thread._post_to_github(build))

        mock.assert_not_called()
Пример #7
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'])
Пример #8
0
    def test_post_to_github_posts_to_correct_url(self):
        configs = dict(GITHUB_ID='github_id', GITHUB_SECRET='github_secret')

        build = Build()
        build.error = "error string"
        build.ref = 'build_ref'

        build.repository.name = 'test_repo'
        build.repository.owner.name = 'jesse'

        self.thread = WorkerThread(self.queue, configs)

        with patch.object(requests, 'post') as mock:
            mock.return_value = True

            self.assertTrue(self.thread._post_to_github(build))

        expected_url = 'https://api.github.com/repos/jesse/test_repo/issues?client_id=github_id&client_secret=github_secret'
        expected_data = {'body': 'error string', 'title': 'Build failure on ref build_ref'}
        mock.assert_called_once_with(expected_url, expected_data)
Пример #9
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)
Пример #10
0
    def test_api_blame_list(self):
        """ Verifies that the data returned is the same as data stored"""

        for i in range(15):
            build = Build()
            build.status = 2
            if i < 5:
                build.author.name = 'jessepollak'
            elif i < 10:
                build.author.name = 'dunvi'
            else:
                build.author.name = 'brennenbyrne'

            build.save()

        response = self.client.get('/blame')

        self.assertEqual(response.json['brennenbyrne'], 5)
        self.assertEqual(response.json['jessepollak'], 5)
        self.assertEqual(response.json['dunvi'], 5)
Пример #11
0
    def test_api_builds(self):
        """ Verifies that a good build builds without error """

        response = self.client.post(
           '/build',
            data=self.json,
            content_type='application/json'
        )

        api.worker.join()

        build = Build.find_one(dict(_id=ObjectId(response.json['id'])))

        self.assertEqual(build['status'],1)
Пример #12
0
    def test_api_builds_bad(self, mock):
        """ Verifies that a bad build returns an error and posts the error to
        GitHub """

        mock.return_value = "This is an error"

        response = self.client.post(
            '/build',
            data=self.json,
            content_type='application/json'
        )

        api.worker.join()

        build = Build.find_one(dict(_id=ObjectId(response.json['id'])))

        self.assertEqual(build.status ,2)
        mock.assert_called_once()
Пример #13
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)
Пример #14
0
    def test_api_rebuilds(self):
        """ Verifies that after adding a failing test, build that passed build()
        now fails."""

        build = Build()
        build.status = 2
        build.save()

        response = self.client.post('/builds/new', data=dict(build_id=str(build._id)))

        api.worker.join()

        build.reload()

        self.assertEqual(build.status, 1)
        self.assertTrue(api.worker.current_build is None)
        self.assertEqual(response.json['id'], str(build._id))
Пример #15
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()
Пример #16
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)