from __future__ import absolute_import, unicode_literals


class StatusCodeAssertion(object):

    _schema = {
    }

    def __init__(self, valid_codes):
        super(StatusCodeAssertion, self).__init__()
        self.valid_codes = valid_codes

    @classmethod
    def from_dict(cls, data):
        # FIXME: Validate input with jsonschema
        return cls(valid_codes=data['expected'])

from __future__ import absolute_import, unicode_literals

from jsonschema.exceptions import ValidationError
import jsonschema

from ..exceptions import YamlParseError


class StatusCodeAssertion(object):

    _schema = {
        '$schema': 'http://json-schema.org/draft-04/schema#',
        'title': 'Assertion on status code ',
        'description': 'Test case markup for Haas Rest Test',
        'type': 'object',
        'properties': {
            'expected': {
                'type': 'integer',
            },
        },
        'required': ['expected']
    }

    def __init__(self, expected_status):
        super(StatusCodeAssertion, self).__init__()
        self.expected_status = expected_status

    @classmethod
    def from_dict(cls, data):
        try:
            jsonschema.validate(data, cls._schema)
        except ValidationError as e:
            raise YamlParseError(str(e))
        return cls(expected_status=data['expected'])

    def run(self, case, response):
        case.fail()

Add initial status code assertion
Add initial status code assertion

  from __future__ import absolute_import, unicode_literals
+ 
+ from jsonschema.exceptions import ValidationError
+ import jsonschema
+ 
+ from ..exceptions import YamlParseError
  
  
  class StatusCodeAssertion(object):
  
      _schema = {
+         '$schema': 'http://json-schema.org/draft-04/schema#',
+         'title': 'Assertion on status code ',
+         'description': 'Test case markup for Haas Rest Test',
+         'type': 'object',
+         'properties': {
+             'expected': {
+                 'type': 'integer',
+             },
+         },
+         'required': ['expected']
      }
  
-     def __init__(self, valid_codes):
+     def __init__(self, expected_status):
          super(StatusCodeAssertion, self).__init__()
-         self.valid_codes = valid_codes
+         self.expected_status = expected_status
  
      @classmethod
      def from_dict(cls, data):
-         # FIXME: Validate input with jsonschema
+         try:
+             jsonschema.validate(data, cls._schema)
+         except ValidationError as e:
+             raise YamlParseError(str(e))
-         return cls(valid_codes=data['expected'])
+         return cls(expected_status=data['expected'])
  
+     def run(self, case, response):
+         case.fail()
+ 
Add initial status code assertion
## Code Before:
from __future__ import absolute_import, unicode_literals


class StatusCodeAssertion(object):

    _schema = {
    }

    def __init__(self, valid_codes):
        super(StatusCodeAssertion, self).__init__()
        self.valid_codes = valid_codes

    @classmethod
    def from_dict(cls, data):
        # FIXME: Validate input with jsonschema
        return cls(valid_codes=data['expected'])

## Instruction:
Add initial status code assertion
## Code After:
from __future__ import absolute_import, unicode_literals

from jsonschema.exceptions import ValidationError
import jsonschema

from ..exceptions import YamlParseError


class StatusCodeAssertion(object):

    _schema = {
        '$schema': 'http://json-schema.org/draft-04/schema#',
        'title': 'Assertion on status code ',
        'description': 'Test case markup for Haas Rest Test',
        'type': 'object',
        'properties': {
            'expected': {
                'type': 'integer',
            },
        },
        'required': ['expected']
    }

    def __init__(self, expected_status):
        super(StatusCodeAssertion, self).__init__()
        self.expected_status = expected_status

    @classmethod
    def from_dict(cls, data):
        try:
            jsonschema.validate(data, cls._schema)
        except ValidationError as e:
            raise YamlParseError(str(e))
        return cls(expected_status=data['expected'])

    def run(self, case, response):
        case.fail()
