def add_user(n=5):
    for i in range(n):
        fname = fake.first_name()
        lname = fake.last_name()
        email = fake.email()
        user = User(f_name=fname, lname=lname, email=email)
        user.save()
Пример #2
0
class TestItem(TestCase):
    def setUp(self):
        self.user_object = User(username='******', email='*****@*****.**')
        self.user_object.set_password('testing321')
        self.user_object.save()
        self.createduser = Profile.objects.create(user=self.user_object,
                                                  phone_no='1234567891',
                                                  address='Sricity',
                                                  card_no='1234567891011121')
        self.createauction = Auction.objects.create(
            creator=self.createduser,
            scheduled_date=datetime.datetime.today() +
            datetime.timedelta(days=2),
            category='Gaming')
        self.itemset_create = ItemSet.objects.create(
            ItemList=self.createauction)
        self.items = Item.objects.create(
            item=self.itemset_create,
            item_name='stand',
            description='well polished',
            base_price=342,
            keywords='polished',
        )
        self.client = None

    def test_Item(self):
        self.assertTrue(Item.objects.filter(item_name='stand').exists())
        #self.assertTrue(ItemSet.objects.filter(item_name='umbrella').exists())
        self.assertTrue(ItemSet.objects.filter(item=self.items).exists())
        # item = models.ForeignKey(ItemSet, on_delete=models.CASCADE)
        # item_name = models.CharField(max_length=40, null=True)
        # description = models.TextField()
        # base_price = models.FloatField()
        # keywords = models.CharField(max_length=255)
        # status = models.BooleanField(default=False)
        # updated_price = models.FloatField(default=0, blank=False)
        # bidder = models.OneToOneField(Profile, on_delete=models.CASCADE, blank=True, null=True)


# class Testurl(TestCase):
#
#     def setUp(self):
#         self.user_object = User(username='******', email='*****@*****.**')
#         self.user_object.set_password('testing321')
#         self.user_object.save()
#         self.createduser = Profile.objects.create(user=self.user_object, phone_no='1234567891', address='Sricity',
#                                                               card_no='1234567891011121')
#         self.createauction = Auction.objects.create(creator=self.createduser, scheduled_date=datetime.datetime.today()+datetime.timedelta(days=2), category='Gaming')
#         self.itemset_create = ItemSet.objects.create(ItemList=self.createauction)
#         self.items = Item.objects.create(item=self.itemset_create, item_name='stand', description='well polished',
#                                                  base_price=342, keywords='polished', )
#         self.client = None
#
#         self.request = '/auctions/Gaming/'
#         self.client = Client()
#
#     def test_url(self):
#         response = self.client.get(self.request)
#         #print(response.status_code)
#         self.assertRedirects(response, expected_url=self.request)
Пример #3
0
class RegisterUrlTest(TestCase):
    def setUp(self):
        self.user_object = User(username='******', email='*****@*****.**')
        self.user_object.set_password('testing321')
        self.user_object.save()
        #self.createduser = Profile.objects.create(user=user_object, phone_no='1234567891', address='Sricity', card_no='1234567891011121')
        self.client = None
        self.request_url = '/register/'
        # Create clients on the fly in the tests as login/logout is required

    def test_anonymous(self):
        #print('register unknown testing\n')
        #print(self.user_object.password)
        self.client = Client()
        response = self.client.get(self.request_url)

        self.assertEqual(response.status_code, 200)

    def test_after_login(self):
        #print('register authenticated testing\n')
        self.client = Client()
        self.client.login(username='******',
                          password='******')
        response = self.client.get(self.request_url)
        self.assertEqual(response.status_code, 200)

    def test_authenticated_random_id(self):
        #print('register authenticated_random testing\n')
        self.client = Client()
        self.client.login(username='******',
                          password='******')
        response = self.client.get('/register/blahblah')
        self.assertEqual(response.status_code, 404)
Пример #4
0
 def setUp(self):
     self.user_object = User(username='******', email='*****@*****.**')
     self.user_object.set_password('testing321')
     self.user_object.save()
     #self.createduser = Profile.objects.create(user=user_object, phone_no='1234567891', address='Sricity', card_no='1234567891011121')
     self.client = None
     self.request_url = '/register/'
