def test_get_split_names(self, mocker):
        """Test getting all split names."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        from_raw_mock = self._get_from_raw_mock(mocker)
        mocker.patch('splitio.models.splits.from_raw', new=from_raw_mock)

        split_1 = from_raw_mock({'name': 'some_split_1', 'trafficTypeName': 'user'})
        split_2 = from_raw_mock({'name': 'some_split_2', 'trafficTypeName': 'user'})
        storage.put(split_1)
        storage.put(split_2)

        assert set(storage.get_split_names()) == set(['some_split_1', 'some_split_2'])
        storage.remove('some_split_1')
        assert storage.get_split_names() == ['some_split_2']
Exemple #2
0
 def test_get_split_names(self, mocker):
     """Test getting all split names."""
     uwsgi = get_uwsgi(True)
     storage = UWSGISplitStorage(uwsgi)
     split_1 = mocker.Mock(spec=Split)
     split_1.to_json.return_value = '{"name": "split1"}'
     split_name_1 = mocker.PropertyMock()
     split_name_1.return_value = 'some_split_1'
     type(split_1).name = split_name_1
     split_2 = mocker.Mock(spec=Split)
     split_2.to_json.return_value = '{"name": "split2"}'
     split_name_2 = mocker.PropertyMock()
     split_name_2.return_value = 'some_split_2'
     type(split_2).name = split_name_2
     storage.put(split_1)
     storage.put(split_2)
     assert set(storage.get_split_names()) == set(['some_split_1', 'some_split_2'])
     storage.remove('some_split_1')
     assert storage.get_split_names() == ['some_split_2']
    def test_is_valid_traffic_type(self, mocker):
        """Test that traffic type validation works properly."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        from_raw_mock = self._get_from_raw_mock(mocker)
        mocker.patch('splitio.models.splits.from_raw', new=from_raw_mock)

        split_1 = from_raw_mock({'name': 'some_split_1', 'trafficTypeName': 'user'})
        storage.put(split_1)
        assert storage.is_valid_traffic_type('user') is True
        assert storage.is_valid_traffic_type('account') is False

        split_2 = from_raw_mock({'name': 'some_split_2', 'trafficTypeName': 'account'})
        storage.put(split_2)
        assert storage.is_valid_traffic_type('user') is True
        assert storage.is_valid_traffic_type('account') is True

        split_3 = from_raw_mock({'name': 'some_split_3', 'trafficTypeName': 'user'})
        storage.put(split_3)
        assert storage.is_valid_traffic_type('user') is True
        assert storage.is_valid_traffic_type('account') is True

        storage.remove('some_split_1')
        assert storage.is_valid_traffic_type('user') is True
        assert storage.is_valid_traffic_type('account') is True

        storage.remove('some_split_2')
        assert storage.is_valid_traffic_type('user') is True
        assert storage.is_valid_traffic_type('account') is False

        storage.remove('some_split_3')
        assert storage.is_valid_traffic_type('user') is False
        assert storage.is_valid_traffic_type('account') is False
    def test_store_retrieve_split(self, mocker):
        """Test storing and retrieving splits."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        from_raw_mock = self._get_from_raw_mock(mocker)
        mocker.patch('splitio.models.splits.from_raw', new=from_raw_mock)

        raw_split = {'name': 'some_split', 'trafficTypeName': 'user'}
        split = from_raw_mock(raw_split)

        from_raw_mock.reset_mock()  # clear mock calls so they don't interfere with the testing itself.
        storage.put(split)

        retrieved = storage.get('some_split')

        assert retrieved.name == split.name and retrieved.traffic_type_name == split.traffic_type_name
        assert from_raw_mock.mock_calls == [mocker.call(raw_split)]
        assert split.to_json.mock_calls == [mocker.call()]

        assert storage.get('nonexistant_split') is None

        storage.remove('some_split')
        assert storage.get('some_split') == None
Exemple #5
0
    def test_store_retrieve_split(self, mocker):
        """Test storing and retrieving splits."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        split = mocker.Mock(spec=Split)
        split.to_json.return_value = '{}'
        split_name = mocker.PropertyMock()
        split_name.return_value = 'some_split'
        type(split).name = split_name
        storage.put(split)

        from_raw_mock = mocker.Mock()
        from_raw_mock.return_value = 'ok'
        mocker.patch('splitio.models.splits.from_raw', new=from_raw_mock)
        retrieved = storage.get('some_split')

        assert retrieved == 'ok'
        assert from_raw_mock.mock_calls == [mocker.call('{}')]
        assert split.to_json.mock_calls == [mocker.call()]

        assert storage.get('nonexistant_split') is None

        storage.remove('some_split')
        assert storage.get('some_split') == None