Example #1
0
 def test_counts(self, write_row):
     generate_cli.callback(
         yaml_file=sample_yaml,
         target_number=("Account", 2),
         option={},
         debug_internals=None,
         generate_cci_mapping_file=None,
     )
     assert write_row.mock_calls == [
         mock.call(
             "Account",
             {
                 "id": 1,
                 "name": "Default Company Name",
                 "ShippingCountry": "Canada"
             },
         ),
         mock.call(
             "Account",
             {
                 "id": 2,
                 "name": "Default Company Name",
                 "ShippingCountry": "Canada"
             },
         ),
     ]
Example #2
0
 def test_with_debug_flags_on(self, write_row):
     generate_cli.callback(
         yaml_file=sample_yaml,
         option={},
         debug_internals=True,
         mapping_file=None,
     )
Example #3
0
 def test_from_cli(self):
     x = StringIO()
     with redirect_stdout(x):
         generate_cli.callback(yaml_file=sample_yaml, output_format="json")
     data = json.loads(x.getvalue())
     print(data)
     assert data == sample_output
Example #4
0
 def test_with_option(self, write_row):
     with pytest.warns(UserWarning):
         generate_cli.callback(
             yaml_file=sample_yaml,
             option={"xyzzy": "abcd"},
             debug_internals=None,
             generate_cci_mapping_file=None,
         )
Example #5
0
    def test_external_output_stream(self):
        x = StringIO()
        with redirect_stdout(x):
            generate_cli.callback(yaml_file=sample_yaml,
                                  output_format="package1.TestOutputStream")
        assert (x.getvalue() == """A - {'id': 1, 'B': 'B(1)'}
B - {'id': 1, 'A': 'A(1)'}
""")
Example #6
0
 def test_with_bad_dburl(self, write_row):
     with pytest.raises(Exception):
         generate_cli.callback(
             yaml_file=sample_yaml,
             option={},
             dburl="xyzzy:////foo/bar/baz.com",
             debug_internals=None,
             generate_cci_mapping_file=None,
         )
Example #7
0
 def test_from_cli__unknown_extension(self, capsys):
     with pytest.raises(ClickException) as e:
         generate_cli.callback(
             yaml_file=str(sample_yaml),
             target_number=("Account", 5),
             output_format="xyzzy",
             output_files=["foo.txt"],
         )
     assert "xyzzy" in str(e.value)
Example #8
0
 def test_exception_with_debug_flags_off(self, write_row):
     with named_temporary_file_path(suffix=".yml") as t:
         with pytest.raises(ClickException):
             generate_cli.callback(
                 yaml_file=bad_sample_yaml,
                 option={},
                 debug_internals=False,
                 generate_cci_mapping_file=t,
             )
             assert yaml.safe_load(t)
Example #9
0
 def test_from_cli(self):
     x = StringIO()
     with redirect_stdout(x):
         generate_cli.callback(yaml_file=sample_yaml, output_format="json")
     data = json.loads(x.getvalue())
     assert data == [{
         "_table": "Account",
         "id": 1,
         "name": "Default Company Name",
         "ShippingCountry": "Canada",
     }]
Example #10
0
    def test_external_output_stream_yaml(self):
        x = StringIO()
        with redirect_stdout(x):
            generate_cli.callback(yaml_file=sample_yaml,
                                  output_format="examples.YamlOutputStream")
        expected = """- object: A
  nickname: row_1
  fields:
    id: 1
    B:
      reference: row_1
- object: B
  nickname: row_1
  fields:
    id: 1
    A:
      reference: row_1
"""
        print(x.getvalue())
        assert x.getvalue() == expected
Example #11
0
 def test_external_output_stream__failure(self):
     with pytest.raises(ClickException, match="no.such.output.Stream"):
         generate_cli.callback(
             yaml_file=sample_yaml, output_format="no.such.output.Stream"
         )
 def test_from_cli(self):
     x = StringIO()
     with redirect_stdout(x):
         generate_cli.callback(
             yaml_file=sample_yaml, output_format="json", output_files=["-"]
         )