Пример #5
0
 def setUp(self):
     self.user_object = User(username='******', email='*****@*****.**')
     self.user_object.set_password('testing321')
     self.user_object.save()
     self.createduser = Profile.objects.create(user=self.user_object,
                                               phone_no='1234567891',
                                               address='Sricity',
                                               card_no='1234567891011121')
     #self.createduser = User.objects.create_user(username="******", password="******")
     self.client = None
Пример #6
0
def create_user_google():
    user = User()

    user.name = request.values['name']
    user.mail = request.values['mail']
    user.google_access_token = request.values['access_token']

    if User.query.filter_by(mail=user.mail).first() is not None:
        return jsonify({'status': 'Name exists'})

    db.session.add(user)
    db.session.commit()
    return jsonify({'id': user.id})
Пример #7
0
 def setUp(self):
     self.user_object = User(username='******', email='*****@*****.**')
     self.user_object.set_password('testing321')
     self.user_object.save()
     self.createduser = Profile.objects.create(user=self.user_object,
                                               phone_no='1234567891',
                                               address='Sricity',
                                               card_no='1234567891011121')
     #print(self.createduser)
     self.createauction = Auction.objects.create(
         creator=self.createduser,
         scheduled_date=datetime.datetime.today() +
         datetime.timedelta(days=2),
         category='Gaming')
     self.client = None
Пример #8
0
    def _create(self,
                username,
                password=None,
                properties=None,
                property_backend=None,
                dry=False,
                transaction=True):
        assert isinstance(username, six.string_types)
        assert isinstance(password, six.string_types) or password is None
        assert isinstance(properties, dict) or properties is None

        try:
            user = User(username=username)
            if password is not None and password != '':
                user.set_password(password)
            user.save()
        except IntegrityError:
            raise UserExists("A user with the given name already exists.")

        if properties is None:
            stamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            properties = {'date joined': stamp}
        elif 'date joined' not in properties:
            stamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            properties['date joined'] = stamp

        property_backend.set_multiple(user,
                                      properties,
                                      dry=dry,
                                      transaction=transaction)
        return user
Пример #9
0
    def notify_also_commented(self, feed):
        comments = feed.get_comments()
        users = []
        for comment in comments:
            if comment.user != self.user and comment.user != feed.user:
                users.append(comment.user.pk)

        users = list(set(users))
        for user in users:
            Notification(notification_type=Notification.ALSO_COMMENTED,
                         from_user=self.user,
                         to_user=User(id=user), feed=feed).save()
Пример #10
0
def insert_dummy_data():
    # users data
    with open('Users/users.json') as file:
        data = json.load(file)
    file.close()
    for user_item in data:
        user = User(username=user_item['username'])
        user.email = user_item['email']
        user.hash_password(user_item['password'])
        db.session.add(user)
        db.session.commit()
    # posts data
    with open('Posts/posts.json') as file:
        data = json.load(file)
        for post_item in data:
            post = Post()
            post.id = post_item['id']
            post.body = post_item['body']
            post.user_id = post_item['userId']
            post.title = post_item['title']
            db.session.add(post)
            db.session.commit()
Пример #11
0
    def create_user(self, mobile, password, open_id):
        # if not re.match(r'[^_][_0-9a-zA-Z]{6,12}$', password):
        #     raise serializers.ValidationError('密码格式不正确,由数字、字母、下划线组成,首字符不能为下划线')


        try:
            user = User()
            user.username = mobile
            user.set_password(password)
            user.mobile = mobile
            user.save()
        except:
            raise serializers.ValidationError('数据库操作失败')

        return user
Пример #12
0
class TestItemset(TestCase):
    def setUp(self):
        self.user_object = User(username='******', email='*****@*****.**')
        self.user_object.set_password('testing321')
        self.user_object.save()
        self.createduser = Profile.objects.create(user=self.user_object,
                                                  phone_no='1234567891',
                                                  address='Sricity',
                                                  card_no='1234567891011121')
        self.createauction = Auction.objects.create(
            creator=self.createduser,
            scheduled_date=datetime.datetime.today() +
            datetime.timedelta(days=2),
            category='Gaming')
        self.itemset_create = ItemSet.objects.create(
            ItemList=self.createauction)
        #print(self.itemset_create)
        #self.itemset = self.createauction
        self.client = None

    def test_Itemset(self):
        self.assertTrue(
            ItemSet.objects.filter(ItemList=self.createauction).exists())
