Exemplo n.º 1
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)
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()
Exemplo n.º 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)
Exemplo n.º 4
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')
Exemplo n.º 5
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
Exemplo n.º 6
0
class TestAuction(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')
        #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

    def test_Auction(self):
        self.assertTrue(
            Auction.objects.filter(creator=Profile.objects.get(
                phone_no='1234567891')).exists())
Exemplo n.º 7
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')	
# 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 = ['蒸羊羔',
          '蒸熊掌',
          '蒸鹿尾儿',
          '烧花鸭',
          '烧雏鸡',
          '烧子鹅',
          '卤猪',
          '卤鸭',
          '酱鸡',
          '腊肉',
Exemplo n.º 9
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)
Exemplo n.º 10
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()