Exemplo n.º 1
0
    def test_parse_fail_schema2(self):
        """Missing required timeZone field"""
        data = """
        {
            "details": {
                "id": "1234",
                "name": "Easy St",
                "accountId": 123456,
                "status": "Active",
                "installationDate": "2019-09-24"
            }
        }"""

        with self.assertRaises(SchemaValidationFailure):
            parsers.parse_site(data)
Exemplo n.º 2
0
    def test_parse_fail_schema1(self):
        """Additional properties is set to false"""
        data = """
        {
            "details": {
                "name": "Easy St",
                "accountId": 123456,
                "status": "Active",
                "schema_violation": "Yes",
                "installationDate": "2019-09-24"
                }
        }"""

        with self.assertRaises(SchemaValidationFailure):
            parsers.parse_site(data)
Exemplo n.º 3
0
    def test_parse_fail_schema3(self):
        """Missing required name field"""
        data = """
        {
            "details": {
                "id": "1234",
                "accountId": 123456,
                "status": "Active",
                "installationDate": 42,
                "location": {
                    "country": "United States",
                    "state": "California",
                    "city": "San Francisco"
                }
            }
        }"""

        with self.assertRaises(SchemaValidationFailure):
            parsers.parse_site(data)
Exemplo n.º 4
0
    def test_parse_empty(self):
        """Time zone field is present but empty"""
        data = """
        {
            "details": {
                "id": 1234,
                "name": "Bob",
                "accountId": 123456,
                "status": "Active",
                "installationDate": "2019-09-24",
                "location": {
                    "country": "United States",
                    "state": "California",
                    "city": "San Francisco",
                    "timeZone": ""
                }
            }
        }"""

        sites = parsers.parse_site(data)
        self.assertEqual(len(sites.time_zone), 0)
Exemplo n.º 5
0
    def test_success(self):
        data = """
            {
                "details": {
                    "id": 1234,
                    "name": "Bob",
                    "accountId": 123456,
                    "status": "Active",
                    "installationDate": "2019-09-24",
                    "location": {
                        "country": "United States",
                        "state": "California",
                        "city": "San Francisco",
                        "timeZone": "America/Los_Angeles"
                    }
                }
            }"""

        site_details = parsers.parse_site(data)
        self.assertEqual(site_details.id, 1234)
        self.assertEqual(site_details.time_zone, "America/Los_Angeles")
        self.assertEqual(site_details.installation_date, "2019-09-24")
        self.assertEqual(site_details.name, "Bob")
Exemplo n.º 6
0
 def test_parse_fail_json(self):
     """The parser raises an exception when the response is not JSON."""
     data = """{abc123:"""
     with self.assertRaises(JsonParseFailure):
         parsers.parse_site(data)