Пример #13
0
 def setUp(self):
     self.user_object = User(username='******', email='*****@*****.**')
     self.user_object.set_password('testing321')
     self.user_object.save()
     self.createduser = Profile.objects.create(user=self.user_object,
                                               phone_no='1234567891',
                                               address='Sricity',
                                               card_no='1234567891011121')
     self.createauction = Auction.objects.create(
         creator=self.createduser,
         scheduled_date=datetime.datetime.today() +
         datetime.timedelta(days=2),
         category='Gaming')
     self.itemset_create = ItemSet.objects.create(
         ItemList=self.createauction)
     self.items = Item.objects.create(
         item=self.itemset_create,
         item_name='stand',
         description='well polished',
         base_price=342,
         keywords='polished',
     )
     self.client = None
Пример #14
0
    def setUpTestData(cls):
        user_object = User(username='******', email='*****@*****.**')
        user_object.set_password('testing321')
        user_object.save()

        profile_object = Profile.objects.create(user=user_object,
                                                phone_no='1234567891',
                                                address='Sricity',
                                                card_no='1234567891011121')
Пример #15
0
def register():
    form = SignupForm()
    if form.validate_on_submit():

        user = User(email=form.email_register.data,
                    login=form.login_register.data,
                    password=form.password_register.data)
        role = Role.query.filter_by(name='user').first()
        user.roles.append(role)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('mashup_map'))
    else:
        form.flash_errors()
        return redirect(url_for('mashup_map'))
Пример #16
0
 def post(self):
     if not self.sig_up_data_validation():
         return render_template(self.template)
     try:
         user = User(
             username=request.form['username'],
             email=request.form['email'],
             password=request.form['password'],
         )
         user_profile = Profile(user=user)
         db.session.add_all([user, user_profile])
         db.session.commit()
         flash('Sign up is successful.')
         return redirect(url_for('User.sign-in'))
     except Exception:
         flash('Something wrong')
     return redirect(url_for('User.sign-up'))
Пример #17
0
def createUser(request):

	if request.method == 'POST':		
		
		form = UserForm(request.POST)		
							
		if form.is_valid():

			user = User()
			
			user.birth_date = form.cleaned_data.get('birth_date')
			user.randomId = form.cleaned_data.get('randomId')	
			user.username = form.cleaned_data.get('username')		
			user.password = form.cleaned_data.get('password')							
			user.save()		
			#import pdb; pdb.set_trace()		
			# messages.success(request, 'Form submission successful')
			return redirect('list')
		else:
			form = UserForm(request.POST)
		
		return redirect('add')	
Пример #18
0
class TestAuctionBidders(TestCase):
    def setUp(self):
        self.user_object = User(username='******', email='*****@*****.**')
        self.user_object.set_password('testing321')
        self.user_object.save()
        self.user_object1 = User(username='******', email='*****@*****.**')
        self.user_object1.set_password('testing321')
        self.user_object1.save()
        self.createduser = Profile.objects.create(user=self.user_object,
                                                  phone_no='1234567891',
                                                  address='Sricity',
                                                  card_no='1234567891011121')
        self.createduser1 = Profile.objects.create(user=self.user_object1,
                                                   phone_no='1234567890',
                                                   address='SriCity',
                                                   card_no='1234567891011190')
        self.createauction = Auction.objects.create(
            creator=self.createduser,
            scheduled_date=datetime.datetime.today() +
            datetime.timedelta(days=2),
            category='Gaming')
        self.bidder = AuctionBidders.objects.create(auction=self.createauction,
                                                    bidders=self.createduser1)
        self.client = None

    def test_AuctionBidders(self):
        self.auction = self.createauction
        self.bidders = self.createduser1
        self.assertFalse(
            Auction.objects.filter(creator=Profile.objects.get(
                phone_no='1234567890')).exists())
        self.assertTrue(
            Auction.objects.filter(creator=Profile.objects.get(
                phone_no='1234567891')).exists())
        self.assertTrue(
            AuctionBidders.objects.filter(bidders=Profile.objects.get(
                phone_no='1234567890')).exists())
