Exemplo n.º 1
0
    def test_must_return_none_if_file_not_found(self, yaml_parse_mock):
        expected = "parsed result"
        yaml_parse_mock.return_value = expected

        reader = SamSwaggerReader(definition_uri="somepath")
        actual = reader._download_swagger("abcdefgh.txt")

        self.assertIsNone(actual)
        yaml_parse_mock.assert_not_called()
Exemplo n.º 2
0
    def test_must_return_none_if_file_not_found(self, yaml_parse_mock):
        expected = "parsed result"
        yaml_parse_mock.return_value = expected

        reader = SamSwaggerReader(definition_uri="somepath")
        actual = reader._download_swagger("abcdefgh.txt")

        self.assertIsNone(actual)
        yaml_parse_mock.assert_not_called()
Exemplo n.º 3
0
    def test_must_skip_non_s3_dictionaries(self, yaml_parse_mock):

        location = {"some": "value"}

        reader = SamSwaggerReader(definition_uri=location)
        reader._download_from_s3 = Mock()

        actual = reader._download_swagger(location)

        self.assertIsNone(actual)
        reader._download_from_s3.assert_not_called()
        yaml_parse_mock.assert_not_called()
Exemplo n.º 4
0
    def test_read_from_definition_uri(self):
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_uri=uri)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._download_swagger.assert_called_with(uri)
Exemplo n.º 5
0
    def test_must_skip_non_s3_dictionaries(self, yaml_parse_mock):

        location = {"some": "value"}

        reader = SamSwaggerReader(definition_uri=location)
        reader._download_from_s3 = Mock()

        actual = reader._download_swagger(location)

        self.assertIsNone(actual)
        reader._download_from_s3.assert_not_called()
        yaml_parse_mock.assert_not_called()
Exemplo n.º 6
0
    def test_read_from_definition_uri(self):
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_uri=uri)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._download_swagger.assert_called_with(uri)
Exemplo n.º 7
0
    def test_must_work_with_include_transform(self, parse_mock):
        body = {'this': 'swagger'}
        expected = {'k': 'v'}
        location = "some location"

        reader = SamSwaggerReader(definition_body=body)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected
        parse_mock.return_value = location

        actual = reader._read_from_definition_body()
        self.assertEquals(actual, expected)
        parse_mock.assert_called_with(body)
Exemplo n.º 8
0
    def test_must_work_with_include_transform(self, parse_mock):
        body = {'this': 'swagger'}
        expected = {'k': 'v'}
        location = "some location"

        reader = SamSwaggerReader(definition_body=body)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected
        parse_mock.return_value = location

        actual = reader._read_from_definition_body()
        self.assertEquals(actual, expected)
        parse_mock.assert_called_with(body)
Exemplo n.º 9
0
    def test_must_read_first_from_definition_body(self):
        body = {"this is": "swagger"}
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_body=body, definition_uri=uri)
        reader._download_swagger = Mock()
        reader._read_from_definition_body = Mock()
        reader._read_from_definition_body.return_value = expected

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._read_from_definition_body.assert_called_with()
        reader._download_swagger.assert_not_called()
Exemplo n.º 10
0
    def test_must_read_first_from_definition_body(self):
        body = {"this is": "swagger"}
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_body=body, definition_uri=uri)
        reader._download_swagger = Mock()
        reader._read_from_definition_body = Mock()
        reader._read_from_definition_body.return_value = expected

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._read_from_definition_body.assert_called_with()
        reader._download_swagger.assert_not_called()
Exemplo n.º 11
0
    def test_must_read_from_local_file_without_working_directory(self, yaml_parse_mock):
        data = {"some": "value"}
        expected = "parsed result"
        yaml_parse_mock.return_value = expected

        with tempfile.NamedTemporaryFile(mode='w') as fp:
            filepath = fp.name

            json.dump(data, fp)
            fp.flush()

            reader = SamSwaggerReader(definition_uri=filepath)
            actual = reader._download_swagger(filepath)

            self.assertEquals(actual, expected)
            yaml_parse_mock.assert_called_with('{"some": "value"}')  # data was read back from the file as JSON string
