示例#1
0
    def test_get_domains(self):
        responses.add(responses.POST,
                      'https://fortimail.example.com/api/v1/AdminLogin/',
                      json=LOGIN_SUCCESS_RESPONSE,
                      status=200)
        responses.add(responses.GET,
                      'https://fortimail.example.com/api/v1/domain/',
                      json=DOMAINS_SUCCESS_RESPONSE,
                      status=200)

        client = FortiMailClient(baseurl=BASEURL,
                                 username=USERNAME,
                                 password=PASSWORD)

        domains = client.get_domains()

        assert domains == DOMAINS_SUCCESS_RESPONSE
示例#2
0
    def test_get_domain_not_found(self):
        '''
        Ensure a not found error is raised for 404
        '''
        responses.add(responses.POST,
                      'https://fortimail.example.com/api/v1/AdminLogin/',
                      json=LOGIN_SUCCESS_RESPONSE,
                      status=200)
        responses.add(responses.GET,
                      'https://fortimail.example.com/api/v1/domain/test.com',
                      json=DOMAIN_NOT_FOUND_RESPONSE,
                      status=404)

        client = FortiMailClient(baseurl=BASEURL,
                                 username=USERNAME,
                                 password=PASSWORD)

        with pytest.raises(NotFound):
            domain = client.get_domain('test.com')
示例#3
0
 def test_session_is_requests_session(self):
     '''
     Ensure the session given is a requests Session
     '''
     session = {'hello': 'world'}
     with pytest.raises(IllegalArgumentError):
         client = FortiMailClient(session=session,
                                  username=USERNAME,
                                  password=PASSWORD,
                                  baseurl=BASEURL)
示例#4
0
 def test_client_create(self):
     '''
     Ensure the client instance is created (login is called)
     '''
     responses.add(responses.POST,
                   'https://fortimail.example.com/api/v1/AdminLogin/',
                   json=LOGIN_SUCCESS_RESPONSE,
                   status=200)
     client = FortiMailClient(username=USERNAME,
                              password=PASSWORD,
                              baseurl=BASEURL)
示例#5
0
 def test_client_login_failed(self):
     '''
     Ensure an exception is raised when the login failed
     '''
     responses.add(responses.POST,
                   'https://fortimail.example.com/api/v1/AdminLogin/',
                   json=LOGIN_FAILED_RESPONSE,
                   status=403)
     with pytest.raises(Forbidden):
         client = FortiMailClient(username=USERNAME,
                                  password=PASSWORD,
                                  baseurl=BASEURL)
示例#6
0
 def test_session_accepted_keyword_arg(self):
     '''
     Ensure the session can be set for the client
     '''
     responses.add(responses.POST,
                   'https://fortimail.example.com/api/v1/AdminLogin/',
                   json=LOGIN_SUCCESS_RESPONSE,
                   status=200)
     session = requests.Session()
     client = FortiMailClient(session=session,
                              username=USERNAME,
                              password=PASSWORD,
                              baseurl=BASEURL)
示例#7
0
 def test_no_username_raises_error(self):
     with pytest.raises(TypeError):
         client = FortiMailClient(baseurl=BASEURL, password=PASSWORD)
示例#8
0
 def test_no_password_raises_error(self):
     with pytest.raises(TypeError):
         client = FortiMailClient(username=USERNAME, baseurl=BASEURL)
示例#9
0
 def test_no_baseurl_raises_error(self):
     with pytest.raises(TypeError):
         client = FortiMailClient(username=USERNAME, password=PASSWORD)