예제 #1
0
파일: tests.py 프로젝트: kxing/Geddit
 def tearDown(self):
     # delete the items
     Item.delete_item(self.item1)
     Item.delete_item(self.item2)
     # delete the categories
     Category.delete_category(self.category1)
     Category.delete_category(self.category2)
     # delete the users
     User.delete_user(self.buyer)
     User.delete_user(self.seller)
예제 #2
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_filter_by_category(self):
        items1 = Item.get_filtered_items(category=self.textbooks)
        self.assertIn(self.textbook_3091_1, items1)
        self.assertIn(self.textbook_3091_2, items1)

        items2 = Item.get_filtered_items(category=self.videos)
        self.assertIn(self.video_5111, items2)

        items3 = Item.get_filtered_items(category=self.girs)
        self.assertIn(self.cheat_sheets, items3)
예제 #3
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_items(self):
        # check to make sure that both ways of getting items work
        for items in [Item.get_items(self.user), self.user.get_items(), Item.get_all_items()]:
            # check the item count
            self.assertEqual(len(items), 4)

            self.assertIn(self.textbook_3091_1, items)
            self.assertIn(self.textbook_3091_2, items)
            self.assertIn(self.video_5111, items)
            self.assertIn(self.cheat_sheets, items)
예제 #4
0
파일: tests.py 프로젝트: kxing/Geddit
 def setUp(self):
     self.category = Category.create_category(self.GIRS_CATEGORY)
     self.user = User.create_user(self.USERNAME, self.FIRST_NAME, self.LAST_NAME, \
             self.EMAIL, self.PHONE, self.LOCATION)
     self.item1 = Item.create_item(self.user, self.PHYSICS_NAME, \
             self.PHYSICS_DESCRIPTION, self.category, self.PHYSICS_PRICE_1)
     self.item2 = Item.create_item(self.user, self.PHYSICS_NAME, \
             self.PHYSICS_DESCRIPTION, self.category, self.PHYSICS_PRICE_2)
     self.item3 = Item.create_item(self.user, self.VIDEO_NAME, \
             self.VIDEO_DESCRIPTION, self.category, self.VIDEO_PRICE)
     self.reservation1 = Reservation.create_reservation(self.user, \
             self.SEARCH_QUERY1, self.MAX_PRICE)
     self.reservation2 = self.user.add_reservation(self.SEARCH_QUERY2, self.MAX_PRICE)
예제 #5
0
파일: views.py 프로젝트: pH14/Geddit
def claim_listing(request):
    if request.method != 'POST':
        return redirect('data.views.buy_page')
    item = Item.get_item_by_id(request.POST['item_id'])
    get_current_user(request).add_claim(item)

    buyer = get_current_user(request)
    item = Item.get_item_by_id(request.POST['item_id'])
    item.seller_user.send_email(str(buyer) + ' wants to buy your ' + str(item) + '. Please contact your buyer at ' + buyer.email, '[Geddit] Buyer for ' + str(item))
    
    get_params = QueryDict('', mutable=True)
    get_params['message'] = "Item Claimed.  An email has been sent to the seller.  Please wait for them to contact you to coordinate the transaction."
    return redirect(reverse('data.views.dashboard_page') + '?' + get_params.urlencode())
예제 #6
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_filter_by_id(self):
        textbook_1 = Item.get_filtered_items(id=self.textbook_3091_1.id)
        self.assertEqual(len(textbook_1), 1)
        self.assertIn(self.textbook_3091_1, textbook_1)

        textbook_2 = Item.get_filtered_items(id=self.textbook_3091_2.id)
        self.assertEqual(len(textbook_2), 1)
        self.assertIn(self.textbook_3091_2, textbook_2)

        video = Item.get_filtered_items(id=self.video_5111.id)
        self.assertEqual(len(video), 1)
        self.assertIn(self.video_5111, video)

        sheets = Item.get_filtered_items(id=self.cheat_sheets.id)
        self.assertEqual(len(sheets), 1)
        self.assertIn(self.cheat_sheets, sheets)
예제 #7
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_claims(self):
        # check that the items are not claimed
        self.assertFalse(self.item1.claimed)
        self.assertFalse(self.item2.claimed)

        # create the claims
        self.claim1 = Claim.create_claim(self.buyer, self.item1)
        self.claim2 = self.buyer.add_claim(self.item2)

        # check that the items are claimed
        self.assertTrue(self.item1.claimed)
        self.assertTrue(self.item2.claimed)

        for claims in [Claim.get_claims(self.buyer), self.buyer.get_claims()]:
            self.assertIn(self.claim1, claims)
            self.assertIn(self.claim2, claims)
        self.assertEqual(Claim.get_claim(self.item1), self.claim1)
        self.assertEqual(Claim.get_claim(self.item1).buyer, self.buyer)

        # delete the second claim and verify that the item is not claimed
        self.buyer.remove_claim(self.item2)
        # refresh self.item2
        self.item2 = Item.get_item_by_id(self.item2.id)
        self.assertFalse(self.item2.claimed)

        # add the claim back
        self.claim2 = self.buyer.add_claim(self.item2)
        self.assertTrue(self.item2.claimed)

        # delete the claims
        Claim.delete_claim(self.claim1)
        Claim.delete_claim(self.claim2)