Exemplo n.º 12
0
    def test_must_use_definition_uri_if_body_does_not_exist(self):
        body = {"this is": "swagger"}
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_body=body, definition_uri=uri)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected

        # Set the output of reading the definition body to be None
        reader._read_from_definition_body = Mock()
        reader._read_from_definition_body.return_value = None

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._read_from_definition_body.assert_called_with()
        reader._download_swagger.assert_called_with(uri)
Exemplo n.º 13
0
    def test_must_use_definition_uri_if_body_does_not_exist(self):
        body = {"this is": "swagger"}
        uri = "./file.txt"
        expected = {"some": "value"}

        reader = SamSwaggerReader(definition_body=body, definition_uri=uri)
        reader._download_swagger = Mock()
        reader._download_swagger.return_value = expected

        # Set the output of reading the definition body to be None
        reader._read_from_definition_body = Mock()
        reader._read_from_definition_body.return_value = None

        actual = reader.read()
        self.assertEquals(actual, expected)

        reader._read_from_definition_body.assert_called_with()
        reader._download_swagger.assert_called_with(uri)
Exemplo n.º 14
0
    def test_must_read_from_local_file_without_working_directory(
            self, yaml_parse_mock):
        data = {"some": "value"}
        expected = "parsed result"
        yaml_parse_mock.return_value = expected

        with tempfile.NamedTemporaryFile(mode='w') as fp:
            filepath = fp.name

            json.dump(data, fp)
            fp.flush()

            reader = SamSwaggerReader(definition_uri=filepath)
            actual = reader._download_swagger(filepath)

            self.assertEquals(actual, expected)
            yaml_parse_mock.assert_called_with(
                '{"some": "value"}'
            )  # data was read back from the file as JSON string
Exemplo n.º 15
0
    def test_must_download_from_s3_for_s3_locations(self, yaml_parse_mock):
        location = {
            "Bucket": "mybucket",
            "Key": "swagger.yaml",
            "Version": "versionId"
        }
        swagger_str = "some swagger str"
        expected = "some data"

        reader = SamSwaggerReader(definition_uri=location)
        reader._download_from_s3 = Mock()
        reader._download_from_s3.return_value = swagger_str
        yaml_parse_mock.return_value = expected

        actual = reader._download_swagger(location)

        self.assertEquals(actual, expected)
        reader._download_from_s3.assert_called_with(location["Bucket"],
                                                    location["Key"],
                                                    location["Version"])
        yaml_parse_mock.assert_called_with(swagger_str)
Exemplo n.º 16
0
    def test_must_download_from_s3_for_s3_locations(self, yaml_parse_mock):
        location = {
            "Bucket": "mybucket",
            "Key": "swagger.yaml",
            "Version": "versionId"
        }
        swagger_str = "some swagger str"
        expected = "some data"

        reader = SamSwaggerReader(definition_uri=location)
        reader._download_from_s3 = Mock()
        reader._download_from_s3.return_value = swagger_str
        yaml_parse_mock.return_value = expected

        actual = reader._download_swagger(location)

        self.assertEquals(actual, expected)
        reader._download_from_s3.assert_called_with(location["Bucket"],
                                                    location["Key"],
                                                    location["Version"])
        yaml_parse_mock.assert_called_with(swagger_str)
Exemplo n.º 17
0
    def test_with_invalid_location(self):

        reader = SamSwaggerReader(definition_uri="something")
        actual = reader._download_swagger({})

        self.assertIsNone(actual)
Exemplo n.º 18
0
    def test_with_invalid_location(self):

        reader = SamSwaggerReader(definition_uri="something")
        actual = reader._download_swagger({})

        self.assertIsNone(actual)