def test_get_apps(self):
        """
        When the list of apps is requested, a list of apps added via add_app()
        should be returned.
        """
        app = {
            'id':
            '/my-app_1',
            'cmd':
            'sleep 50',
            'tasks': [{
                "host": "host1.local",
                "id": "my-app_1-1396592790353",
                "ports": []
            }, {
                "host": "host2.local",
                "id": "my-app_1-1396592784349",
                "ports": []
            }]
        }
        self.marathon.add_app(app)

        response = self.client.get('http://localhost/v2/apps')
        assert_that(
            response,
            succeeded(
                MatchesAll(
                    IsJsonResponseWithCode(200),
                    After(json_content, succeeded(Equals({'apps': [app]}))))))
 def test_get_apps_empty(self):
     """
     When the list of apps is requested and there are no apps, an empty list
     of apps should be returned.
     """
     response = self.client.get('http://localhost/v2/apps')
     assert_that(
         response,
         succeeded(
             MatchesAll(
                 IsJsonResponseWithCode(200),
                 After(json_content, succeeded(Equals({'apps': []}))))))
Example #3
0
    def test_health_unhealthy(self):
        """
        When a GET request is made to the health endpoint, and the health
        handler reports that the service is unhealthy, a 503 status code should
        be returned together with the JSON message from the handler.
        """
        self.server.set_health_handler(
            lambda: Health(False, {'error': "I'm sad :("}))

        response = self.client.get('http://localhost/health')
        assert_that(
            response,
            succeeded(
                MatchesAll(
                    IsJsonResponseWithCode(503),
                    After(json_content,
                          succeeded(Equals({'error': "I'm sad :("}))))))
Example #4
0
 def test_health_handler_unset(self):
     """
     When a GET request is made to the health endpoint, and the health
     handler hasn't been set, a 501 status code should be returned together
     with a JSON message that explains that the handler is not set.
     """
     response = self.client.get('http://localhost/health')
     assert_that(
         response,
         succeeded(
             MatchesAll(
                 IsJsonResponseWithCode(501),
                 After(
                     json_content,
                     succeeded(
                         Equals({
                             'error':
                             'Cannot determine service health: no handler set'
                         }))))))
    def test_get_apps_check_called(self):
        """
        When a client makes a call to the GET /v2/apps API, a flag should be
        set to indicate that the API has been called. Checking the flag should
        reset it.
        """
        # The flag should start out False
        assert_that(self.marathon_api.check_called_get_apps(), Equals(False))

        # Make a call to get_apps()
        response = self.client.get('http://localhost/v2/apps')
        assert_that(
            response,
            succeeded(
                MatchesAll(
                    IsJsonResponseWithCode(200),
                    After(json_content, succeeded(Equals({'apps': []}))))))

        # After the call the flag should be True
        assert_that(self.marathon_api.check_called_get_apps(), Equals(True))

        # Checking the flag should reset it to False
        assert_that(self.marathon_api.check_called_get_apps(), Equals(False))