Example #1
0
    def test_calculate_average(self):
        grocery = Grocerystats('fruit')
        grocery.add_quantity(1)
        grocery.add_quantity(1)
        grocery.add_quantity(1)
        grocery.add_quantity(1)
        grocery.add_sale()
        grocery.add_sale()

        self.assertEqual(grocery.calculate_average(), 2)
Example #2
0
    def test_handle_message_two(self):
        message = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            47.00,
            "cart": [{
                "name": "apple",
                "type": "fruit",
                "quantity": 4
            }, {
                "name": "orange",
                "type": "fruit",
                "quantity": 2
            }]
        }
        messagetwo = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            53.00,
            "cart": [{
                "name": "water",
                "type": "beverage",
                "quantity": 3
            }, {
                "name": "carrot",
                "type": "vegetable",
                "quantity": 3
            }]
        }

        message_json = json.dumps(message)
        messagetwo_json = json.dumps(messagetwo)
        grocery = Grocerystats(['fruit', 'beverage', 'vegetable'])

        grocery.handle_message_two(message_json)
        self.assertEqual(grocery.handle_message_two(messagetwo_json), {
            'fruit': 3,
            'beverage': 1.5,
            'vegetable': 1.5
        })
Example #3
0
    def test_handle_message(self):
        message = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            47.12,
            "cart": [{
                "name": "apple",
                "type": "fruit",
                "quantity": 4
            }, {
                "name": "orange",
                "type": "fruit",
                "quantity": 2
            }]
        }
        messagetwo = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            47.12,
            "cart": [{
                "name": "apple",
                "type": "fruit",
                "quantity": 3
            }, {
                "name": "carrot",
                "type": "vegetable",
                "quantity": 3
            }]
        }

        message_json = json.dumps(message)
        messagetwo_json = json.dumps(messagetwo)
        grocery = Grocerystats('fruit')
        grocery.handle_message(message_json)

        self.assertEqual(grocery.handle_message(messagetwo_json), 4.5)
Example #4
0
    def test_calculate_average_amount(self):
        message = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            47.00,
            "cart": [{
                "name": "apple",
                "type": "fruit",
                "quantity": 4
            }, {
                "name": "orange",
                "type": "fruit",
                "quantity": 2
            }]
        }
        messagetwo = {
            "shopper": {
                "name": "John Smith",
                "gender": "male"
            },
            "amount":
            53.00,
            "cart": [{
                "name": "water",
                "type": "beverage",
                "quantity": 3
            }, {
                "name": "carrot",
                "type": "vegetable",
                "quantity": 3
            }]
        }

        message_json = json.dumps(message)
        messagetwo_json = json.dumps(messagetwo)
        grocery = Grocerystats('fruit')

        grocery.calculate_average_amount(message_json)
        self.assertEqual(grocery.calculate_average_amount(messagetwo_json), 50)
Example #5
0
from socketIO_client import SocketIO
import json
from grocerystats import Grocerystats

# basic socket usage taken from Matt Dodge's example
SOCKET_HOST = 'http://eval.socket.nio.works'

# initiate new class to handle everything
# parameter is type of grocery user wants to track
grocery = Grocerystats(['fruit', 'vegetable'])

with SocketIO(SOCKET_HOST) as sock:
    # Set up our message handler
    sock.on('recvData', grocery.handle_message_two)
    # Join the "fruits" room
    sock.emit('ready', 'groceries')
    # Wait for messages to come through! Ctrl-C to quit
    sock.wait()
Example #6
0
 def test_create_grocery(self):
     grocery = Grocerystats('vegetable')
     self.assertEqual(grocery.type, 'vegetable')
     self.assertEqual(grocery.total_sales, 0)
     self.assertEqual(grocery.total_quantity, 0)
Example #7
0
    def test_add_quantity(self):
        grocery = Grocerystats('fruit')
        grocery.add_quantity(1)
        grocery.add_quantity(1)

        self.assertEqual(grocery.total_quantity, 2)
Example #8
0
    def test_add_sale(self):
        grocery = Grocerystats('fruit')
        grocery.add_sale()
        grocery.add_sale()

        self.assertEqual(grocery.total_sales, 2)