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

        self.pet2 = petstore_api.Pet()
        self.pet2.name = "test name"
        self.pet2.id = 1
        self.pet2.photo_urls = ["string"]
        self.pet2.status = "available"
        cate2 = petstore_api.Category()
        cate2.id = 1
        cate2.name = "dog"
        self.pet.category = cate2
        tag2 = petstore_api.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)
Example #2
0
 def setUp(self):
     self.pet = petstore_api.Pet(name="test name", photo_urls=["string"])
     self.pet.id = 1
     self.pet.status = "available"
     cate = petstore_api.Category()
     cate.id = 1
     cate.name = "dog"
     self.pet.category = cate
     tag = petstore_api.Tag()
     tag.id = 1
     self.pet.tags = [tag]
Example #3
0
 def setUpModels(self):
     self.category = petstore_api.Category()
     self.category.id = id_gen()
     self.category.name = "dog"
     self.tag = petstore_api.Tag()
     self.tag.id = id_gen()
     self.tag.name = "swagger-codegen-python-pet-tag"
     self.pet = petstore_api.Pet(name="hello kity", photo_urls=["http://foo.bar.com/1", "http://foo.bar.com/2"])
     self.pet.id = id_gen()
     self.pet.status = "sold"
     self.pet.category = self.category
     self.pet.tags = [self.tag]
 def setUpModels(cls):
     cls.category = petstore_api.Category()
     cls.category.id = id_gen()
     cls.category.name = "dog"
     cls.tag = petstore_api.Tag()
     cls.tag.id = id_gen()
     cls.tag.name = "python-pet-tag"
     cls.pet = petstore_api.Pet(
         name="hello kity",
         photo_urls=["http://foo.bar.com/1", "http://foo.bar.com/2"])
     cls.pet.id = id_gen()
     cls.pet.status = "sold"
     cls.pet.category = cls.category
     cls.pet.tags = [cls.tag]
Example #5
0
 def setUpModels(self):
     self.category = petstore_api.Category()
     self.category.id = int(time.time())
     self.category.name = "dog"
     self.tag = petstore_api.Tag()
     self.tag.id = int(time.time())
     self.tag.name = "blank"
     self.pet = petstore_api.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]
    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 = petstore_api.Pet(name=pet_dict["name"],
                               photo_urls=pet_dict["photoUrls"])
        pet.id = pet_dict["id"]
        cate = petstore_api.Category()
        cate.id = pet_dict["category"]["id"]
        cate.name = pet_dict["category"]["name"]
        pet.category = cate
        tag1 = petstore_api.Tag()
        tag1.id = pet_dict["tags"][0]["id"]
        tag1.name = pet_dict["tags"][0]["name"]
        tag2 = petstore_api.Tag()
        tag2.id = pet_dict["tags"][1]["id"]
        tag2.name = pet_dict["tags"][1]["name"]
        pet.tags = [tag1, tag2]
        pet.status = pet_dict["status"]

        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)

        # model with additional proerties
        model_dict = {'some_key': True}
        model = petstore_api.StringBooleanMap(**model_dict)
        result = self.api_client.sanitize_for_serialization(model)
        self.assertEqual(result, model_dict)