Exemplo n.º 1
0
    def test_log_debug_instance_details(self, mock_logger_debug):
        """
        Test logger`s debug output occurs installation details.
        """
        ReceiveInstallationStatistics().log_debug_instance_details(
            self.received_data)

        expected_logger_debugs = [
            call((json.dumps(self.received_data, sort_keys=True, indent=4)), ),
        ]

        self.assertEqual(expected_logger_debugs,
                         mock_logger_debug.call_args_list)
Exemplo n.º 2
0
    def test_get_students_per_country(self):
        """
        Test get_students_per_country method correctly return students per country value.
        """
        active_students_amount_day = 40
        students_per_country = "{\"RU\": 10, \"CA\": 5, \"UA\": 20}"

        result = ReceiveInstallationStatistics().get_students_per_country(
            students_per_country, active_students_amount_day)

        expected_students_per_country = "{\"RU\": 10, \"CA\": 5, \"UA\": 20, \"null\": 5}"

        self.assertDictContainsSubset(
            json.loads(expected_students_per_country), json.loads(result))
Exemplo n.º 3
0
    def test_update_students_with_no_country(self):
        """
        Verify that update_students_with_no_country method correctly update students without country amount.
        """
        active_students_amount = 40
        students_per_country_before_update = {'RU': 10, 'CA': 5, 'UA': 20}

        result = ReceiveInstallationStatistics.update_students_with_no_country(
            active_students_amount, students_per_country_before_update)

        students_per_country_before_update.update({'null': 5})
        expected_students_per_country_after_update = students_per_country_before_update

        self.assertEqual(expected_students_per_country_after_update, result)
Exemplo n.º 4
0
    def test_installation_stats_creation_occurs(
            self, mock_edx_installation_objects_get,
            mock_installation_statistics_installation_objects_create):
        """
        Verify that installation statistic creation was successfully called via `objects.create` method.
        """
        edx_installation_object = EdxInstallationFactory()

        mock_edx_installation_objects_get.return_value = edx_installation_object

        ReceiveInstallationStatistics().create_instance_data(
            self.received_data, self.access_token)

        # Assertion `mock_installation_statistics_installation_objects_create.assert_called_once_with()` does not work.
        # I did debug, all passed arguments as `edx_installation_object` and `installation_statistics` equal
        # the same parameters in `create_instance_data` method. But tests did not passed.
        mock_installation_statistics_installation_objects_create.assert_called_once(
        )
Exemplo n.º 5
0
    def test_extend_stats_occurs(
        self,
        mock_edx_installation_objects_get,
        mock_receive_installation_statistics_extend_stats_to_enthusiast,
    ):
        """
        Verify that extend_stats_to_enthusiast method occurs if edx installation statistics level is enthusiast.
        """
        edx_installation_object = EdxInstallationFactory()

        mock_edx_installation_objects_get.return_value = edx_installation_object

        ReceiveInstallationStatistics().create_instance_data(
            self.received_data, self.access_token)

        mock_receive_installation_statistics_extend_stats_to_enthusiast.assert_called_once_with(
            self.received_data, self.installation_statistics,
            edx_installation_object)
Exemplo n.º 6
0
    def test_extend_stats_if_needed(self):
        """
        Verify that extend_stats_to_enthusiast method extends edx installation fields.
        """
        edx_installation_object = EdxInstallationFactory(platform_name=None,
                                                         platform_url=None,
                                                         latitude=None,
                                                         longitude=None)

        ReceiveInstallationStatistics().extend_stats_to_enthusiast(
            self.received_data, self.installation_statistics,
            edx_installation_object)

        extended_edx_installation_object_attributes = EdxInstallation.objects.first(
        ).__dict__

        self.assertDictContainsSubset(
            self.enthusiast_edx_installation,
            extended_edx_installation_object_attributes)
Exemplo n.º 7
0
    def test_extend_stats_does_not_occur(
        self,
        mock_edx_installation_objects_get,
        mock_receive_installation_statistics_extend_stats_to_enthusiast,
    ):
        """
        Verify that extend_stats_to_enthusiast method does not occurs if edx installation statistics level is paranoid.
        """
        self.received_data['statistics_level'] = 'paranoid'

        edx_installation_object = EdxInstallationFactory()

        mock_edx_installation_objects_get.return_value = edx_installation_object

        ReceiveInstallationStatistics().create_instance_data(
            self.received_data, self.access_token)

        self.assertEqual(
            0, mock_receive_installation_statistics_extend_stats_to_enthusiast.
            call_count)
Exemplo n.º 8
0
    def test_logger_debug_occurs_if_stats_was_created(
            self, mock_edx_installation_objects_get, mock_logger_debug):
        """
        Test logger`s debug output occurs if installation was created.
        """
        edx_installation_object = EdxInstallationFactory()

        mock_edx_installation_objects_get.return_value = edx_installation_object

        ReceiveInstallationStatistics().create_instance_data(
            self.received_data, self.access_token)

        expected_logger_debug = [
            (('Corresponding data was created in OLGA database.'), ),
        ]

        # Factory Boy`s BaseFactory and LazyStub loggers occurs during method's logger occurs.
        # So totally 5 loggers occurs, but only one last belongs to `create_instance_data` method.
        # https://factoryboy.readthedocs.io/en/latest/#debugging-factory-boy
        self.assertEqual(expected_logger_debug,
                         mock_logger_debug.call_args_list[-1])