예제 #8
0
파일: views.py 프로젝트: kxing/Geddit
def buy_page(request):
    render_params = base_params(request)
    render_params[NAV_PAGE] = BUY

    category = None
    if 'category' in request.GET:
        category = Category.get_category(request.GET['category'])

    search_query = request.GET.get('search_query', None)
    id = request.GET.get('id', None)
    page = (int)(request.GET.get('page', 0))

    matching_items = Item.get_filtered_items(category, search_query, id)

    if page * BUY_PAGE_ITEMS_PER_PAGE > len(matching_items):
      page = 0

    render_params['items'] = matching_items[page * 10 : (page + 1) * 10]
    render_params['category'] = category
    render_params['search_query'] = search_query
    render_params['id'] = id
    render_params['page'] = page
    render_params['pages'] = 1 + (len(matching_items) - 1) / BUY_PAGE_ITEMS_PER_PAGE

    return render(request, 'buy/buy.html', render_params, \
            context_instance=RequestContext(request))
예제 #9
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_filter_by_search(self):
        textbooks = Item.get_filtered_items(search_query='Textbook')
        self.assertIn(self.textbook_3091_1, textbooks)
        self.assertIn(self.textbook_3091_2, textbooks)

        videos = Item.get_filtered_items(search_query='Video')
        self.assertIn(self.video_5111, videos)

        solid_state = Item.get_filtered_items(search_query='3.091')
        self.assertIn(self.textbook_3091_1, solid_state)
        self.assertIn(self.textbook_3091_2, solid_state)
        self.assertIn(self.cheat_sheets, solid_state)

        principles = Item.get_filtered_items(search_query='5.111')
        self.assertIn(self.video_5111, principles)
        self.assertIn(self.cheat_sheets, principles)
예제 #10
0
파일: tests.py 프로젝트: kxing/Geddit
 def setUp(self):
     # create the users
     self.buyer = User.create_user(self.BUYER_USERNAME, \
             self.BUYER_FIRST_NAME, self.BUYER_LAST_NAME, \
             self.BUYER_EMAIL, self.BUYER_CELL_PHONE,
             self.BUYER_LOCATION)
     self.seller = User.create_user(self.SELLER_USERNAME, \
             self.SELLER_FIRST_NAME, self.SELLER_LAST_NAME, \
             self.SELLER_EMAIL, self.SELLER_CELL_PHONE,
             self.SELLER_LOCATION)
     # create the categories
     self.category1 = Category.create_category(self.CATEGORY_1)
     self.category2 = Category.create_category(self.CATEGORY_2)
     # create the items
     self.item1 = Item.create_item(self.seller, self.ITEM_1_NAME, \
             self.ITEM_1_DESCRIPTION, self.category1, self.ITEM_1_PRICE)
     self.item2 = Item.create_item(self.seller, self.ITEM_2_NAME, \
             self.ITEM_2_DESCRIPTION, self.category2, self.ITEM_2_PRICE)
예제 #11
0
파일: views.py 프로젝트: kxing/Geddit
def unclaim_listing(request):
    if request.method != 'POST':
        return redirect('data.views.dashboard_page')
    item = Item.get_item_by_id(request.POST['item_id'])
    try:
        get_current_user(request).remove_claim(item)
    except:
        # TODO(kxing): Log this.
        pass
    return redirect('data.views.dashboard_page')
예제 #12
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_claim_item_remove(self):
        # create the item
        test_item = Item.create_item(self.seller, self.ITEM_1_NAME, \
                self.ITEM_1_DESCRIPTION, self.category1, self.ITEM_1_PRICE)

        # check that the item is not claimed
        self.assertFalse(test_item.claimed)

        # create the claim
        claim = Claim.create_claim(self.buyer, test_item)

        # check that the item is claimed
        test_item = Item.get_item_by_id(test_item.id)
        self.assertTrue(test_item.claimed)

        # delete the item
        self.seller.remove_item(test_item)

        # check that there is no claim on the item
        self.assertEqual(len(self.buyer.get_claims()), 0)
예제 #13
0
파일: tests.py 프로젝트: kxing/Geddit
    def tearDown(self):
        # delete the items
        Item.delete_item(self.textbook_3091_1)
        Item.delete_item(self.textbook_3091_2)
        Item.delete_item(self.video_5111)
        Item.delete_item(self.cheat_sheets)

        # delete the categories
        Category.delete_category(self.textbooks)
        Category.delete_category(self.videos)
        Category.delete_category(self.girs)

        # delete the user
        User.delete_user(self.user)