Пример #19
0
def create_user():
    user = User()
    unencrypted_password = request.values['password']

    user.name = request.values['name']
    user.password = encrypt(unencrypted_password)
    user.mail = request.values['mail']
    user.role = 'user'
    if 'role' in request.values:
        user.role = request.values['role']

    if User.query.filter_by(name=user.name).first() is not None:
        return jsonify({'status': 'Name exists'})

    if User.query.filter_by(mail=user.mail).first() is not None:
        return jsonify({'status': 'Name exists'})

    db.session.add(user)
    db.session.commit()
    return jsonify({'id': user.id})
Пример #20
0
def seed_user(num_entries, overwrite, pkAdmin, pkPsyc, pkPatient):
    if overwrite:
        print("Overwriting users")
        User.objects.all().delete()
        count = 0

        # Used to store the most recent psychologist that has been read so that
        # the users before a new psychologist can be assigned to this psychologist
        currentPsychologist = None

        for _ in range(num_entries):
            # Create data for user
            usrname = fake.first_name() if count != 0 else 'a'
            print(usrname)
            email = fake.email()
            pssw = fake.password(length=15) if count != 0 else 'a'
            encrpyted_pass = hashlib.sha256((pssw).encode()).hexdigest()
            title = fake.prefix()
            first_name = fake.first_name()
            surname = fake.last_name()
            cell = fake.phone_number()
            Da_OB = fake.date_of_birth()
            gender = 'M' if count % 2 == 1 else 'F'
            prim_adress = fake.address()
            city = fake.city()
            postal_code = fake.postcode()
            country = fake.country()
            citizenship = fake.country()
            is_inactive = fake.boolean(chance_of_getting_true=50)
            created_at = fake.date()
            updated_at = created_at

            if count == 0:
                user_pass = open("all_users.txt", "w+")
            else:
                user_pass = open("all_users.txt", "a")

            # for _ in range(num_entries):
            user_pass.write("username " + usrname + " pass " + pssw + " " +
                            "\n")
            user_pass.close()

            u = User(username=usrname,
                     email_address=email,
                     password=encrpyted_pass,
                     title=title,
                     first_name=first_name,
                     surname=surname,
                     cell_number=cell,
                     date_of_birth=Da_OB,
                     gender=gender,
                     primary_address=prim_adress,
                     city=city,
                     postal_code=postal_code,
                     country=country,
                     citizenship=citizenship,
                     is_inactive=is_inactive,
                     created_at=created_at,
                     updated_at=updated_at)  # Create new User
            # used to calculate progress
            count += 1
            percent_complete = count / num_entries * 100
            print("Adding {} new Users: {:.2f}%".format(
                num_entries, percent_complete))
            print()
            u.save()

            # set first user to an admin
            if (count == 0):
                ur = User_Roles(user=u, role=pkAdmin)
                ur.save()
            else:
                print(pkAdmin)
                # random number
                rndNum = fake.random_digit()
                if rndNum >= 0 and rndNum <= 3 and currentPsychologist != None:  # rand number between 0 and 3
                    # create patient user role
                    ur = User_Roles(user=u, role=pkPatient)
                    ur.save()

                    # create a diagnosis for the patient
                    diagnosis = Diagnosis(name=fake.first_name(),
                                          description=fake.last_name())
                    diagnosis.save()

                    # create patient user
                    patientUser = Patient_User(
                        user=u,
                        psychologist=currentPsychologist,
                        diagnosis=diagnosis)
                    patientUser.save()

                elif rndNum >= 4 and rndNum <= 6 and currentPsychologist != None:  # rand number between 4 and 6
                    # create admin user role
                    ur = User_Roles(user=u, role=pkAdmin)
                    ur.save()
                elif rndNum >= 7 and rndNum <= 9 or currentPsychologist == None:  # rand number between 7 and 9
                    # create psychologist user role
                    ur = User_Roles(user=u, role=pkPsyc)
                    ur.save()

                    # create a psychologist user
                    psychologistUser = Psychologist_User(
                        user=u,
                        practitioners_id=fake.random_digit(),
                        practice_address=fake.address(),
                        practice_work_number=fake.phone_number(),
                        practice_email=fake.email())
                    psychologistUser.save()

                    # set the current psychologist to the user that has just been added
                    currentPsychologist = psychologistUser
            print("Serializing Data")
        print()
