Exemplo n.º 1
0
    def test_zero_quantifier(self):
        buy_string = self.test_username + " 42:0"

        username, products = parser.parse(buy_string)

        self.assertEqual(username, self.test_username)
        self.assertEqual(len(products), 0)
Exemplo n.º 2
0
def sale(request, room_id):
    room = get_object_or_404(Room, pk=room_id)
    news = __get_news()
    product_list = __get_productlist(room_id)

    buy_string = request.POST['quickbuy'].strip()
    # Handle empty line
    if buy_string == "":
        return render(request, 'stregsystem/index.html', locals())
    # Extract username and product ids
    try:
        username, bought_ids = parser.parse(buy_string)
    except parser.QuickBuyError as err:
        values = {
            'correct': err.parsed_part,
            'incorrect': err.failed_part,
            'error_ptr': '~' * (len(err.parsed_part)) + '^',
            'error_msg': ' ' * (len(err.parsed_part) - 4) + 'Fejl her',
            'room': room
        }
        return render(request, 'stregsystem/error_invalidquickbuy.html',
                      values)
    # Fetch member from DB
    try:
        member = Member.objects.get(username=username, active=True)
    except Member.DoesNotExist:
        return render(request, 'stregsystem/error_usernotfound.html', locals())

    if len(bought_ids):
        return quicksale(request, room, member, bought_ids)
    else:
        return usermenu(request, room, member, None)
Exemplo n.º 3
0
    def test_username_only(self):
        buy_string = self.test_username

        username, products = parser.parse(buy_string)

        self.assertEqual(self.test_username, username)
        self.assertEqual(len(products), 0)
Exemplo n.º 4
0
    def test_multi_buy_quantifier(self):
        product_ids = [42, 42, 1337, 1337, 1337]
        buy_string = self.test_username + " 42:2 1337:3"

        username, products = parser.parse(buy_string)

        self.assertEqual(username, self.test_username)
        self.assertEqual(len(products), len(product_ids))
        assertCountEqual(self, product_ids, products)
Exemplo n.º 5
0
    def test_multi_buy_repeated(self):
        product_ids = [42, 42]
        buy_string = self.test_username + " 42 42"

        username, products = parser.parse(buy_string)

        self.assertEqual(username, self.test_username)
        self.assertEqual(len(products), len(product_ids))
        assertCountEqual(self, product_ids, products)
Exemplo n.º 6
0
    def test_single_buy(self):
        product_ids = [42]
        buy_string = self.test_username + ' 42'

        username, products = parser.parse(buy_string)

        self.assertEqual(username, self.test_username)
        self.assertEqual(len(products), 1)
        assertCountEqual(self, product_ids, products)
Exemplo n.º 7
0
 def test_invalid_productId(self):
     buy_string = self.test_username + ' a:2 1337:3'
     with self.assertRaises(parser.QuickBuyError):
         parser.parse(buy_string)
Exemplo n.º 8
0
 def test_invalid_quantifier(self):
     buy_string = self.test_username + ' 42:a 1337:3'
     with self.assertRaises(parser.QuickBuyError):
         parser.parse(buy_string)
Exemplo n.º 9
0
 def test_negative_quantifier(self):
     buy_string = self.test_username + ' 42:-1 1337:3'
     with self.assertRaises(parser.QuickBuyError):
         parser.parse(buy_string)