Exemplo n.º 1
0
    def test_profile_context(self, tcex):
        """Test profile contexts

        Args:
            tcex (TcEx, fixture): An instantiated instance of TcEx object.
        """
        default_args = {}
        feature = 'PyTest'
        name = f'pytest-{randint(1000, 9999)}'

        # initialize profile
        profile = Profile(default_args=default_args,
                          feature=feature,
                          name=name,
                          redis_client=tcex.redis_client)

        # add profile
        profile.add()

        # test context
        context = str(uuid4())
        profile.add_context(context)

        # assert context
        assert profile.context_tracker == [context]

        # clear context
        profile.clear_context(context)
        profile._context_tracker = []

        # assert context
        assert profile.context_tracker == []

        # cleanup
        os.remove(profile.filename)
Exemplo n.º 2
0
    def test_profile_add(self):
        """Test adding a profile.

        {
          "exit_codes": [
            0
          ],
          "exit_message": null,
          "inputs": {
            "optional": {
              "my_multi": [
                "one",
                "two"
              ]
            },
            "required": {
              "my_bool": false
            }
          },
          "options": {
            "autostage": {
              "enabled": false,
              "only_inputs": null
            },
            "session": {
              "blur": [],
              "enabled": false
            }
          },
          "outputs": null,
          "stage": {
            "kvstore": {}
          }
        }

        Args:
            tcex (TcEx, fixture): An instantiated instance of TcEx object.
        """
        default_args = {}
        feature = 'PyTest'
        name = f'pytest-{randint(1000, 9999)}'

        # initialize profile
        profile = Profile(default_args=default_args,
                          feature=feature,
                          name=name)

        # add profile
        profile.add()

        # load profile from disk
        profile_data = self.load_profile(f'{name}.json')

        # assert JSON file matches expected values
        assert profile_data.get('exit_codes') == [0]
        assert profile_data.get('exit_message') is None
        # inputs must match those defined in mock_app.py
        for k, _ in profile_data.get('inputs', {}).get('optional', {}).items():
            if k == 'my_multi':
                break
        else:
            assert False, 'Key my_multi not found in inputs, did someone change inputs in mock App?'
        for k, _ in profile_data.get('inputs', {}).get('required', {}).items():
            if k == 'my_bool':
                break
        else:
            assert False, 'Key my_bool not found in inputs, did someone change inputs in mock App?'
        assert profile_data.get('outputs') is None

        # cleanup
        os.remove(profile.filename)