Example #1
0
    def test_sql_convert_registration_relations(self,
                                                mock_sql_relations_array):
        # type: (MagicMock) -> None
        mock_sql_relations_array.side_effect = lambda *x: x

        # Arrange
        registration = {
            'states': {},
            'attributes': {},
            'relations': {
                'relation1': [],
                'relation2': []
            },
        }

        class_name = 'classname'

        # Act
        db.sql_convert_registration(registration, class_name)

        # Assert
        sql_state_array_args = mock_sql_relations_array.call_args_list
        self.assertIn(call('classname', {'relation1': [], 'relation2': []}),
                      sql_state_array_args)
Example #2
0
    def test_sql_convert_registration_variants(self,
                                               mock_adapt,
                                               mock_convert_variants):
        # type: (MagicMock) -> None
        mock_adapt.side_effect = lambda x: x
        mock_convert_variants.side_effect = lambda x: x

        # Arrange
        variants = ['variant1', 'variant2']
        registration = {
            'variants': variants,
            'states': {},
            'attributes': {},
            'relations': {},
        }

        class_name = 'classname'

        # Act
        db.sql_convert_registration(registration, class_name)

        # Assert
        mock_adapt.assert_called_with(variants)
        mock_convert_variants.assert_called_with(variants)
Example #3
0
    def test_sql_convert_registration_states(self, mock_get_state_names,
                                             mock_sql_relations_array,
                                             mock_sql_state_array):
        # type: (MagicMock, MagicMock, MagicMock) -> None
        mock_get_state_names.return_value = ['state1', 'state2']
        mock_sql_relations_array.return_value = []
        mock_sql_state_array.side_effect = lambda *x: x

        # Arrange
        registration = {
            'states': {'classnamestate1': 'val1',
                       'classnamestate3': 'val3',
                       'whatever': 'whatever'},
            'attributes': {},
            'relations': {}
        }

        class_name = 'classname'

        expected_result = {
            'states': [
                ('state1', 'val1', 'classname'),
                ('state2', None, 'classname')
            ],
            'attributes': [],
            'relations': []
        }

        # Act
        actual_result = db.sql_convert_registration(registration, class_name)

        # Assert
        sql_state_array_args = mock_sql_state_array.call_args_list
        self.assertIn(call('state1', 'val1', 'classname'),
                      sql_state_array_args)
        self.assertIn(call('state2', None, 'classname'), sql_state_array_args)
        self.assertEqual(2, len(sql_state_array_args))

        self.assertEqual(expected_result, actual_result)