Exemplo n.º 1
0
 async def _store(self, ctx):
     """View store information and inventory."""
     player = Player(ctx.message.author.id)
     location = Location(player.current_location)
     store_ids = self.stores.list_id()
     for store_id in store_ids:
         store = Store(store_id)
         prices = store.settings['prices']
         if store.location.location_id == player.current_location:
             embed = discord.Embed(
                 title=location.name,
                 color=discord.Color.green(),
                 description='Welcome to **' + store.name + '**, ' + ctx.message.author.display_name + '!')
             items = self.items.list()
             embed.add_field(name='Items for Sale', value='The following are available for sale.\n', inline=False)
             for item in items:
                 if item['id'] in store.available_items:
                     embed.add_field(
                         name=item['emoji'] + ' ' + str(item['id']) + '. ' + item['name'],
                         value='Price: ' + str(prices[str(item['id'])])
                     )
             embed.set_footer(text='Requested by '+ctx.message.author.display_name + '. Prices updated: '
                                   + str(prices['date']),
                              icon_url=ctx.message.author.avatar_url)
             if hasattr(store, 'thumbnail'):
                 embed.set_thumbnail(url=store.thumbnail)
             await ctx.send(embed=embed)
Exemplo n.º 2
0
def create_store():
    if request.method == 'POST':
        name = request.form['name']
        url_prefix = request.form['url_prefix']
        tag_name = request.form['tag_name']
        query = json.loads(request.form['query'])

        Store(name, url_prefix, tag_name, query).save_to_mongo()

    return render_template('stores/new_store.html')
Exemplo n.º 3
0
def new_alert():
    if request.method == 'POST':
        alert_name = request.form['name']
        item_url = request.form['item_url']
        price_limit = float(request.form['price_limit'])

        store = Store.find_by_url(item_url)
        item = Item(item_url, store.tag_name, store.query)
        item.load_price()
        item.save_to_mongo()

        Alert(alert_name, item._id, price_limit,
              session['email']).save_to_mongo()

    return render_template('alerts/new_alert.html')
Exemplo n.º 4
0
def edit_store(store_id):
    store = Store.get_by_id(store_id)

    if request.method == 'POST':
        name = request.form['name']
        url_prefix = request.form['url_prefix']
        tag_name = request.form['tag_name']
        query = json.loads(request.form['query'])

        store.name = name
        store.url_prefix = url_prefix
        store.tag_name = tag_name
        store.query = query

        store.save_to_mongo()

        return redirect(url_for('.index'))

    return render_template('stores/edit_store.html', store=store)
 def setup_method(self):
     self.store = Store()
     self.cart = Cart()
     self.soup = Product('soup', 1.89)
     self.soup.has_special = True
     self.soup.special_details = {
         'specialType': 'basic unit discount',
         'perUnitDiscount': 0.20,
         'limit': 5
     }
     self.soda = Product('soda', 1.49)
     self.soda.has_special = True
     self.soda.special_details = {
         'specialType': 'buy some get some',
         'buyAmount': 2,
         'getAmount': 1,
         'percentOff': 100,
         'limit': 2
     }
     self.soap = Product('soap', 2.49)
     self.soap.has_special = True
     self.soap.special_details = {
         'specialType': 'buy some for amount',
         'buyAmount': 3,
         'dollarAmount': 5,
         'limit': 2
     }
     self.beef = Product('beef', 5.99, 1)
     self.cheese = Product('cheese', 2.38, 1)
     self.store.products = [
         self.soup, self.soda, self.soap, self.beef, self.cheese
     ]
     self.soups = [self.soup, self.soup, self.soup, self.soup, self.soup]
     self.sodas = [
         self.soda, self.soda, self.soda, self.soda, self.soda, self.soda
     ]
     self.soaps = [self.soap, self.soap, self.soap, self.soap]
     self.beefs = [self.beef]
     self.cheeses = [self.cheese, self.cheese]
     self.cart.products = self.soups + self.sodas + self.soaps + self.beefs + self.cheeses
     self.cart.standard_items = self.cheeses + self.beefs
     self.cart.special_items = self.soups + self.sodas + self.soaps
Exemplo n.º 6
0
 def post(self):
     data = AddStore.parser.parse_args()
     store = Store(data['name'])
     store.insert()
     return store.json(), 200
