コード例 #1
0
    def test_alter_circle_dimension_filter_not_alter_others_circle_dimension_filter(
        self, ):
        client = get_logged_superuser_client()
        person = create_users(1)[0]
        first_circle = CircleFactory.create()
        second_circle = CircleFactory.create()
        first_circle_topic = TopicFactory.create(circle=first_circle)
        second_circle_topic = TopicFactory.create(circle=second_circle)
        first_circle_dimension_populated = DimensionFactory.create(
            name="dimension_1", topic=first_circle_topic)
        first_circle_dimension_empty = DimensionFactory.create(
            name="dimension_2", topic=first_circle_topic)
        second_circle_dimension = DimensionFactory.create(
            name="dimension_1", topic=second_circle_topic)
        first_circle_score = ScoreFactory.create(
            dimension=first_circle_dimension_populated, person=person)
        second_circle_score = ScoreFactory.create(
            dimension=second_circle_dimension, person=person)

        response = client.get(
            "/",
            {
                f"topic_dimension_eq_{first_circle.id}":
                f"{first_circle_dimension_empty.id}"
            },
        )

        self.assertContains(
            response,
            f'{first_circle_topic.name} : <span class="badge dark-grey-bg text-white">0</span>',
        )
        self.assertContains(
            response,
            f'{second_circle_topic.name} : <span class="badge dark-grey-bg text-white">1</span>',
        )
コード例 #2
0
    def test_alter_circle_value_filter_not_alter_others_circle_value_filter(
            self):
        client = get_logged_superuser_client()
        person = create_users(1)[0]
        first_circle = CircleFactory.create()
        second_circle = CircleFactory.create()
        first_circle_topic = TopicFactory.create(circle=first_circle)
        second_circle_topic = TopicFactory.create(circle=second_circle)
        first_circle_dimension = DimensionFactory.create(
            topic=first_circle_topic)
        second_circle_dimension = DimensionFactory.create(
            topic=second_circle_topic)
        first_circle_score = ScoreFactory.create(
            dimension=first_circle_dimension, value=3, person=person)
        second_circle_score = ScoreFactory.create(
            dimension=second_circle_dimension, value=3, person=person)

        response = client.get("/", {f"topic_value_gt_{first_circle.id}": 4})

        self.assertContains(
            response,
            f'{first_circle_topic.name} : <span class="badge dark-grey-bg text-white">0</span>',
        )
        self.assertContains(
            response,
            f'{second_circle_topic.name} : <span class="badge dark-grey-bg text-white">1</span>',
        )
コード例 #3
0
    def test_different_circles_can_have_same_topic(self):
        circle = CircleFactory.create(name="testCircle")
        circle_two = CircleFactory.create(name="testCircle_two")
        topic_name = "testTopic"

        topic = Topic(name=topic_name, circle=circle)
        topic.save()
        topic_double = Topic(name=topic_name, circle=circle_two)
        topic_double.save()

        self.assertEqual(topic_double.name, topic.name)
コード例 #4
0
    def test_parse_xlsx_correct_import_datas_from_dataframe(self):
        circle = CircleFactory.create()

        result = ExcelUploadUseCase.Parser().parse_xlsx(
            "clusters/tests/test_models/excel_test_file/cl_example.xlsx",
            Circle.objects.all(),
        )
        expected_result = {
            "user_name":
            "user_name",
            "user_surname":
            "user_surname",
            "circles": [[
                ("Circle", "topic1", "dimension1", 2),
                ("Circle", "topic1", "dimension2", 1),
                ("Circle", "topic1", "dimension3", 2),
                ("Circle", "topic1", "dimension4", 1),
                ("Circle", "topic2", "dimension1", 4),
                ("Circle", "topic2", "dimension2", 4),
                ("Circle", "topic2", "dimension3", 4),
                ("Circle", "topic2", "dimension4", 4),
            ]],
        }

        self.assertEqual(result[0]["user_name"], expected_result["user_name"])
        self.assertEqual(result[0]["user_surname"],
                         expected_result["user_surname"])
        self.assertListEqual(result[0]["circles"], expected_result["circles"])
コード例 #5
0
    def test_index_with_no_topic_in_circle_print_message(self):
        client = get_logged_superuser_client()
        circle = CircleFactory.create()
        circle.save()

        response = client.get("/")
        self.assertContains(response, "No Topics available.")
コード例 #6
0
    def test_index_view_shows_all_topics_of_different_circles(self):
        client = get_logged_superuser_client()
        first_circle = CircleFactory.create()
        second_circle = CircleFactory.create()
        first_circle_topics = [
            TopicFactory.create(circle=first_circle) for _ in range(3)
        ]
        second_circle_topics = [
            TopicFactory.create(circle=second_circle) for _ in range(3)
        ]

        response = client.get("/")

        topics_names = [topic.name for topic in first_circle_topics
                        ] + [topic.name for topic in second_circle_topics]
        for topic_name in topics_names:
            self.assertContains(response, topic_name)
コード例 #7
0
    def test_index_view_shows_all_circle_names(self):
        client = get_logged_superuser_client()
        circles = [CircleFactory.create() for _ in range(4)]
        circles_names = [circle.name for circle in circles]

        response = client.get("/")

        for name in circles_names:
            self.assertContains(response, name)
コード例 #8
0
    def test_circle_cant_have_same_topic_twice(self):
        circle = CircleFactory.create(name="testCircle")
        topic_name = "testTopic"

        topic = Topic(name=topic_name, circle=circle)
        topic.save()

        with self.assertRaises(IntegrityError):
            topic_double = Topic(name=topic_name, circle=circle)
            topic_double.save()
