예제 #1
0
    def setUp(self):
        t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
        t.save()

        u = User(id=1, name='Test user', subscribed=True)
        u.save()
        c = Card(card_id='12345678', user=u)
        c.save()
예제 #2
0
    def setUp(self):
        t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
        t.save()

        u = User(id=1, name='Test user', subscribed=True)
        u.save()
        c = Card(card_id='12345678', user=u)
        c.save()

        # make user 1 a user for tool 1
        p = Permission(user=User.objects.get(pk=1),
                       permission=1,
                       tool=Tool.objects.get(pk=1),
                       addedby=User.objects.get(pk=1))
        p.save()
예제 #3
0
    def setUp(self):
        t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
        t.save()

        v = VendItem(name='test_item', price=55)
        v.save()
        v = VendItem(name='test_item2', price=600)
        v.save()

        m = MachineItem(item=VendItem.objects.get(name='test_item'),
                        tool=Tool.objects.get(pk=1),
                        position=1,
                        stock=0)
        m.save()
        m = MachineItem(item=VendItem.objects.get(name='test_item2'),
                        tool=Tool.objects.get(pk=1),
                        position=2,
                        stock=1)
        m.save()
        m = MachineItem(item=VendItem.objects.get(name='test_item'),
                        tool=Tool.objects.get(pk=1),
                        position=3,
                        stock=7)
        m.save()

        users = (
            # user 1 has 2 cards, and is a maintainer
            (1, 'user1a', '00112233445566', True, 99999),
            (1, 'user1b', 'aabbccdd', True, 99999),

            # a user
            (2, 'user2', '22222222', True, 0),

            # subscribed, but not a user
            (3, 'user3', '33333333', True, 77),

            # exists, but not is not subscribed
            (4, 'user4', '44444444', False, 555),
        )

        for id, name, card, subscribed, balance in users:
            self.__dict__[name] = card
            try:
                u = User.objects.get(pk=id)
                u.save()
                c = Card(card_id=card, user=u)
                c.save()
            except ObjectDoesNotExist:
                u = User(id=id,
                         name=name,
                         subscribed=subscribed,
                         balance=balance)
                u.save()
                c = Card(card_id=card, user=u)
                c.save()
예제 #4
0
def register_professor():
    res = CustomResponse()
    try:
        password = Customer.generate_password()
        pw_hash = bcrypt.generate_password_hash(password=password)
        phone_numbers = request.json.get('phone_numbers')
        phone_numbers = list(
            map(
                lambda number: PhoneNumber(
                    customer_ssn=request.json.get('ssn'), **number),
                phone_numbers))
        address = request.json.get('address')
        address = Address(**address)
        request.json['type'] = 'PROFESSOR'
        if phone_numbers is not None and address is not None:
            del request.json['phone_numbers']
            del request.json['address']
        else:
            raise InvalidRequestException(
                'Address and phone numbers must not be empty!')
        cards = [
            Card(customer_ssn=request.json.get('ssn'),
                 expiration_date=datetime.now() + timedelta(days=100000))
        ]
        customer = Customer(**request.json,
                            cards=cards,
                            address=address,
                            phone_numbers=phone_numbers,
                            pw_hash=pw_hash)
        db.session.add(customer)
        db.session.commit()

        result = customer.get_relaxed_v1_view()
        result['password'] = password
        res.set_data(result)
        return res.get_response(201)
    except InvalidRequestException as e:
        db.session.rollback()
        res.set_error(e.message)
    except IntegrityError as e:
        db.session.rollback()
        res.set_error(Config.UNHANDLED_EXCEPTION_MESSAGE)
    except:
        db.session.rollback()
        res.set_error(Config.UNHANDLED_EXCEPTION_MESSAGE)
    return res.get_response()
예제 #5
0
    def cast(self, data=None):
        from server.models import Card
        tailored = []
        targets = self.find_target(data)
        for card in targets:

            if not card.alive or card.hp <= 0:  # ex: take control of the destroyer (but destroyer is dead already?)
                continue

            old_uuid = card.uuid
            old_owner = card.player
            new_owner = self.game.get_opposite_player(card.player.uid)

            if not new_owner.ground.is_full():
                slot = new_owner.ground.get_available_slot()
                if slot:
                    old_owner.ground.remove(card)

                    card.uuid = Card.vuuid(new_owner.uid, card.title)
                    card.player = new_owner
                    card.stealed = True  # cannot return hand etc
                    new_owner.ground.add(card, slot=slot)

                    tailored.append({'side_switched': {
                        'from': {
                            'uid': old_owner.uid,
                            'uuid': old_uuid,
                        },
                        'to': {
                            'uid': new_owner.uid,
                            'uuid': card.uuid,
                            'slot': slot
                        }
                    }})

        logger.info("spell> SwitchSide cast result:{0}".format(tailored))
        return tailored
