def test_client_echo_valid_success(self, generate_key_method):
        generate_key_method.return_value = "12345GENKEY"

        with requests_mock.Mocker() as mocker:
            mocker.register_uri("GET", "http://localhost/endpoint", json={"echo": "12345GENKEY"}, status_code=client.OK)

            self.assertTrue(client_echo_valid("http://localhost/endpoint"))
    def test_client_echo_valid_fail_wrong_status(self):
        with requests_mock.Mocker() as mocker:
            mocker.register_uri('GET', 'http://localhost/endpoint',
                                json={'echo': '12345GENKEY'},
                                status_code=client.INTERNAL_SERVER_ERROR)

            self.assertFalse(client_echo_valid('http://localhost/endpoint'))
    def test_client_echo_valid_success(self, generate_key_method):
        generate_key_method.return_value = '12345GENKEY'

        with requests_mock.Mocker() as mocker:
            mocker.register_uri('GET', 'http://localhost/endpoint',
                                json={'echo': '12345GENKEY'},
                                status_code=client.OK)

            self.assertTrue(client_echo_valid('http://localhost/endpoint'))
    def test_client_echo_valid_fail_wrong_status(self):
        with requests_mock.Mocker() as mocker:
            mocker.register_uri(
                "GET",
                "http://localhost/endpoint",
                json={"echo": "12345GENKEY"},
                status_code=client.INTERNAL_SERVER_ERROR,
            )

            self.assertFalse(client_echo_valid("http://localhost/endpoint"))
Beispiel #5
0
    def post(self):
        """
        Creates a new account
        """
        json_data = request.get_json()

        if not client_echo_valid(json_data['endpoint']):
            return make_response(jsonify({'Error': 'Echo response failed'}),
                                 client.BAD_REQUEST)

        return insert_account(DEFAULT_ACCOUNTS_TABLE,
                              **{'username': json_data['username'],
                                 'endpoint': json_data['endpoint'],
                                 'is_admin': False,
                                 'failed_count': 0,
                                 'api_key': generate_key(),
                                 'secret_key': generate_key()})