예제 #1
0
    def test_update_spot_items(self):
        """
        Tests that when a spot item is updated that changes persist and that
        the id remains the same.
        """
        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json['items'].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        get_response = self.client.get(self.url)

        returned_spot_json = json.loads(get_response.content)

        returned_spot_json['items'][0]['name'] = 'Test!'

        response = self.put_spot(self.url, returned_spot_json)

        get_response = self.client.get(self.url)

        updated_spot_json = json.loads(get_response.content)

        self.assertEqual(updated_spot_json['items'][0]['id'],
                         returned_spot_json['items'][0]['id'],
                         "IDs do not match for updated spot!")

        self.assertEqual(updated_spot_json['items'][0]['name'],
                         returned_spot_json['items'][0]['name'],
                         "Spot name failed to update!")
예제 #2
0
    def test_create_spot_with_items(self):
        """
        Tests the creation of a spot with correct items data.
        """
        c = self.client

        new_name = self.random_name()
        new_capacity = 10

        spot_json = utils_test.get_spot(new_name, new_capacity)

        spot_json["items"].append(utils_test.get_item())

        response = self.post_spot(spot_json)

        # assert that the spot was created
        self.assertEqual(response.status_code, 201)

        # try to retrieve the spot and ensure that items are there
        get_response = c.get(response["Location"])

        json_response = json.loads(get_response.content)

        self.assertEqual(len(json_response["items"]), 1)

        original_item = spot_json["items"][0]
        item = json_response["items"][0]
        self.assertEqual(item["name"], original_item["name"])
        self.assertEqual(item["category"], original_item["category"])
        self.assertEqual(item["subcategory"], original_item["subcategory"])
예제 #3
0
    def test_remove_item(self):
        """Tests to ensure that not including an item in PUT will remove it"""
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)

        for i in range(0, 10):
            spot_json['items'].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        del spot_json['items'][9]

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        try:
            updated_items = Item.objects.filter(spot=self.spot)
        except Exception as ex:
            self.fail("Items shoud exist but do not! :" + str(ex))

        self.assertEqual(len(updated_items), 9)
예제 #4
0
    def test_remove_item_extended_info(self):
        """Tests to ensure that not including an item EI in PUT will delete"""
        ei = {
            "make_model": "itemmodel",
            "customer_type": "UW Student",
            "auto_item_status": "active"
        }

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json['items'].append(utils_test.get_item())

        for key, value in ei.iteritems():
            spot_json['items'][0]['extended_info'][key] = value

        response = self.put_spot(self.url, spot_json)

        spot_json = json.loads(response.content)

        self.assertEqual(response.status_code, 200)

        del spot_json['items'][0]['extended_info']['make_model']

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        updated_spot_json = json.loads(get_response.content)

        self.assertNotIn('make_model',
                         updated_spot_json['items'][0]['extended_info'])
예제 #5
0
    def test_update_spot_with_missing_data(self):
        """
        Tests to make sure that updating a spot without all required fields
        fails, giving a 400.
        """
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)
        spot_json['items'].append(utils_test.get_item())

        new_spots = (copy.deepcopy(spot_json), copy.deepcopy(spot_json),
                     copy.deepcopy(spot_json))

        messages = ('Item name validation failed to raise an error',
                    'Item category validation failed to raise an error',
                    'Item subcategory validation failed to raise an error')

        # delete required fields
        del new_spots[0]['items'][0]['name']
        del new_spots[1]['items'][0]['category']
        del new_spots[2]['items'][0]['subcategory']

        for spot, message in zip(new_spots, messages):
            response = self.put_spot(self.url, spot)
            self.assertEqual(response.status_code, 400, message)
예제 #6
0
    def test_update_spot_items(self):
        """
        Tests that when a spot item is updated that changes persist and that
        the id remains the same.
        """
        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json["items"].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        get_response = self.client.get(self.url)

        returned_spot_json = json.loads(get_response.content)

        returned_spot_json["items"][0]["name"] = "Test!"

        response = self.put_spot(self.url, returned_spot_json)

        get_response = self.client.get(self.url)

        updated_spot_json = json.loads(get_response.content)

        self.assertEqual(
            updated_spot_json["items"][0]["id"],
            returned_spot_json["items"][0]["id"],
            "IDs do not match for updated spot!",
        )

        self.assertEqual(
            updated_spot_json["items"][0]["name"], returned_spot_json["items"][0]["name"], "Spot name failed to update!"
        )
예제 #7
0
    def test_update_spot_with_items(self):
        """Creates a spot and then updates it with items."""
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)

        for i in range(0, 10):
            spot_json['items'].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        try:
            updated_items = Item.objects.filter(spot=self.spot)
        except Exception as ex:
            self.fail("Items shoud exist but do not! :" + str(ex))

        self.assertEqual(len(updated_items), 10)

        for i in range(0, len(updated_items)):
            self.assertEqual(updated_items[i].json_data_structure()['name'],
                             spot_json['items'][i]['name'])
            self.assertEqual(
                updated_items[i].json_data_structure()['category'],
                spot_json['items'][i]['category'])
            self.assertEqual(
                updated_items[i].json_data_structure()['subcategory'],
                spot_json['items'][i]['subcategory'])
