<commit_before># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests the ProjectDao."""

import json

from google.apputils import basetest
import mock

from MySQLdb import DataError

from google.cloud.security.common.data_access import _db_connector
from google.cloud.security.common.data_access import errors
from google.cloud.security.common.data_access import bucket_dao
from google.cloud.security.common.data_access.sql_queries import select_data


class BucketDaoTest(basetest.TestCase):
	"""Tests for the BucketDao."""

	FAKE_PROJECT_NUMBERS = ['11111']

	@mock.patch.object(_db_connector.DbConnector, '__init__', autospec=True)
	def setUp(self, mock_db_connector):
		mock_db_connector.return_value = None
		self.bucket_dao = bucket_dao.BucketDao()
		self.resource_name = 'buckets_acl'
		self.fake_timestamp = '12345'

	def test_get_buckets_by_project_number(self):
		"""Test get_buckets_by_project_number()."""
		conn_mock = mock.MagicMock()
		cursor_mock = mock.MagicMock()
		fetch_mock = mock.MagicMock()

		self.bucket_dao.conn = conn_mock
		self.bucket_dao.conn.cursor.return_value = cursor_mock
		cursor_mock.fetchall.return_value = fetch_mock

		fake_query = select_data.BUCKETS_BY_PROJECT_ID.format(
			self.fake_timestamp, 
			self.FAKE_PROJECT_NUMBERS[0])
		self.bucket_dao.get_buckets_by_project_number(
			self.resource_name, 
			self.fake_timestamp, 
			self.FAKE_PROJECT_NUMBERS[0])

		cursor_mock.execute.assert_called_once_with(fake_query, ())
		cursor_mock.fetchall.assert_called_once_with()

	def test_get_project_numbers_raises_error(self):<commit_msg>Update bucket_dao_test.py<commit_after># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests the ProjectDao."""

import json

from google.apputils import basetest
import mock

from MySQLdb import DataError

from google.cloud.security.common.data_access import _db_connector
from google.cloud.security.common.data_access import errors
from google.cloud.security.common.data_access import bucket_dao
from google.cloud.security.common.data_access.sql_queries import select_data


class BucketDaoTest(basetest.TestCase):
	"""Tests for the BucketDao."""

	FAKE_PROJECT_NUMBERS = ['11111']

	@mock.patch.object(_db_connector.DbConnector, '__init__', autospec=True)
	def setUp(self, mock_db_connector):
		mock_db_connector.return_value = None
		self.bucket_dao = bucket_dao.BucketDao()
		self.resource_name = 'buckets_acl'
		self.fake_timestamp = '12345'

	def test_get_buckets_by_project_number(self):
		"""Test get_buckets_by_project_number()."""
		conn_mock = mock.MagicMock()
		cursor_mock = mock.MagicMock()
		fetch_mock = mock.MagicMock()

		self.bucket_dao.conn = conn_mock
		self.bucket_dao.conn.cursor.return_value = cursor_mock
		cursor_mock.fetchall.return_value = fetch_mock

		fake_query = select_data.BUCKETS_BY_PROJECT_ID.format(
			self.fake_timestamp, 
			self.FAKE_PROJECT_NUMBERS[0])
		self.bucket_dao.get_buckets_by_project_number(
			self.resource_name, 
			self.fake_timestamp, 
			self.FAKE_PROJECT_NUMBERS[0])

		cursor_mock.execute.assert_called_once_with(fake_query, None)
		cursor_mock.fetchall.assert_called_once_with()

	def test_get_project_numbers_raises_error(self):
{'fraction_non_alphanumeric': 0.0858561967833491, 'fraction_numerical': 0.00946073793755913, 'mean_word_length': 5.456488549618321, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4322384', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1348, 'n_words': 329}