Esempio n. 1
0
    def test_normal(self, title, config_yml, expected_text):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response':
            make_response(TEXT, 'utf-8', 'utf-8'),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8"
            }
        })

        expected = {
            'response':
            make_response(json.dumps(expected_text, ensure_ascii=False),
                          'utf-8', 'utf-8').to_dict(),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8"
            }
        }

        assert expected == Executor(
            load_yaml(config_yml)).exec(payload).to_dict()
Esempio n. 2
0
    def test_static(self, reqs, expected):
        config = load_yaml("""
items:
  - conditions:
      - path:
          items:
            - regexp: /api
      - name:
          items:
            - regexp: hoge
    queries:
      q1: ['v99']
      q2: ['v999']
  - conditions:
      - path:
          items:
            - regexp: /hogehoge
    queries:
      q1: ['v77']
      q3: ['v777']
    headers:
      h1: H1
      h2: H2
        """)

        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests': reqs
        })

        assert Executor(config).exec(payload, None).to_dict() == {
            'requests': expected
        }
Esempio n. 3
0
    def from_yaml_to_list(cls, data, force_snake_case=True):
        """From yaml string to list of instance

        :param data: Yaml string
        :type data: unicode
        :param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
        :type force_snake_case: bool
        :return: List of instance
        :rtype: TList[T]

        Usage:

            >>> from owlmixin.samples import Human
            >>> humans = Human.from_yaml_to_list('''
            ... - id: 1
            ...   name: Tom
            ...   favorites:
            ...     - name: Apple
            ... - id: 2
            ...   name: John
            ...   favorites:
            ...     - name: Orange
            ... ''')
            >>> humans[0].name
            'Tom'
            >>> humans[1].name
            'John'
            >>> humans[0].favorites[0].name
            'Apple'
        """
        return cls.from_dicts(util.load_yaml(data), force_snake_case)
Esempio n. 4
0
    def test_multibyte(self, title, encoding, body_encoding, config_yml,
                       expected_text):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response':
            make_response(TEXT_MULTIBYTE, encoding, body_encoding),
            'req': {
                "path": "/filter",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        })

        actual = Executor(load_yaml(config_yml)).exec(payload).to_dict()
        expected = {
            'response':
            make_response(json.dumps(expected_text, ensure_ascii=False),
                          encoding, encoding).to_dict(),
            'req': {
                "path": "/filter",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        }

        assert expected == actual
Esempio n. 5
0
    def from_yaml(cls, data, force_snake_case=True):
        """From yaml string to instance

        :param data: Yaml string
        :type data: unicode
        :param force_snake_case: Keys are transformed to snake case in order to compliant PEP8 if True
        :type force_snake_case: bool
        :return: Instance
        :rtype: T

        Usage:

            >>> from owlmixin.samples import Human
            >>> human = Human.from_yaml('''
            ... id: 1
            ... name: Tom
            ... favorites:
            ...   - name: Apple
            ...     names_by_lang:
            ...       en: Apple
            ...       de: Apfel
            ...   - name: Orange
            ... ''')
            >>> human.id
            1
            >>> human.name
            'Tom'
            >>> human.favorites[0].names_by_lang["de"]
            'Apfel'
        """
        return cls.from_dict(util.load_yaml(data), force_snake_case)
Esempio n. 6
0
    def test_static(self, reqs, expected):
        config = load_yaml("""
items:
  - conditions:
      - path:
          items:
            - regexp: /api
      - name:
          items:
            - regexp: hoge
    queries:
      q1: ['v99']
      q2: ['v999']
  - conditions:
      - path:
          items:
            - regexp: /hogehoge
    queries:
      q1: ['v77']
      q3: ['v777']
    headers:
      h1: H1
      h2: H2
        """)

        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict(
            {'requests': reqs})

        assert Executor(config).exec(payload, None).to_dict() == {
            'requests': expected
        }
Esempio n. 7
0
    def test_filter(self, title, config_yml, requests, expected_result):
        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests': requests,
        })

        actual: Reqs2ReqsAddOnPayload = Executor(load_yaml(config_yml)).exec(payload, None)

        assert expected_result == actual.requests.to_dicts()
Esempio n. 8
0
    def test(self, title, config_yml, response, expected_result):
        payload: Res2DictAddOnPayload = Res2DictAddOnPayload.from_dict({
            'response': response,
        })

        actual: Res2DictAddOnPayload = Executor(load_yaml(config_yml)).exec(payload)

        assert actual.response == response
        assert load_json(dump_json(actual.result.get())) == expected_result