예제 #14
0
파일: views.py 프로젝트: sarine/Geddit
def buy_page(request):
    render_params = base_params(request)

    category = None
    if 'category' in request.GET:
        category = Category.get_category(request.GET['category'])

    search_query = request.GET.get('search_query', None)
    id = request.GET.get('id', None)

    render_params['items'] = Item.get_filtered_items(category, search_query, id)

    return render(request, 'buy.html', render_params, \
            context_instance=RequestContext(request))
예제 #15
0
파일: tests.py 프로젝트: kxing/Geddit
    def tearDown(self):
        Reservation.delete_reservation(self.reservation1)
        self.user.remove_reservation(self.reservation2)

        Item.delete_item(self.item1)
        Item.delete_item(self.item2)
        Item.delete_item(self.item3)

        User.delete_user(self.user)
        Category.delete_category(self.category)
예제 #16
0
    def link_item(self, name, *args):
        item = Item.query.get(name=name)
        if not item:
            item = Item(name=name, values=[], groups=[])

        if args:
            for arg in args:
                group = Group.query.get(name=arg)
                if not group:
                    Group(name=arg, item_order=[item.name])
                else:
                    group.item_order.append(item.name)
                item.groups.append(arg)

        session.flush()
        return item.groups
예제 #17
0
def save_item(item, session=None):
    """
    Insert an item into the database
    :param item: item dictionary
    :param session: session object (testing util)
    """
    if not session:
        session = Session()
    if item.get('new_cart'):
        session.add(Cart(id=item.get('cart_id')))
    session.add(
        Item(external_id=item.get('external_id'),
             cart_id=item.get('cart_id'),
             name=item.get('name'),
             value=item.get('value')))
    # errors should be caught in celery logs
    session.commit()
예제 #18
0
    def add_item(self, name, *values):
        date = self.date or None
        # TODO: fuzzy logic search to avoid creating weird new items

        item = Item.query.get(name=name)
        if not item:
            item = Item(name=name, values=[], groups=[])

        if not date:
            date = datetime.now()

        if values:
            for arg in values:
                print('  adding ', arg, ' to ', item.name)
                item.values.append({'timestamp': date, 'value': arg})

        session.flush()
        return item
예제 #19
0
파일: tests.py 프로젝트: kxing/Geddit
    def setUp(self):
        # create the user
        self.user = User.create_user(self.USERNAME, self.FIRST_NAME, \
                self.LAST_NAME, self.EMAIL, self.PHONE, self.LOCATION)

        # create the categories
        self.textbooks = Category.create_category(self.TEXTBOOK_CATEGORY)
        self.videos = Category.create_category(self.VIDEOS_CATEGORY)
        self.girs = Category.create_category(self.GIRS_CATEGORY)

        # create the items
        self.textbook_3091_1 = Item.create_item(self.user, self.TEXTBOOK_NAME, \
                self.TEXTBOOK_DESCRIPTION, self.textbooks, self.TEXTBOOK_PRICE)
        self.textbook_3091_2 = self.user.add_item(self.TEXTBOOK_NAME, \
                self.TEXTBOOK_DESCRIPTION, self.textbooks, self.TEXTBOOK_PRICE)
        self.video_5111 = self.user.add_item(self.VIDEOS_NAME, \
                self.VIDEOS_DESCRIPTION, self.videos, self.VIDEOS_PRICE)
        self.cheat_sheets = self.user.add_item(self.CHEAT_SHEET_NAME, \
                self.CHEAT_SHEET_DESCRIPTION, self.girs, self.CHEAT_SHEET_PRICE)
예제 #20
0
파일: views.py 프로젝트: pH14/Geddit
def remove_item(request):
    if request.method != 'POST':
        return redirect('data.views.sell_page')
    item = Item.get_item_by_id(request.POST['item_id'])
    get_current_user(request).remove_item(item)
    return redirect('data.views.dashboard_page')
예제 #21
0
파일: views.py 프로젝트: sarine/Geddit
def unclaim_listing(request):
    if request.method != 'POST':
        return redirect('data.views.cart_page')
    item = Item.get_item_by_id(request.POST['item_id'])
    get_current_user(request).remove_claim(item)
    return redirect('data.views.cart_page')
예제 #22
0
파일: tests.py 프로젝트: kxing/Geddit
 def test_get_item_by_id(self):
     self.assertEqual(Item.get_item_by_id(self.textbook_3091_1.id), self.textbook_3091_1)
     self.assertEqual(Item.get_item_by_id(self.textbook_3091_2.id), self.textbook_3091_2)
     self.assertEqual(Item.get_item_by_id(self.video_5111.id), self.video_5111)
     self.assertEqual(Item.get_item_by_id(self.cheat_sheets.id), self.cheat_sheets)