예제 #6
0
    def handle(self, *args, **options):
        path = options['path']
        if not os.path.exists(path):
            raise CommandError('Can\'t find %s' % (path))

        sr = os.stat(path)
        if sr[stat.ST_SIZE] == 0:
            raise CommandError('%s is zero size, not using it.' % (path))

        fh = open(path, 'r')
        jdata = json.load(fh)
        fh.close()

        if len(jdata) == 0:
            raise CommandError('%s has no entries, not using it.' % (path))

        for u in jdata:
            # {u'perms': [], u'subscribed': False, u'gladosfile': u'zz', u'nick': u'notsubscribed', u'cards': [u'44444444'], u'id': u'4'}
            eu = None
            try:
                eu = User.objects.get(pk=u['id'])
            except ObjectDoesNotExist:
                pass
            if eu:
                # update nick and subscription
                eu.name = u['nick']
                eu.subscribed = u['subscribed']
                #gladosfile should be empty rather than null in this DB
                if u['gladosfile'] is not None:
                    eu.gladosfile = u['gladosfile']
                else:
                    eu.gladosfile = ""
                ecs = eu.card_set.all()
                for ec in ecs:
                    # delete cards that have gone away
                    if ec.card_id not in u['cards']:
                        ec.delete()
                for c in u['cards']:
                    # add new cards
                    if c not in [x.card_id for x in ecs]:
                        try:
                            if len(c) <= 14:
                                co = Card(card_id=c, user=eu)
                                co.save()
                            else:
                                self.stdout.write(
                                    "for %s, card id %s is too long" % (eu, c))
                        except DataError as e:
                            self.stdout.write(u)
                            self.stdout.write(e)
                            self.stdout.write(
                                "error adding new card for %s, card too long? %s"
                                % (eu, c))
                eu.save()
            else:
                with transaction.atomic():
                    nu = User(id=int(u['id']),
                              name=u['nick'],
                              subscribed=u['subscribed'])
                    #gladosfile should be empty rather than null in this DB
                    if u['gladosfile'] is not None:
                        nu.gladosfile = u['gladosfile']
                    try:
                        nu.save()
                    except Exception as e:
                        self.stdout.write("blah.")
                        self.stdout.write(e, type(e))
                        self.stdout.write(u)
                    for c in u['cards']:
                        try:
                            # the card already exist?
                            ec = Card.objects.get(card_id=c)
                            # bother, it does.
                            # Which of the 2 users is subscribed?
                            if not u['subscribed']:
                                self.stdout.write(
                                    "skipping card %s, it's already in the db and this user is not subscribed"
                                    % (c, ))
                                continue
                            else:
                                # darn, maybe the other user is not subscribed?
                                if not ec.user.subscribed:
                                    self.stdout.write(
                                        "card %s is already in the db for %s, but they are not subscribed so i'm deleting the card"
                                        % (c, ec.user))
                                    ec.delete()
                                else:
                                    self.stdout.write(
                                        "panic: card id %s is in use by 2 users: %s and %s"
                                        % (c, ec.user, nu))
                        except ObjectDoesNotExist:
                            pass
                        except Exception as e:
                            self.stdout.write(u)
                            self.stdout.write("lol wtf", e)
                        try:
                            if len(c) <= 14:
                                co = Card(card_id=c, user=nu)
                                co.save()
                            else:
                                self.stdout.write(
                                    "for %s, card id %s is too long" % (nu, c))
                        except Exception as e:
                            self.stdout.write(e, type(e))
                            PrintFrame()
                            self.stdout.write(u)
                            self.stdout.write(nu)
                            continue
                    try:
                        nu.save()
                    except Exception as e:
                        self.stdout.write(e, type(e))
                        PrintFrame()
                        self.stdout.write(u)
                        self.stdout.write(nu)

        carddb_by_id = {}
        for u in jdata:
            # {u'perms': [], u'subscribed': False, u'gladosfile': u'zz', u'nick': u'notsubscribed', u'cards': [u'44444444'], u'id': u'4'}
            carddb_by_id[int(u['id'])] = u

        # loop through all acnode users and check that they exist in the carddb.
        for au in User.objects.all():
            if au.id not in carddb_by_id:
                self.stdout.write(
                    "user with id %d is in the local db, but not in carddb.json, unsubscribeing them and removing their cards"
                    % (au.id))
                # remove  cards
                cs = au.card_set.all()
                for c in cs:
                    c.delete()
                # set status to unsubscribed
                au.subscribed = False
                # we don't want to delete them cos of 'on cascade delete' stuffs, and there account might get re-activated
                au.save()
