def test_gen_alpha_3_3(self): """ @Test: Create alpha string with zero length @Feature: String Generator @Assert: String is not created due to value error """ with self.assertRaises(ValueError): gen_latin1(length=0)
def test_gen_latin1_8(self): """ @Test: Create latin1 string with alpha string length @Feature: String Generator @Assert: Latin1 string is not created due to value error """ with self.assertRaises(ValueError): gen_latin1(length='a')
def test_gen_latin1_1(self): """ @Test: Create latin1 string of varied length @Feature: String Generator @Assert: Latin1 string is generated """ result = gen_latin1() self.assertTrue(len(result) > 0, "Empty string was generated")
def test_gen_latin1_1(self): """ @Test: Create latin1 string of varied length @Feature: String Generator @Assert: Latin1 string is generated """ result = gen_latin1() self.assertTrue( len(result) > 0, "Empty string was generated")
def test_gen_latin1_2(self): """ @Test: Create latin1 string of fixed length @Feature: String Generator @Assert: Latin1 string with fixed length is created """ for length in range(2, 12, 2): result = gen_latin1(length) self.assertEqual( len(result), length, "Generate string does not have the expected length")
class TestExport(object): """Unittests related to data export.""" @pytest.mark.parametrize('format', ['html', fauxfactory.gen_latin1()]) def test_invalid_format(self, controler_with_logging, format, mocker): """Make sure that passing an invalid format exits prematurely.""" controler = controler_with_logging with pytest.raises(ClickException): hamster_cli._export(controler, format, None, None) def test_csv(self, controler, controler_with_logging, mocker): """Make sure that a valid format returns the apropiate writer class.""" hamsterlib.reports.TSVWriter = mocker.MagicMock() hamster_cli._export(controler, 'csv', None, None) assert hamsterlib.reports.TSVWriter.called def test_ical(self, controler, controler_with_logging, mocker): """Make sure that a valid format returns the apropiate writer class.""" hamsterlib.reports.ICALWriter = mocker.MagicMock() hamster_cli._export(controler, 'ical', None, None) assert hamsterlib.reports.ICALWriter.called def test_xml(self, controler, controler_with_logging, mocker): """Make sure that passing 'xml' as format parameter returns the apropiate writer class.""" hamsterlib.reports.XMLWriter = mocker.MagicMock() hamster_cli._export(controler, 'xml', None, None) assert hamsterlib.reports.XMLWriter.called def test_with_start(self, controler, controler_with_logging, tmpdir, mocker): """Make sure that passing a end date is passed to the fact gathering method.""" controler.facts.get_all = mocker.MagicMock() path = os.path.join(tmpdir.mkdir('report').strpath, 'report.csv') hamsterlib.reports.TSVWriter = mocker.MagicMock( return_value=hamsterlib.reports.TSVWriter(path)) start = fauxfactory.gen_datetime() hamster_cli._export(controler, 'csv', start, None) args, kwargs = controler.facts.get_all.call_args assert kwargs['start'] == start def test_with_end(self, controler, controler_with_logging, tmpdir, mocker): """Make sure that passing a end date is passed to the fact gathering method.""" controler.facts.get_all = mocker.MagicMock() path = os.path.join(tmpdir.mkdir('report').strpath, 'report.csv') hamsterlib.reports.TSVWriter = mocker.MagicMock( return_value=hamsterlib.reports.TSVWriter(path)) end = fauxfactory.gen_datetime() hamster_cli._export(controler, 'csv', None, end) args, kwargs = controler.facts.get_all.call_args assert kwargs['end'] == end
@pytest.fixture def fact_manager(request, live_service): """Provide a convenient object hook to our hamster-dbus service.""" daemon, bus = live_service object_ = bus.get_object('org.projecthamster.HamsterDBus', '/org/projecthamster/HamsterDBus/FactManager') interface = dbus.Interface( object_, dbus_interface='org.projecthamster.HamsterDBus.FactManager1') return interface # Data @pytest.fixture(params=[ fauxfactory.gen_alpha(), fauxfactory.gen_utf8(), fauxfactory.gen_latin1(), fauxfactory.gen_cjk(), ]) def category_name_parametrized(request): """Provide a huge variety of possible ``Category.name`` strings.""" return request.param @pytest.fixture(params=[ fauxfactory.gen_alpha(), fauxfactory.gen_utf8(), fauxfactory.gen_latin1(), fauxfactory.gen_cjk(), ]) def activity_name_parametrized(request): """Provide a huge variety of possible ``Activity.name`` strings."""
datetime.time(17, 22, 0), )) def day_start_parametrized(request): """Return a parametrized day_start value.""" return request.param @pytest.fixture(params=(0, 1, 30, 60)) def fact_min_delta_parametrized(request): """Return a parametrized fact_min_delta value.""" return request.param @pytest.fixture(params=( fauxfactory.gen_utf8(), fauxfactory.gen_latin1(), )) def tmpfile_path_parametrized(request, tmpdir): """Return a parametrized tmpfile_path value.""" return tmpdir.mkdir(request.param).join('tmpfile.hamster') @pytest.fixture(params=( 'sqlite', )) def db_engine_parametrized(request): """Return a parametrized db_engine value.""" return request.param @pytest.fixture(params=(
return fauxfactory.gen_utf8() @pytest.fixture def db_user(request): """Return a randomized database username.""" return fauxfactory.gen_utf8() @pytest.fixture def db_password(request): """Return a randomized database password.""" return fauxfactory.gen_utf8() @pytest.fixture(params=(fauxfactory.gen_latin1(), fauxfactory.gen_ipaddr())) def db_host(request): """Return a randomized database username.""" return request.param @pytest.fixture def db_port(request): """Return a randomized database port.""" return text_type(fauxfactory.gen_integer(min_value=0, max_value=65535)) @pytest.fixture def tmp_fact(controler_with_logging, fact): """Fixture that ensures there is a ``ongoing fact`` file present at the expected place.""" fact.end = None