Exemple #1
0
 def test_import_export_functions(self):
     # More data is needed for a meaningful test, for this and the following.
     # Whenever a new exported type is added, samples of it should be added
     # here, as well.
     for data_type in sheet.models.EXPORTABLE_MODELS:
         logger.info("Import test for %s", data_type)
         exported_data = marshal.csv_export(getattr(sheet.models, data_type))
         marshal.import_text(exported_data)
Exemple #2
0
    def test_import_with_deps(self):
        csv_data = u"""\
Skill
name,tech_level,description,notes,can_be_defaulted,is_specialization,skill_cost_0,skill_cost_1,skill_cost_2,skill_cost_3,type,stat,required_edges,required_skills
Jackadeering,all,,,TRUE,TRUE,0,2,,,Combat,MOV,,Nutcasing
Throw,all,,,TRUE,TRUE,0,2,,,Combat,MOV,,Unarmed combat
Unarmed combat,all,,,TRUE,TRUE,0,2,,,Combat,MOV,,Jackadeering
Nutcasing,all,,,TRUE,TRUE,0,2,,,Combat,MOV,,
"""
        marshal.import_text(csv_data.encode('utf-8'))
        self.assertListEqual(
            sorted([sk.name for sk in sheet.models.Skill.objects.all()]),
            sorted(["Nutcasing", "Throw", "Unarmed combat", "Jackadeering"]))
Exemple #3
0
    def test_import_with_self_loops(self):
        """
        Verify that importing with selfloops works.
        """
        self_loop = u"""\
Skill
name,tech_level,description,notes,can_be_defaulted,is_specialization,skill_cost_0,skill_cost_1,skill_cost_2,skill_cost_3,type,stat,required_edges,required_skills
Nutcasing,all,,,TRUE,TRUE,0,2,,,Combat,MOV,,Nutcasing
"""
        marshal.import_text(self_loop.encode('utf-8'))
        self.assertListEqual(
            [sk.name for sk in sheet.models.Skill.objects.all()],
            ["Nutcasing"])
        skill = sheet.models.Skill.objects.get(name="Nutcasing")
        self.assertEqual(len(skill.required_skills.all()), 0)
Exemple #4
0
    def test_export_ammunition(self):
        marshal.import_text(self.ammo_csv_data)

        csv_data = marshal.csv_export(sheet.models.Ammunition)
        reader = csv.reader(self.stream_type(csv_data))
        data_type = next(reader)
        self.assertEqual(data_type[0], "Ammunition")

        header = next(reader)
        data_row = next(reader)

        idx = header.index("label")
        self.assertGreaterEqual(idx, 0, msg="Required column should be found")
        # Correct ammunition_types should be available.
        self.assertEqual(data_row[idx], "9Pb+")

        idx = header.index("id")
        self.assertGreaterEqual(idx, 0, msg="Required column should be found")
Exemple #5
0
 def test_import_semicolon_csv_should_work(self):
     marshal.import_text(open(os.path.join(os.path.dirname(__file__), 'win-excel-with-semicolons-utf8.csv'), 'rb').read())
Exemple #6
0
 def test_import_ammunition(self):
     marshal.import_text(self.ammo_csv_data)
     ammo = sheet.models.Ammunition.objects.filter(label='9Pb+')
     self.assertEqual(ammo[0].label, "9Pb+")
Exemple #7
0
 def test_import_firearms(self):
     marshal.import_text(self.firearm_csv_data)
     firearm = sheet.models.BaseFirearm.objects.get(name="Glock 19")
     # Import should create the ammunition types.
     self.assertListEqual(sorted(["9Pb", "9Pb+"]),
                          sorted(firearm.get_ammunition_types()))