예제 #1
0
    def test_equal(self):
        self.pet1 = swagger_client.Pet()
        self.pet1.name = "test name"
        self.pet1.id = 1
        self.pet1.photo_urls = ["string"]
        self.pet1.status = "available"
        cate1 = swagger_client.Category()
        cate1.id = 1
        cate1.name = "dog"
        self.pet.category = cate1
        tag1 = swagger_client.Tag()
        tag1.id = 1
        self.pet1.tags = [tag1]

        self.pet2 = swagger_client.Pet()
        self.pet2.name = "test name"
        self.pet2.id = 1
        self.pet2.photo_urls = ["string"]
        self.pet2.status = "available"
        cate2 = swagger_client.Category()
        cate2.id = 1
        cate2.name = "dog"
        self.pet.category = cate2
        tag2 = swagger_client.Tag()
        tag2.id = 1
        self.pet2.tags = [tag2]

        self.assertTrue(self.pet1 == self.pet2)

        # reset pet1 tags to empty array so that object comparison returns false
        self.pet1.tags = []
        self.assertFalse(self.pet1 == self.pet2)
예제 #2
0
 def setUp(self):
     self.pet = swagger_client.Pet()
     self.pet.name = "test name"
     self.pet.id = 1
     self.pet.photo_urls = ["string"]
     self.pet.status = "available"
     cate = swagger_client.Category()
     cate.id = 1
     cate.name = "dog"
     self.pet.category = cate
     tag = swagger_client.Tag()
     tag.id = 1
     self.pet.tags = [tag]
예제 #3
0
 def setUpModels(self):
     self.category = swagger_client.Category()
     self.category.id = int(time.time())
     self.category.name = "dog"
     self.tag = swagger_client.Tag()
     self.tag.id = int(time.time())
     self.tag.name = "blank"
     self.pet = swagger_client.Pet()
     self.pet.id = int(time.time())
     self.pet.name = "hello kity"
     self.pet.photo_urls = ["http://foo.bar.com/1", "http://foo.bar.com/2"]
     self.pet.status = "sold"
     self.pet.category = self.category
     self.pet.tags = [self.tag]
예제 #4
0
    def test_sanitize_for_serialization(self):
        # None
        data = None
        result = self.api_client.sanitize_for_serialization(None)
        self.assertEqual(result, data)

        # str
        data = "test string"
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, data)

        # int
        data = 1
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, data)

        # bool
        data = True
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, data)

        # date
        data = parse("1997-07-16").date()    # date
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, "1997-07-16")

        # datetime
        data = parse("1997-07-16T19:20:30.45+01:00")    # datetime
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, "1997-07-16T19:20:30.450000+01:00")

        # list
        data = [1]
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, data)

        # dict
        data = {"test key": "test value"}
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, data)

        # model
        pet_dict = {"id": 1, "name": "monkey",
                    "category": {"id": 1, "name": "test category"},
                    "tags": [{"id": 1, "name": "test tag1"},
                             {"id": 2, "name": "test tag2"}],
                    "status": "available",
                    "photoUrls": ["http://foo.bar.com/3",
                                  "http://foo.bar.com/4"]}
        pet = swagger_client.Pet()
        pet.id = pet_dict["id"]
        pet.name = pet_dict["name"]
        cate = swagger_client.Category()
        cate.id = pet_dict["category"]["id"]
        cate.name = pet_dict["category"]["name"]
        pet.category = cate
        tag1 = swagger_client.Tag()
        tag1.id = pet_dict["tags"][0]["id"]
        tag1.name = pet_dict["tags"][0]["name"]
        tag2 = swagger_client.Tag()
        tag2.id = pet_dict["tags"][1]["id"]
        tag2.name = pet_dict["tags"][1]["name"]
        pet.tags = [tag1, tag2]
        pet.status = pet_dict["status"]
        pet.photo_urls = pet_dict["photoUrls"]

        data = pet
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, pet_dict)

        # list of models
        list_of_pet_dict = [pet_dict]
        data = [pet]
        result = self.api_client.sanitize_for_serialization(data)
        self.assertEqual(result, list_of_pet_dict)