Esempio n. 9
0
    def test_not_use_notify(self, send, title, config_yml, requests, jumeaux_config_yml, expected_result):
        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests': requests,
        })

        actual: Reqs2ReqsAddOnPayload = Executor(load_yaml(config_yml)) \
            .exec(payload, JumeauxConfig.from_yaml(jumeaux_config_yml))

        assert expected_result == actual.requests.to_dicts()
Esempio n. 10
0
    def test_filter(self, title, config_yml, requests, expected_result):
        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests':
            requests,
        })

        actual: Reqs2ReqsAddOnPayload = Executor(load_yaml(config_yml)).exec(
            payload, None)

        assert expected_result == actual.requests.to_dicts()
Esempio n. 11
0
    def test(self, title, config_yml, response, expected_result):
        payload: Res2DictAddOnPayload = Res2DictAddOnPayload.from_dict({
            'response':
            response,
        })

        actual: Res2DictAddOnPayload = Executor(
            load_yaml(config_yml)).exec(payload)

        assert response == actual.response
        assert expected_result == actual.result.get()
Esempio n. 12
0
    def test_not_use_notify(self, send, title, config_yml, requests,
                            jumeaux_config_yml, expected_result):
        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests':
            requests,
        })

        actual: Reqs2ReqsAddOnPayload = Executor(load_yaml(config_yml)) \
            .exec(payload, JumeauxConfig.from_yaml(jumeaux_config_yml))

        assert expected_result == actual.requests.to_dicts()
Esempio n. 13
0
    def test(self, title, config_yml, response, body, encoding, expected_body, expected_encoding):
        payload: DumpAddOnPayload = DumpAddOnPayload.from_dict({
            'response': response,
            'body': body,
            'encoding': encoding,
        })

        actual: DumpAddOnPayload = Executor(load_yaml(config_yml)).exec(payload)

        assert expected_body == actual.body
        assert expected_encoding == actual.encoding.get()
Esempio n. 14
0
    def test(self, title, config_yml, response, body, encoding, expected_body, expected_encoding):
        payload: DumpAddOnPayload = DumpAddOnPayload.from_dict({
            'response': response,
            'body': body,
            'encoding': encoding,
        })

        actual: DumpAddOnPayload = Executor(load_yaml(config_yml)).exec(payload)

        assert actual.body == expected_body
        assert actual.encoding.get() == expected_encoding
Esempio n. 15
0
    def test_error(self, title, config_yml):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response': make_response(TEXT, 'utf-8', 'utf-8'),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
            }
        })

        with pytest.raises(SystemExit):
            Executor(load_yaml(config_yml)).exec(payload)
Esempio n. 16
0
    def test_normal(self, title, config_yml, expected):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response': make_response("json", 200),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        })

        assert expected == Executor(load_yaml(config_yml)).exec(payload).to_dict()
Esempio n. 17
0
    def test_error(self, title, config_yml):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response':
            make_response(TEXT, 'utf-8', 'utf-8'),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
            }
        })

        with pytest.raises(SystemExit):
            Executor(load_yaml(config_yml)).exec(payload)
Esempio n. 18
0
    def test_normal(self, title, config_yml, expected):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response':
            make_response("json", 200),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        })

        assert expected == Executor(
            load_yaml(config_yml)).exec(payload).to_dict()
Esempio n. 19
0
    def test(self, title, config_yml, trial, expected_result):
        payload: DidChallengeAddOnPayload = DidChallengeAddOnPayload.from_dict({
            'trial': trial,
        })
        reference: DidChallengeAddOnReference = DidChallengeAddOnReference.from_dict({
            "res_one": RES_ONE,
            "res_other": RES_OTHER,
            "res_one_props": RES_ONE_PROPS,
            "res_other_props": RES_OTHER_PROPS,
        })

        actual: DidChallengeAddOnPayload = Executor(load_yaml(config_yml)).exec(payload, reference)

        assert expected_result == actual.trial.to_dict()
Esempio n. 20
0
    def test(self, title, config_yml, trial, expected_result):
        payload: DidChallengeAddOnPayload = DidChallengeAddOnPayload.from_dict(
            {
                'trial': trial,
            })
        reference: DidChallengeAddOnReference = DidChallengeAddOnReference.from_dict(
            {
                "res_one": RES_ONE,
                "res_other": RES_OTHER
            })

        actual: DidChallengeAddOnPayload = Executor(
            load_yaml(config_yml)).exec(payload, reference)

        assert expected_result == actual.trial.to_dict()
