Beispiel #1
0
 def test_get_abs_location_returns_rel_loc_if_not_in_dev_environment(self):
     self.useFixture(ImportErrorFixture('maastesting', 'root'))
     static_root = factory.make_string()
     self.patch(settings, 'STATIC_ROOT', static_root)
     rel_location = os.path.join(factory.make_string(),
                                 factory.make_string())
     expected_location = os.path.join(static_root, rel_location)
     observed = get_absolute_location(location=rel_location)
     self.assertEqual(expected_location, observed)
Beispiel #2
0
 def test__not_available_in_production(self):
     self.useFixture(ImportErrorFixture("maasserver.testing", "sampledata"))
     self.patch(sampledata, "populate")
     with CaptureStandardIO() as stdio:
         self.assertRaises(SystemExit, call_command, "generate_sample_data")
     self.assertThat(sampledata.populate, MockNotCalled())
     self.assertThat(stdio.getOutput(), Equals(""))
     self.assertThat(
         stdio.getError(),
         MatchesRegex(
             "Sample data generation is available only in development "
             "and test environments.\n\\s*"))
Beispiel #3
0
 def test_import_restores_original__import__(self):
     __real_import = builtins.__import__
     with ImportErrorFixture('maastesting', 'root'):
         self.assertNotEqual(
             __real_import,
             builtins.__import__,
             'ImportErrorFixture did not properly '
             'patch __builtin__.__import__')
     self.assertEqual(
         __real_import,
         builtins.__import__,
         'ImportErrorFixture did not properly restore '
         'the original __builtin__.__import__ upon cleanup')
Beispiel #4
0
 def test_import_restores_original__import__(self):
     __real_import = builtins.__import__
     with ImportErrorFixture("maastesting", "root"):
         self.assertNotEqual(
             __real_import,
             builtins.__import__,
             "ImportErrorFixture did not properly "
             "patch __builtin__.__import__",
         )
     self.assertEqual(
         __real_import,
         builtins.__import__,
         "ImportErrorFixture did not properly restore "
         "the original __builtin__.__import__ upon cleanup",
     )
Beispiel #5
0
 def test_is_dev_environment_returns_false(self):
     self.useFixture(ImportErrorFixture('maastesting', 'root'))
     self.assertFalse(is_dev_environment())
Beispiel #6
0
 def test_import_targeted_module_unsuccessfull(self):
     self.useFixture(ImportErrorFixture("maastesting", "root"))
     with ExpectedException(ImportError):
         from maastesting import root  # noqa
Beispiel #7
0
 def test_import_non_targeted_module_successfull(self):
     self.useFixture(ImportErrorFixture("maastesting", "root"))
     from maastesting import bindir  # noqa