Esempio n. 1
0
def cargo_handler(args):
    #TODO this should be moved to a config file
    dirlist = [os.path.dirname(__file__), os.pardir, 'var', 'data']
    varpath = os.path.abspath(os.sep.join(dirlist))

    c = CargoService(varpath)
    if args.action == 'export':
        c.do_export(args.filename)

    if args.action == 'import':
        c.do_import(args.filename)
Esempio n. 2
0
class TestFileChecks(unittest.TestCase):

    def setUp(self):
        self.cargo = CargoService(thedir)
        self.cargo.pattern_mapper = MockedDataMapper()

    def test_do_import_valid_filetypes_returns_true(self):
        self.assertTrue(self.cargo.do_import('dummy_import.xml'))
        self.assertTrue(self.cargo.do_import('dummy_import.json'))

    def test_do_import_unsupported_filetypes_raises(self):
        with self.assertRaises(errors.ValidationError):
            self.cargo.do_import('dummy_import.doc')

    def test_do_import_screams_filenotfound(self):
        with self.assertRaises(IOError):
            self.assertTrue(self.cargo._checkfile('rickrolled.xml'))
Esempio n. 3
0
class TestCargoXML(unittest.TestCase):

    def setUp(self):
        self.cargo = CargoService(thedir)

        mapper = MockedMapper()
        mapper.dataMapper = XMLMapper()
        self.cargo.pattern_mapper = mapper

    def test_import(self):
        self.cargo.do_import('dummy_import.xml')
        self.assertEqual(self.cargo.size, 3)

    def test_patterns_loaded_by_import(self):
        self.cargo.do_import('dummy_import.xml')
        pattern = self.cargo.patterns[0]
        self.assertEqual(pattern.name, "BuilderPattern")
        self.assertEqual(pattern.problem, "problem1 dork")
        self.assertEqual(pattern.solution, "solution1 dork")
        self.assertEqual(pattern.context, "creational")
        self.assertEqual(pattern.consequences, "consequences1 dork")
        self.assertEqual(pattern.image, "foobar.png")
Esempio n. 4
0
 def setUp(self):
     self.cargo = CargoService(thedir)
     self.cargo.pattern_mapper = MockedDataMapper()
Esempio n. 5
0
    def setUp(self):
        self.cargo = CargoService(thedir)

        mapper = MockedMapper()
        mapper.dataMapper = XMLMapper()
        self.cargo.pattern_mapper = mapper