def test_fake_block_simple_oneline(self, write_row_mock): yaml = """ - object: OBJ fields: first_name: fake: first_name """ generate(StringIO(yaml), {}, None) assert row_values(write_row_mock, 0, "first_name")
def test_constants(self, write_row_mock): yaml = """ - plugin: snowfakery.standard_plugins.Math - object: OBJ fields: pi: ${{Math.pi}} """ generate(StringIO(yaml), {}) assert row_values(write_row_mock, 0, "pi") == math.pi
def test_random_number_with_step(self, generated_rows): yaml = """ - object : A fields: number: ${{random_number(min=15, max=200, step=5)}} """ generate(StringIO(yaml), {}, None) assert 15 <= int(generated_rows.row_values(0, "number")) <= 200 assert int(generated_rows.row_values(0, "number")) % 5 == 0
def test_math(self, write_row_mock): yaml = """ - plugin: snowfakery.standard_plugins.Math - object: OBJ fields: twelve: ${{Math.sqrt(144)}} """ generate(StringIO(yaml), {}) assert row_values(write_row_mock, 0, "twelve") == 12
def test_stops_if_criteria_misspelled(self, write_row): yaml = """ - object: foo just_once: True - object: bar """ with pytest.raises(DataGenError): generate(StringIO(yaml), stopping_criteria=StoppingCriteria("baz", 3))
def test_gen_npsp_standard_objects(self, write_row): with open(npsp_standard_objects) as open_yaml_file: generate(open_yaml_file, {}, None) calls = write_row.mock_calls assert find_row("Account", {}, calls) assert find_row("Contact", {}, calls) assert find_row("Opportunity", {}, calls)
def test_stops_on_no_progress(self, write_row): yaml = """ - object: foo just_once: True - object: bar """ with pytest.raises(RuntimeError): generate(StringIO(yaml), stopping_criteria=StoppingCriteria("foo", 3))
def generate_twice(yaml): continuation_file = StringIO() generate(StringIO(yaml), generate_continuation_file=continuation_file) next_contination_file = StringIO() generate( StringIO(yaml), continuation_file=StringIO(continuation_file.getvalue()), generate_continuation_file=next_contination_file, )
def test_missing_options_from_yaml(self): yaml = """ - option: total_data_imports default: 16 - option: xyzzy """ with pytest.raises(DataGenNameError) as e: generate(StringIO(yaml), {"qwerty": "EBCDIC"}) assert "xyzzy" in str(e.value)
def test_functions_inline(self, write_row): yaml = """ - object : A fields: wedding: Our wedding date is ${{date_between(start_date="2012-01-31", end_date="2012-12-31")}} number: The number is ${{random_number(min=15, max=19)}} """ generate(StringIO(yaml), {}, None) assert "2012" in write_row.mock_calls[0][1][1]["wedding"] assert "1" in write_row.mock_calls[0][1][1]["number"]
def test_wrong_special_object(self): recipe_data = """ - plugin: snowfakery.standard_plugins.Salesforce - object: Account fields: Foo: Salesforce.SpecialObject: Bar """ with pytest.raises(exc.DataGenError, match="Bar"): generate(StringIO(recipe_data), {}, None)
def test_reference_really_wrong_type(self): yaml = """ - object: B count: 2 fields: A_ref: reference: 5""" with pytest.raises(DataGenError) as e: generate(StringIO(yaml)) assert "can't get reference to object" in str(e).lower()
def test_missing_orgname(self, sf): yaml = """ - plugin: snowfakery.standard_plugins.Salesforce.SalesforceQuery - object: Contact fields: AccountId: SalesforceQuery.random_record: Account """ with pytest.raises(DataGenError): generate(StringIO(yaml), {})
def test_i18n(self, write_row_mock): yaml = """ - object: foo fields: japanese_name: i18n_fake: locale: ja_JP fake: name""" generate(StringIO(yaml), {}) assert isinstance(row_values(write_row_mock, 0, "japanese_name"), str)
def test_top_field_unknown(self): yaml = """ - bobject: OBJ fields: first_name: fake: first_name """ with self.assertRaises(DataGenError): generate(StringIO(yaml), {}, None)
def test_reference_unknown_object(self): yaml = """ - object: B count: 2 fields: A_ref: reference: AA""" with pytest.raises(DataGenError) as e: generate(StringIO(yaml)) assert "cannot find" in str(e).lower()
def test_bogus_plugin(self): yaml = """ - plugin: tests.test_custom_plugins_and_providers.TestCustomPlugin - object: OBJ fields: service_name: saascrmlightning """ with pytest.raises(TypeError) as e: generate(StringIO(yaml), {}) assert "TestCustomPlugin" in str(e.value)
def test_secondary_field_unknown(self): yaml = """ - object: OBJ bfields: first_name: fake: first_name """ with pytest.raises(DataGenError): generate(StringIO(yaml), {}, None)
def test_missing_plugin(self): yaml = """ - plugin: xyzzy.test_custom_plugins_and_providers.TestCustomPlugin - object: OBJ fields: service_name: saascrmlightning """ with pytest.raises(DataGenImportError) as e: generate(StringIO(yaml), {}) assert "xyzzy" in str(e.value)
def test_fake_block_one_param(self, write_row_mock): yaml = """ - object: OBJ fields: country: fake.country_code: representation: alpha-2 """ generate(StringIO(yaml), {}) assert len(row_values(write_row_mock, 0, "country")) == 2
def test_fake_two_params_flat(self, write_row_mock): yaml = """ - object: OBJ fields: date: ${{fake.date(pattern="%Y-%m-%d", end_datetime=None)}} """ generate(StringIO(yaml), {}, None) date = row_values(write_row_mock, 0, "date") assert type(date) == str, write_row_mock.mock_calls assert len(date.split("-")) == 3, date
def test_faker_internals_are_invisible(self): yaml = """ - object: A fields: xyzzy: fake: seed """ with pytest.raises(exc.DataGenError) as e: generate(StringIO(yaml), {}, None) assert "seed" in str(e.value)
def test_did_you_mean(self, write_row_mock): yaml = """ - object: A fields: xyzzy: fake: frst_name """ with pytest.raises(exc.DataGenError) as e: generate(StringIO(yaml), {}, None) assert "first_name" in str(e.value)
def test_custom_faker_provider(self, write_row_mock): yaml = """ - plugin: faker_microservice.Provider - object: OBJ fields: service_name: fake: microservice """ generate(StringIO(yaml), {}) assert row_values(write_row_mock, 0, "service_name")
def test_weird_types(self): yaml = """ - plugin: tests.test_custom_plugins_and_providers.WrongTypePlugin # 2 - object: B #3 fields: #4 foo: #5 WrongTypePlugin.return_bad_type: 5 #6 """ with pytest.raises(DataGenError) as e: generate(StringIO(yaml)) assert 6 > e.value.line_num >= 3
def test_non_overlapping_dates(self, write_row_mock): yaml = """ - object: OBJ fields: date: date_between: start_date: today end_date: 2000-01-01 """ generate(StringIO(yaml), {}, None) assert row_values(write_row_mock, 0, "date") is None
def test_fake_two_params_nested(self, write_row_mock): yaml = """ - object: OBJ fields: date: fake.date_between: start_date: -10y end_date: today """ generate(StringIO(yaml), {}, None) assert row_values(write_row_mock, 0, "date").year
def test_error_handling(self, write_row_mock): yaml = """ - object: A fields: xyzzy: fake: xyzzy """ with pytest.raises(exc.DataGenError) as e: generate(StringIO(yaml), {}, None) assert "xyzzy" in str(e.value) assert "fake" in str(e.value)
def test_faker_kwargs(self, write_row_mock): yaml = """ - object: A fields: neg: fake.random_int: min: -5 max: -1 """ generate(StringIO(yaml), {}, None) assert -5 <= row_values(write_row_mock, 0, "neg") <= -1
def test_simple_parent_list_child(self, write_row): generate(StringIO(simple_parent_list), {}, None) a_values = find_row("A", {}, write_row.mock_calls) b_values = find_row("B", {}, write_row.mock_calls) id_a = a_values["id"] reference_b = a_values["B"] id_b = b_values["id"] reference_a = b_values["A_ref"] assert f"A({id_a})" == reference_a assert f"B({id_b})" == reference_b