예제 #8
0
    def test_create_spot_with_items(self):
        """
        Tests the creation of a spot with correct items data.
        """
        c = self.client

        new_name = self.random_name()
        new_capacity = 10

        spot_json = utils_test.get_spot(new_name, new_capacity)

        spot_json['items'].append(utils_test.get_item())

        response = self.post_spot(spot_json)

        # assert that the spot was created
        self.assertEqual(response.status_code, 201)

        # try to retrieve the spot and ensure that items are there
        get_response = c.get(response["Location"])

        json_response = json.loads(get_response.content)

        self.assertEqual(len(json_response["items"]), 1)

        original_item = spot_json['items'][0]
        item = json_response["items"][0]
        self.assertEqual(item["name"], original_item['name'])
        self.assertEqual(item["category"], original_item['category'])
        self.assertEqual(item["subcategory"], original_item['subcategory'])
예제 #9
0
    def test_remove_item_extended_info(self):
        """Tests to ensure that not including an item EI in PUT will delete"""
        ei = {"make_model": "itemmodel", "customer_type": "UW Student", "auto_item_status": "active"}

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json["items"].append(utils_test.get_item())

        for key, value in ei.iteritems():
            spot_json["items"][0]["extended_info"][key] = value

        response = self.put_spot(self.url, spot_json)

        spot_json = json.loads(response.content)

        self.assertEqual(response.status_code, 200)

        del spot_json["items"][0]["extended_info"]["make_model"]

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        updated_spot_json = json.loads(get_response.content)

        self.assertNotIn("make_model", updated_spot_json["items"][0]["extended_info"])
예제 #10
0
    def test_remove_item(self):
        """Tests to ensure that not including an item in PUT will remove it"""
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)

        for i in range(0, 10):
            spot_json["items"].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        del spot_json["items"][9]

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        try:
            updated_items = Item.objects.filter(spot=self.spot)
        except Exception as ex:
            self.fail("Items shoud exist but do not! :" + str(ex))

        self.assertEqual(len(updated_items), 9)
예제 #11
0
    def test_update_spot_with_missing_data(self):
        """
        Tests to make sure that updating a spot without all required fields
        fails, giving a 400.
        """
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)
        spot_json["items"].append(utils_test.get_item())

        new_spots = (copy.deepcopy(spot_json), copy.deepcopy(spot_json), copy.deepcopy(spot_json))

        messages = (
            "Item name validation failed to raise an error",
            "Item category validation failed to raise an error",
            "Item subcategory validation failed to raise an error",
        )

        # delete required fields
        del new_spots[0]["items"][0]["name"]
        del new_spots[1]["items"][0]["category"]
        del new_spots[2]["items"][0]["subcategory"]

        for spot, message in zip(new_spots, messages):
            response = self.put_spot(self.url, spot)
            self.assertEqual(response.status_code, 400, message)
예제 #12
0
    def test_update_spot_with_items(self):
        """Creates a spot and then updates it with items."""
        spot_name = self.random_name()
        capacity = 20

        spot_json = utils_test.get_spot(spot_name, capacity)

        for i in range(0, 10):
            spot_json["items"].append(utils_test.get_item())

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        try:
            updated_items = Item.objects.filter(spot=self.spot)
        except Exception as ex:
            self.fail("Items shoud exist but do not! :" + str(ex))

        self.assertEqual(len(updated_items), 10)

        for i in range(0, len(updated_items)):
            self.assertEqual(updated_items[i].json_data_structure()["name"], spot_json["items"][i]["name"])
            self.assertEqual(updated_items[i].json_data_structure()["category"], spot_json["items"][i]["category"])
            self.assertEqual(
                updated_items[i].json_data_structure()["subcategory"], spot_json["items"][i]["subcategory"]
            )
예제 #13
0
    def test_update_item_extended_info(self):
        """Test that item EI updates correctly."""
        ei = {"make_model": "itemmodel", "customer_type": "UW Student", "auto_item_status": "active"}

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json["items"].append(utils_test.get_item())

        for key, value in ei.iteritems():
            spot_json["items"][0]["extended_info"][key] = value

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        spot_json = json.loads(get_response.content)

        self.assertEqual(len(spot_json["items"]), 1)

        self.assertIn("extended_info", spot_json["items"][0], "No extended_info in the item!")

        # assert that values were correct
        for key, value in ei.iteritems():
            self.assertTrue(key in spot_json["items"][0]["extended_info"], key + " not in item extended info!")

            self.assertEqual(
                spot_json["items"][0]["extended_info"][key],
                value,
                key + " was not " + value + ", was :" + spot_json["items"][0]["extended_info"][key],
            )

        spot_json["items"][0]["extended_info"]["make_model"] = "new_model"
        ei["make_model"] = "new_model"

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        spot_json = json.loads(get_response.content)

        self.assertEqual(len(spot_json["items"]), 1)

        self.assertIn("extended_info", spot_json["items"][0], "No extended_info in the item!")

        # assert that values were correct
        for key, value in ei.iteritems():
            self.assertTrue(key in spot_json["items"][0]["extended_info"], key + " not in item extended info!")

            self.assertEqual(
                spot_json["items"][0]["extended_info"][key],
                value,
                key + " was not " + value + ", was :" + spot_json["items"][0]["extended_info"][key],
            )