Пример #21
0
login = input("Type an username:"******"Type an email:")
password = input("Type a password:")

from MashupMap import db
from Users.models import User, Role
adm = Role.query.filter_by(name='admin').first()
u = User(login=login, email=email, password=password)
u.roles.append(adm)
db.session.add(u)
db.session.commit()
Пример #22
0
class LoginUrlTest(TestCase):
    def setUp(self):
        self.user_object = User(username='******', email='*****@*****.**')
        self.user_object.set_password('testing321')
        self.user_object.save()
        self.createduser = Profile.objects.create(user=self.user_object,
                                                  phone_no='1234567891',
                                                  address='Sricity',
                                                  card_no='1234567891011121')
        #self.createduser = User.objects.create_user(username="******", password="******")
        self.client = None

    def test_dashboard(self):
        self.client = Client()
        self.request_url = reverse('dashboard')
        response = self.client.get(self.request_url)
        #print(response.status_code)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)

    def test_create_auction(self):
        self.client = Client()
        self.request_url = reverse('create-auction')
        response = self.client.get(self.request_url)
        #print(response)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)

    def test_joined_auction(self):
        self.client = Client()
        self.request_url = '/dashboard/participated-auctions/'
        response = self.client.get(self.request_url)
        #print(response)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)

    def test_created_auction(self):
        self.client = Client()
        self.request_url = '/dashboard/created-auctions/'
        response = self.client.get(self.request_url)
        #print(response)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)

    def test_join_in_auction(self):
        self.client = Client()
        self.request_url = '/join/332'
        response = self.client.get(self.request_url)
        #print(response)?next=/join/33
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)

    #after login
    def test_dashboard_login(self):
        self.client = Client()
        self.client.login(username=self.user_object.username,
                          password=self.user_object.password)
        self.request_url = reverse('dashboard')
        response = self.client.get(self.request_url)
        #print(response.status_code)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)
        # self.assertRedirects(response, expected_url='/dashboard/')

    def test_create_auction_login(self):
        self.client = Client()
        self.client.login(username=self.user_object.username,
                          password=self.user_object.password)
        self.request_url = reverse('create-auction')
        response = self.client.get(self.request_url)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)
        # self.assertRedirects(response, expected_url='/create-auction/')

    def test_joined_auction_login(self):
        self.client = Client()
        self.client.login(username=self.user_object.username,
                          password=self.user_object.password)
        self.request_url = '/dashboard/participated-auctions/'
        response = self.client.get(self.request_url)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)
        #self.assertRedirects(response, expected_url='/dashboard/participated-auctions/')

    def test_created_auction_login(self):
        self.client = Client()
        self.client.login(username=self.user_object.username,
                          password=self.user_object.password)
        self.request_url = '/dashboard/created-auctions/'
        response = self.client.get(self.request_url)
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)
        #self.assertRedirects(response, expected_url='/dashboard/created-auctions/')

    def test_join_in_auction_login(self):
        self.client = Client()
        self.client.login(username=self.user_object.username,
                          password=self.user_object.password)
        self.request_url = '/join/332'
        response = self.client.get(self.request_url)
        #print(response)?next=/join/33
        self.assertRedirects(response,
                             expected_url='/accounts/login/?next=' +
                             self.request_url)
Пример #23
0
# import os
import random

from Dishes.models import Dish
from Tables.models import Table
from Users.models import User

user = User()
user.username = '******'
user.is_superuser = True
user.is_staff = True
user.set_password("123456")
user.save()

for i in range(10):
    table = Table(
        table_category=random.randint(0, 2),
        table_state=random.randint(0, 1),
    )
    table.save()

dishes = ['蒸羊羔',
          '蒸熊掌',
          '蒸鹿尾儿',
          '烧花鸭',
          '烧雏鸡',
          '烧子鹅',
          '卤猪',
          '卤鸭',
          '酱鸡',
          '腊肉',