Exemple #1
0
 def test_level_reporter(self):
     prefix = "Курс $course_id --> "
     postfix = "[$total]: $id_items"
     lr = LevelReporter()
     lr.report(
         fresh_level_entities,
         f"{prefix}Тестирование визуализации добавления новых уровней{postfix}",
     )
 def test_delete(self):
     before_levels = Level.objects.all()
     self.assertEqual(len(before_levels), 29)
     dca = DBLevelActions(reporter=LevelReporter())
     dca.delete(fresh_level_entities)
     after_levels = Level.objects.all()
     self.assertEqual(len(after_levels), 23)
    def test_update(self):
        update_ids = [x.id for x in fresh_level_entities]
        before_levels = Level.objects.all().filter(id__in=update_ids)
        self.assertEqual(
            [f"{x.id} -- {x.name}" for x in before_levels],
            [
                "1 -- New level",
                "2 -- New level",
                "3 -- New level",
                "52 -- 1 - 20",
                "137 -- Safari and Exotic Animals",
                "138 -- About Animals",
            ],
        )
        dca = DBLevelActions(reporter=LevelReporter())
        dca.update(fresh_level_entities)

        after_levels = Level.objects.all().filter(id__in=update_ids)
        self.assertEqual(
            [f"{x.id} -- {x.name}" for x in after_levels],
            [
                "1 -- New level",
                "2 -- New level",
                "3 -- New level",
                "52 -- New level",
                "137 -- Level 123-346",
                "138 -- New level",
            ],
        )
    def test_create(self):
        fresh_entities = [
            LevelEntity(id=11, number=1, course_id=1987730, name="test 1"),
            LevelEntity(id=21, number=2, course_id=1987730, name="test 2"),
            LevelEntity(id=31, number=3, course_id=1987730, name="test 3"),
            LevelEntity(id=41, number=4, course_id=1987730, name="test 4"),
            LevelEntity(id=51, number=5, course_id=1987730, name="test 5"),
        ]

        before_levels = Level.objects.all()
        expected_before_num_levels = 29
        self.assertEqual(len(before_levels), expected_before_num_levels)
        dca = DBLevelActions(reporter=LevelReporter())
        dca.create(fresh_entities)

        after_levels = Level.objects.all()
        expected_after_num_levels = expected_before_num_levels + len(
            fresh_entities)
        self.assertEqual(len(after_levels), expected_after_num_levels)
 def init(self):
     self.course = EmptyCourseActions(reporter=CourseReporter())
     self.level = EmptyLevelActions(reporter=LevelReporter())
     self.word = EmptyWordActions(reporter=WordReporter())
 def init(self):
     self.course = DBCourseActions(reporter=CourseReporter())
     self.level = DBLevelActions(reporter=LevelReporter())
     self.word = DBWordActions(reporter=WordReporter())
 def test_equal(self):
     before_levels = Level.objects.all()
     dca = DBLevelActions(reporter=LevelReporter())
     dca.equal(fresh_level_entities)
     after_levels = Level.objects.all()
     self.assertListEqual(list(before_levels), list(after_levels))