예제 #14
0
    def test_item_extended_info(self):
        """
        Tests to ensure that the item extended info is being saved on creation.
        """

        # todo : change to dict
        ei_keys = ("make_model", "customer_type", "auto_item_status")
        ei_values = ("itemmodel", "UW Student", "active")

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json['items'].append(utils_test.get_item())

        for key, value in zip(ei_keys, ei_values):
            spot_json['items'][0]['extended_info'][key] = value

        response = self.client.post('/api/v1/spot',
                                    json.dumps(spot_json),
                                    content_type="application/json")

        self.assertEqual(response.status_code, 201)

        get_response = self.client.get(response['Location'])

        self.assertEqual(get_response.status_code, 200)

        json_response = json.loads(get_response.content)

        self.assertEqual(len(json_response["items"]), 1)

        self.assertIn('extended_info', spot_json['items'][0],
                      "No extended_info in the item!")

        # assert that values were correct
        for key, value in zip(ei_keys, ei_values):
            self.assertIn(key, json_response["items"][0]["extended_info"],
                          key + " not in item extended info!")

            self.assertEqual(
                json_response["items"][0]["extended_info"][key], value,
                key + " was not " + value + ", was :" +
                json_response["items"][0]["extended_info"][key])
예제 #15
0
    def test_item_extended_info(self):
        """
        Tests to ensure that the item extended info is being saved on creation.
        """

        # todo : change to dict
        ei_keys = ("make_model", "customer_type", "auto_item_status")
        ei_values = ("itemmodel", "UW Student", "active")

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json["items"].append(utils_test.get_item())

        for key, value in zip(ei_keys, ei_values):
            spot_json["items"][0]["extended_info"][key] = value

        response = self.client.post("/api/v1/spot", json.dumps(spot_json), content_type="application/json")

        self.assertEqual(response.status_code, 201)

        get_response = self.client.get(response["Location"])

        self.assertEqual(get_response.status_code, 200)

        json_response = json.loads(get_response.content)

        self.assertEqual(len(json_response["items"]), 1)

        self.assertIn("extended_info", spot_json["items"][0], "No extended_info in the item!")

        # assert that values were correct
        for key, value in zip(ei_keys, ei_values):
            self.assertIn(key, json_response["items"][0]["extended_info"], key + " not in item extended info!")

            self.assertEqual(
                json_response["items"][0]["extended_info"][key],
                value,
                key + " was not " + value + ", was :" + json_response["items"][0]["extended_info"][key],
            )
예제 #16
0
    def test_update_item_extended_info(self):
        """Test that item EI updates correctly."""
        ei = {
            "make_model": "itemmodel",
            "customer_type": "UW Student",
            "auto_item_status": "active"
        }

        spot_json = utils_test.get_spot(self.random_name(), 20)

        spot_json['items'].append(utils_test.get_item())

        for key, value in ei.iteritems():
            spot_json['items'][0]['extended_info'][key] = value

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        spot_json = json.loads(get_response.content)

        self.assertEqual(len(spot_json["items"]), 1)

        self.assertIn('extended_info', spot_json['items'][0],
                      "No extended_info in the item!")

        # assert that values were correct
        for key, value in ei.iteritems():
            self.assertTrue(key in spot_json["items"][0]["extended_info"],
                            key + " not in item extended info!")

            self.assertEqual(
                spot_json["items"][0]["extended_info"][key], value,
                key + " was not " + value + ", was :" +
                spot_json["items"][0]["extended_info"][key])

        spot_json['items'][0]['extended_info']['make_model'] = 'new_model'
        ei['make_model'] = 'new_model'

        response = self.put_spot(self.url, spot_json)

        self.assertEqual(response.status_code, 200)

        get_response = self.client.get(self.url)

        spot_json = json.loads(get_response.content)

        self.assertEqual(len(spot_json["items"]), 1)

        self.assertIn('extended_info', spot_json['items'][0],
                      "No extended_info in the item!")

        # assert that values were correct
        for key, value in ei.iteritems():
            self.assertTrue(key in spot_json["items"][0]["extended_info"],
                            key + " not in item extended info!")

            self.assertEqual(
                spot_json["items"][0]["extended_info"][key], value,
                key + " was not " + value + ", was :" +
                spot_json["items"][0]["extended_info"][key])