예제 #7
0
def gen_spell_cards(browser, number_of_cards=1):
    for i in range(number_of_cards):
        browser.execute_script("createJS('spellNames.js')")
        names = WebDriverWait(browser, 10).until(
            EC.presence_of_all_elements_located(
                (By.XPATH, "//ul[@id='myresult']/li")))
        print("Collecting Names: {0} {1}".format(i, len(names)))
        for name in names:
            card_title = name.text
            if Card.objects.filter(title=card_title).first() is None:
                card = Card()
                card.type = "spell"
                card.cardset = "set10"
                card.title = card_title
                card.hp = 0
                card.dp = 0
                card.mana = randint(1, 6)
                card.save()

                card.portrait = generate_portrait("{0}.png".format(card.key))
                card.save()
                print("SpellCard created: {0}".format(card.title))
예제 #8
0
def gen_creature_cards(browser, number_of_cards=1):
    browser.execute_script("createJS('classNames.js')")
    WebDriverWait(browser, 10).until(
        EC.presence_of_all_elements_located(
            (By.XPATH, "//span[@id='options']/input")))

    for i in range(number_of_cards):
        browser.execute_script("mynameGen(1)")
        names = WebDriverWait(browser, 10).until(
            EC.presence_of_all_elements_located(
                (By.XPATH, "//ul[@id='myresult']/li")))
        for name in names:
            card_title = name.text
            if Card.objects.filter(title=card_title).first() is None:
                card = Card()
                card.type = "creature"
                card.cardset = "set10"
                card.title = card_title
                card.hp = randint(1, 8)
                card.attack = randint(1, 6)
                card.mana = randint(1, 7)
                card.save()
                card.portrait = generate_portrait("{0}.png".format(card.key))
                card.save()
                print("CreatureCard created: {0}".format(card.title))
예제 #9
0
    def setUp(self):
        t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
        t.save()

        t = Tool(id=2,
                 name='other test tool',
                 status=0,
                 status_message='Out of action')
        t.save()

        users = (
            # user 1 has 2 cards, and is a maintainer
            (1, 'user1a', '00112233445566', True),
            (1, 'user1b', 'aabbccdd', True),

            # a user
            (2, 'user2', '22222222', True),

            # subscribed, but not a user
            (3, 'user3', '33333333', True),

            # exists, but not is not subscribed
            (4, 'user4', '44444444', False),
        )

        for id, name, card, subscribed in users:
            self.__dict__[name] = card
            try:
                u = User.objects.get(pk=id)
                u.save()
                c = Card(card_id=card, user=u)
                c.save()
            except ObjectDoesNotExist:
                u = User(id=id, name=name, subscribed=subscribed)
                u.save()
                c = Card(card_id=card, user=u)
                c.save()

        self.user_does_not_exist = '12345678'
        # user 2 is a user
        p = Permission(user=User.objects.get(pk=2),
                       permission=1,
                       tool=Tool.objects.get(pk=1),
                       addedby=User.objects.get(pk=1))
        p.save()
        # user 1 is a maintainer
        p = Permission(user=User.objects.get(pk=1),
                       permission=2,
                       tool=Tool.objects.get(pk=1),
                       addedby=User.objects.get(pk=1))
        p.save()
        # make the android tag a user
        #    p = Permissions(user=User.objects.get(pk=8), permission=1, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1))
        #    p.save()
        # make the temp card a maintainer
        #    p = Permissions(user=User.objects.get(pk=5), permission=2, tool=Tool.objects.get(pk=1), addedby=User.objects.get(pk=1))
        #    p.save()
        # make user 4 a maintainer
        p = Permission(user=User.objects.get(pk=4),
                       permission=2,
                       tool=Tool.objects.get(pk=1),
                       addedby=User.objects.get(pk=1))
        p.save()