コード例 #9
0
    def test_index_shows_cirle_and_topics_names(self):
        client = get_logged_superuser_client()
        topic_name = "testTopic"
        circle_name = "testCircle"
        circle = CircleFactory.create(name=circle_name)
        topic = TopicFactory.create(name=topic_name, circle=circle)

        response = client.get("/")
        self.assertContains(response, circle_name)
        self.assertContains(response, topic_name)
コード例 #10
0
    def test_topic_cant_have_same_dimension_twice(self):
        circle = CircleFactory.create(name="testCircle")
        topic = TopicFactory.create(name="testTopic", circle=circle)
        dimension_name = "testDimension"

        dimension = Dimension(name=dimension_name, topic=topic)
        dimension.save()

        with self.assertRaises(IntegrityError):
            dimension_double = Dimension(name=dimension_name, topic=topic)
            dimension_double.save()
コード例 #11
0
    def test_different_topics_can_have_same_dimension(self):
        circle = CircleFactory.create(name="testCircle")
        topic = TopicFactory.create(name="testTopic", circle=circle)
        topic_two = TopicFactory.create(name="testTopic_two", circle=circle)
        dimension_name = "testDimension"

        dimension = Dimension(name=dimension_name, topic=topic)
        dimension.save()
        dimension_double = Dimension(name=dimension_name, topic=topic_two)
        dimension_double.save()

        self.assertEqual(dimension.name, dimension_double.name)
コード例 #12
0
    def test_count_people_in_topic_return_expected_value(self):
        circle = CircleFactory.create()
        topic = TopicFactory(circle=circle)
        dimension = DimensionFactory(topic=topic)
        dimension.save()
        people = create_users(2)

        score_first = Score(person=people[0], dimension=dimension, value=0)
        score_first.save()
        score_second = Score(person=people[1], dimension=dimension, value=1)
        score_second.save()

        index = IndexView()
        value = index.count_people_in_topic(topic)

        self.assertEqual(value, 1)
コード例 #13
0
    def test_manage_view_upload_with_bad_circle_in_excel(self):
        client = get_logged_superuser_client()
        user = UserFactory.build(
            username="******",
            first_name="user_name",
            last_name="user_surname",
            password="******",
        )
        user.save()
        circle = CircleFactory.create(name="Circle_wrong")

        with open("clusters/tests/test_models/excel_test_file/cl_example.xlsx",
                  "rb") as xlsx_file:
            response = client.post("/manage/", {"file": xlsx_file})

        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(len(messages), 1)
        self.assertEqual(
            str(messages[0]),
            "Consistency Error: Circle <Circle> in xlsx file does not exists!",
        )
コード例 #14
0
    def test_filtered_view_shows_only_selected_dimensions_score(self):
        client = get_logged_superuser_client()
        circle = CircleFactory.create()
        topic = TopicFactory.create(name="topic", circle=circle)
        dimension_one = DimensionFactory.create(name="dimension_one",
                                                topic=topic)
        dimension_two = DimensionFactory.create(name="dimension_two",
                                                topic=topic)
        people = create_users(2)

        score_first = Score(person=people[0], dimension=dimension_one, value=5)
        score_first.save()
        score_second = Score(person=people[1],
                             dimension=dimension_two,
                             value=5)
        score_second.save()

        response = client.get(
            "/", {f"topic_dimension_eq_{circle.id}": dimension_one.id})
        self.assertContains(
            response,
            'topic : <span class="badge dark-grey-bg text-white">1</span>')
コード例 #15
0
    def test_retrieve_object_ignoring_case(self):
        user = User(username="******",
                    first_name="mario",
                    last_name="rossi",
                    password="******")
        user.save()
        circle = CircleFactory.create(name="circle")
        topics = [
            TopicFactory.create(name=f"Topic{i}", circle=circle)
            for i in range(1, 3)
        ]
        dimensions1 = [
            DimensionFactory.create(name=f"diMension{i}", topic=topics[0])
            for i in range(1, 5)
        ]
        dimensions2 = [
            DimensionFactory.create(name=f"dimenSion{i}", topic=topics[1])
            for i in range(1, 5)
        ]

        with open(
                "clusters/tests/test_models/excel_test_file/cl_example_2.xlsx",
                "rb") as xlsx_file:
            ExcelUploadUseCase(
                UserRepository(),
                CircleRepository(),
                ScoreRepository(),
                TopicRepository(),
                DimensionRepository(),
                TransactionManager(),
                MockListener(),
            ).uploadFile(xlsx_file)

        scores = Score.objects.all()

        self.assertTrue(len(scores) > 0)
コード例 #16
0
    def test_manage_view_upload_file_with_not_existing_dimension_shows_error_message(
        self, ):
        client = get_logged_superuser_client()
        user = UserFactory.build(
            username="******",
            first_name="user_name",
            last_name="user_surname",
            password="******",
        )
        user.save()
        circle = CircleFactory.create(name="Circle")
        topic_one = TopicFactory.create(name="topic1", circle=circle)
        topic_two = TopicFactory.create(name="topic2", circle=circle)

        with open("clusters/tests/test_models/excel_test_file/cl_example.xlsx",
                  "rb") as xlsx_file:
            response = client.post("/manage/", {"file": xlsx_file})

        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(len(messages), 1)
        self.assertEqual(
            str(messages[0]),
            "Consistency Error: Dimension <dimension1> in xlsx file does not exists!",
        )