Esempio n. 21
0
    def test_use_notify(self, send, title, config_yml, requests, jumeaux_config_yml):
        send.side_effect = send_for_test

        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests': requests,
        })

        try:
            Executor(load_yaml(config_yml)) \
                .exec(payload, JumeauxConfig.from_yaml(jumeaux_config_yml))
        except SystemExit:
            assert send.call_args[0][0] == 'empty test notify!'
            assert send.call_args[0][1].to_dict() == {
                "type": "slack",
                "channel": "#jumeaux",
                "username": "******"
            }
Esempio n. 22
0
    def test_use_notify(self, send, title, config_yml, requests,
                        jumeaux_config_yml):
        send.side_effect = send_for_test

        payload: Reqs2ReqsAddOnPayload = Reqs2ReqsAddOnPayload.from_dict({
            'requests':
            requests,
        })

        try:
            Executor(load_yaml(config_yml)) \
                .exec(payload, JumeauxConfig.from_yaml(jumeaux_config_yml))
        except SystemExit:
            assert send.call_args[0][0] == 'empty test notify!'
            assert send.call_args[0][1].to_dict() == {
                "type": "slack",
                "channel": "#jumeaux",
                "username": "******"
            }
Esempio n. 23
0
    def test_normal(self, title, config_yml, expected_text):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response': make_response(TEXT, 'utf-8', 'utf-8'),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8"
            }
        })

        expected = {
            'response': make_response(json.dumps(expected_text, ensure_ascii=False), 'utf-8', 'utf-8').to_dict(),
            'req': {
                "path": "/path",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8"
            }
        }

        assert expected == Executor(load_yaml(config_yml)).exec(payload).to_dict()
Esempio n. 24
0
    def test_multibyte(self, title, encoding, body_encoding, config_yml, expected_text):
        payload: Res2ResAddOnPayload = Res2ResAddOnPayload.from_dict({
            'response': make_response(TEXT_MULTIBYTE, encoding, body_encoding),
            'req': {
                "path": "/filter",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        })

        actual = Executor(load_yaml(config_yml)).exec(payload).to_dict()
        expected = {
            'response': make_response(json.dumps(expected_text, ensure_ascii=False), encoding, encoding).to_dict(),
            'req': {
                "path": "/filter",
                "qs": {},
                "headers": {},
                "url_encoding": "utf-8",
            }
        }

        assert expected == actual
Esempio n. 25
0
 def test_exit(self, title, payload, config):
     with pytest.raises(SystemExit):
         Executor(load_yaml(config)).exec(
             JudgementAddOnPayload.from_dict(payload),
             JudgementAddOnReference.from_dict(REFERENCE),
         )
Esempio n. 26
0
    def test(self, create_tmpfile_from, title, config_yml, expected):
        tmp = create_tmpfile_from(REQUESTS)
        actual = Executor(load_yaml(config_yml)).exec(Log2ReqsAddOnPayload.from_dict({'file': tmp}))

        assert expected == actual.to_dicts()
Esempio n. 27
0
 def test_exit(self, title, payload, config):
     with pytest.raises(SystemExit):
         Executor(load_yaml(config)).exec(
             JudgementAddOnPayload.from_dict(payload),
             JudgementAddOnReference.from_dict(REFERENCE),
         )
Esempio n. 28
0
 def test(self, title, payload, config, expected):
     actual: JudgementAddOnPayload = Executor(load_yaml(config)).exec(
         JudgementAddOnPayload.from_dict(payload),
         JudgementAddOnReference.from_dict(REFERENCE),
     )
     assert expected == actual.to_dict()
Esempio n. 29
0
 def test(self, title, payload, config, expected):
     actual: JudgementAddOnPayload = Executor(load_yaml(config)).exec(
         JudgementAddOnPayload.from_dict(payload),
         JudgementAddOnReference.from_dict(REFERENCE),
     )
     assert expected == actual.to_dict()
Esempio n. 30
0
    def test(self, create_tmpfile_from, title, requests, config_yml, expected):
        tmp = create_tmpfile_from(requests)
        actual = Executor(load_yaml(config_yml)).exec(
            Log2ReqsAddOnPayload.from_dict({'file': tmp}))

        assert actual.to_dicts() == expected