<commit_before>import unittest

from apiclient.http import HttpMockSequence

from google.appengine.ext import testbed
from mock import patch, Mock

from model.model_creator import ModelCreator
import test_utils


class TestModelCreator(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_memcache_stub()
        self.testbed.init_app_identity_stub()

    def tearDown(self):
        self.testbed.deactivate()
        patch.stopall()

    @patch.object(ModelCreator, '_create_http')
    def test_should_create_dataset(self, _create_http):
        # given
        http_mock = Mock(wraps=HttpMockSequence([
            ({'status': '200'}, test_utils.content(
                 'tests/json_samples/bigquery_v2_test_schema.json')),
            ({'status': '200'}, test_utils.content(
                'tests/json_samples/bigquery_v2_datasets_insert_200.json'))
        ]))
        _create_http.return_value = http_mock
        under_test = ModelCreator("bq_schemas")

        # when
        under_test.create_missing_datasets()

        # then
        calls = http_mock.mock_calls
        self.assertEqual(2, len(calls))

    @patch.object(ModelCreator, '_create_http')
    def test_should_ignore_dataset_already_exists_error(self, _create_http):
        # given
        http_mock = Mock(wraps=HttpMockSequence([
            ({'status': '200'}, test_utils.content(
                 'tests/json_samples/bigquery_v2_test_schema.json')),
            ({'status': '200'}, test_utils.content(
                'tests/json_samples/bigquery_v2_datasets_insert_409.json'))
        ]))
        _create_http.return_value = http_mock
        under_test = ModelCreator("bq_schemas")

        # when
        under_test.create_missing_datasets()
<commit_msg>#1 added test for dataset duplicate<commit_after>import unittest

from apiclient.http import HttpMockSequence

from google.appengine.ext import testbed
from mock import patch, Mock

from model.model_creator import ModelCreator
import test_utils


class TestModelCreator(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_memcache_stub()
        self.testbed.init_app_identity_stub()

    def tearDown(self):
        self.testbed.deactivate()
        patch.stopall()

    @patch.object(ModelCreator, '_create_http')
    def test_should_create_dataset(self, _create_http):
        # given
        http_mock = Mock(wraps=HttpMockSequence([
            ({'status': '200'}, test_utils.content(
                 'tests/json_samples/bigquery_v2_test_schema.json')),
            ({'status': '200'}, test_utils.content(
                'tests/json_samples/bigquery_v2_datasets_insert_200.json'))
        ]))
        _create_http.return_value = http_mock
        under_test = ModelCreator("bq_schemas")

        # when
        under_test.create_missing_datasets()

        # then
        calls = http_mock.mock_calls
        self.assertEqual(2, len(calls))

    @patch.object(ModelCreator, '_create_http')
    def test_should_ignore_dataset_already_exists_error(self, _create_http):
        # given
        http_mock = Mock(wraps=HttpMockSequence([
            ({'status': '200'}, test_utils.content(
                 'tests/json_samples/bigquery_v2_test_schema.json')),
            ({'status': '409'}, test_utils.content(
                'tests/json_samples/bigquery_v2_datasets_insert_409.json'))
        ]))
        _create_http.return_value = http_mock
        under_test = ModelCreator("bq_schemas")

        # when
        under_test.create_missing_datasets()

{'fraction_non_alphanumeric': 0.10223555070883315, 'fraction_numerical': 0.012813522355507088, 'mean_word_length': 2.8702531645569622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1179617', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1116, 'n_words': 171}