Exemplo n.º 7
0
 def get(self, name):
     return Store.getByName(name)
Exemplo n.º 8
0
 async def _set_store_thumbnail(self, ctx, store_id: int = 0, url: str = None):
     print('thumbnail')
     store = Store(store_id)
     store.set_thumbnail(url)
     return await ctx.send('Set thumbnail')
Exemplo n.º 9
0
def delete_store(store_id):
    Store.get_by_id(store_id).remove_from_mongo()

    return redirect(url_for('.index'))
Exemplo n.º 10
0
def index():
    stores = Store.all()
    return render_template('stores/store_index.html', stores=stores)
Exemplo n.º 11
0
 def setup_method(self):
     self.store = Store()
     self.soup = Product('soup', 1.89)
     self.beef = Product('beef', 5.99)
Exemplo n.º 12
0
class TestStore:
    def setup_method(self):
        self.store = Store()
        self.soup = Product('soup', 1.89)
        self.beef = Product('beef', 5.99)

    def test_is_product_available__should_be_false_if_list_is_empty(self):
        actual = self.store.is_product_available('soup')
        assert actual is False

    def test_is_product_available__should_be_false_if_item_not_in_list(self):
        self.store.products = [self.beef]
        actual = self.store.is_product_available('soup')
        assert actual is False

    def test_is_product_available__should_be_true(self):
        self.store.products = [self.soup]
        actual = self.store.is_product_available('soup')
        assert actual is True

    def test_stock_product__should_be_true(self):
        self.store.stock_product(self.soup)
        assert self.soup in self.store.products

    def test_stock_product__should_be_false(self):
        self.store.stock_product(self.soup)
        self.store.stock_product(self.soup)
        assert len(self.store.products) == 1
        assert self.soup == self.store.products[0]

    def test_stock_products__should_stock_store_from_database(self):
        self.store.stock_products()
        assert len(self.store.products) == 5

    def test_discontinue_product__soup_should_no_longer_be_available(self):
        self.store.products = [self.soup, self.beef]
        self.store.discontinue_product(self.soup)
        assert len(self.store.products) == 1
        assert self.soup not in self.store.products

    def test_discontinue_product__store_should_only_have_beef_in_products(
            self):
        self.store.products = [self.beef]
        self.store.discontinue_product(self.soup)
        assert len(self.store.products) == 1
        assert self.soup not in self.store.products

    @patch('src.models.store.get_special')
    def test_activate_special_on_product__should_assign_special_for_product(
            self, mock_special):
        self.store.products = [self.soup]
        special_details = {
            'specialType': 'basic unit discount',
            'perUnitDiscount': 0.20,
            'limit': 5
        }
        mock_special.return_value = special_details
        self.store.activate_special_on_product(self.soup)
        assert self.soup.name == mock_special.mock_calls[0][1][0]
        assert self.store.products[0].special_details == special_details
        assert self.store.products[0].has_special is True
Exemplo n.º 13
0
from src.database.specials import get_special
from src.models.cart import Cart
from src.models.store import Store

store = Store()
cart = Cart()
store.stock_products()

by_unit = ['soup', 'soda', 'soap']
by_weight = ['beef', 'cheese']

shopping = True
while shopping is True:
    print('\nThe store has the following items available:\n')
    print([item.name for item in store.products])

    item_to_add = input('\nWhat would you like to add to your cart? Please type the name of the item (without quotes)\nas it appears in the list above, type REVIEW to review your cart, or type EXIT to exit.\n\n')
    item_to_add = item_to_add.lower()

    if item_to_add == 'exit':
        break

    product_to_add = [product for product in store.products if product.name == item_to_add]
    amount_to_add = 0

    if item_to_add in by_unit:
        amount_to_add = input('\nHow many would you like to add to your cart? Please use standard integers (1, 2, 3, etc).\n\n')
        cart.add_product_by_unit(store, product_to_add[0], int(amount_to_add))
    elif item_to_add in by_weight:
        amount_to_add = input('\nHow much would you like to add to your cart? Please enter value in pounds, using standard floats (1.25 for 1.25 lb, .75 for .75 lb, 2.5 for 2.5 lbs, etc).\n\n')
        cart.add_product_by_weight(store, product_to_add[0], float(amount_to_add))