Exemple #1
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    user = User(username='******', email='*****@*****.**', password='******')
    user.save()
Exemple #2
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    user = User(username='******', email='*****@*****.**', password='******')
    user.save()
Exemple #3
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    admin = User(username=app.config['ADMIN_USERNAME'], email=app.config['ADMIN_EMAIL'], password=app.config['ADMIN_PASSWORD'])
    admin.save()
 def test_update_invited_user(self):
     #self.start_smtp()
     bob = User(self.email)
     res1 = bob.invite()
     res2 = bob.update(status="active")
     self.assertEqual(res2.json()['user']['status'], 'active')
     self.assertEqual(res1.json()['user']['status'], 'invited')
 def test_delete_unknown_user(self):
     random_user = User("*****@*****.**")
     r = random_user.delete()
     self.assertEqual({
         'success': False,
         'reason': 'no-such-user'
     }, r.json())
 def test_patch_group_remove_user(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name, users=[bob.email])
     res1 = group.create()
     res2 = group.update(remove_users=[bob.email])
     self.assertEqual(res2.json()['group']['users'], [])
 def test_patch_group_add_site(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = group.update(add_sites=[self.target_url])
     self.assertEqual(res2.json()['group']['sites'][0], self.target_url)
    def test_update_user(self):
        group1 = Group("group1")
        group2 = Group("group2")
        group1.create()
        group2.create()

        # Create a user
        bob = User(self.email, name="Bob", role="user", groups=[group1.group_name])
        res2 = bob.create()
        self.assertEqual(res2.json()['user']['email'], bob.email)
        self.assertEqual(res2.json()['user']['groups'], [group1.group_name])
        self.assertEqual(res2.json()["user"]["role"], "user")

        # Update the user
        res3 = bob.update(name="Bobby", role="administrator", groups=[group2.group_name])
        self.assertEqual(res3.json()["success"], True)
        self.assertEqual(res3.json()['user']['email'], bob.email)
        self.assertEqual(res3.json()['user']['name'], bob.name)
        self.assertEqual(res3.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res3.json()["user"]["role"], "administrator")

        # Make sure the user stored in the db is correct
        res4 = bob.get()
        self.assertEqual(res4.json()['success'], True)
        self.assertEqual(res4.json()['user']['email'], bob.email)
        self.assertEqual(res4.json()['user']['name'], bob.name)
        self.assertEqual(res4.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res4.json()['user']['role'], "administrator")
 def test_get_all_groups(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = Groups().get()
     self.assertEqual(res2.json()['groups'][0], res1.json()['group'])
 def test_patch_group_add_site(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = group.update(add_sites=[self.target_url])
     self.assertEqual(res2.json()['group']['sites'][0], self.target_url)
 def test_delete_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.delete()
     self.assertEqual(res.json()['success'], True)
 def test_patch_group_remove_user(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name, users=[bob.email])
     res1 = group.create()
     res2 = group.update(remove_users=[bob.email])
     self.assertEqual(res2.json()['group']['users'], [])
 def test_patch_group_add_user(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.update(add_users=[bob.email])
     self.assertEqual(res.json()['group']['users'], group.users)
    def test_decline_invite(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])

        # recipient has declined the invitation
        res3 = invite.update(invite_id, "decline", login=recipient.email)
        self.assertEqual(res3.json()['invite']['status'], 'declined')

        # when recipient declined, user account is deleted (bug #175)
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # when recipient declined, user is also not part of a group anymore (bug #175)
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
    def test_delete_not_used_invitation(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])
        # also, this user is still marked as "invited"
        self.assertEqual(res2.json()['user']['status'], 'invited')

        # admin deletes this invitation off minion
        res3 = invite.delete(invite_id)
        self.assertEqual(res3.json()["success"], True)

        # since invitation is gone, user should be gone too
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # recipient is also gone from any group association
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
 def test_get_all_groups(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = Groups().get()
     self.assertEqual(res2.json()['groups'][0], res1.json()['group'])
 def test_delete_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.delete()
     self.assertEqual(res.json()['success'], True)
    def test_update_user(self):
        group1 = Group("group1")
        group2 = Group("group2")
        group1.create()
        group2.create()

        # Create a user
        bob = User(self.email,
                   name="Bob",
                   role="user",
                   groups=[group1.group_name])
        res2 = bob.create()
        self.assertEqual(res2.json()['user']['email'], bob.email)
        self.assertEqual(res2.json()['user']['groups'], [group1.group_name])
        self.assertEqual(res2.json()["user"]["role"], "user")

        # Update the user
        res3 = bob.update(name="Bobby",
                          role="administrator",
                          groups=[group2.group_name])
        self.assertEqual(res3.json()["success"], True)
        self.assertEqual(res3.json()['user']['email'], bob.email)
        self.assertEqual(res3.json()['user']['name'], bob.name)
        self.assertEqual(res3.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res3.json()["user"]["role"], "administrator")

        # Make sure the user stored in the db is correct
        res4 = bob.get()
        self.assertEqual(res4.json()['success'], True)
        self.assertEqual(res4.json()['user']['email'], bob.email)
        self.assertEqual(res4.json()['user']['name'], bob.name)
        self.assertEqual(res4.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res4.json()['user']['role'], "administrator")
 def test_update_invited_user(self):
     #self.start_smtp()
     bob = User(self.email)
     res1 = bob.invite()
     res2 = bob.update(status="active")
     self.assertEqual(res2.json()['user']['status'], 'active')
     self.assertEqual(res1.json()['user']['status'], 'invited')
 def test_invite_user(self):
     #self.start_smtp()
     bob = User(self.email)
     res = bob.invite()
     self.assertEqual(set(res.json()['user'].keys()),
                      set(self.expected_inner_keys))
     self.assertEqual(res.json()['user']['status'], 'invited')
 def test_get_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.get()
     self.assertEqual(res.json()['group']['name'], group.group_name)
     self.assertEqual(res.json()['group']['description'], group.description)
    def test_get_all_users(self):
        bob = User(self.email)
        bob.create()

        res = Users().get()
        _expected = list(self.expected_inner_keys) + ["sites"]
        self.assertEqual(set(res.json()['users'][0].keys()), set(_expected))
        self.assertEqual(1, len(res.json()['users']))
 def test_login_non_active_user(self):
     bob = User(self.email)
     res1 = bob.create()
     # change user to banned
     res2 = bob.update(status="banned")
     res3 = bob.login()
     self.assertEqual(res3.json()['success'], False)
     self.assertEqual(res3.json()['reason'], 'banned')
 def test_create_duplicate_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.create()
     self.assertEqual(res.json()['success'], False)
     self.assertEqual(res.json()['reason'], 'group-already-exists')
 def test_get_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.get()
     self.assertEqual(res.json()['group']['name'], group.group_name)
     self.assertEqual(res.json()['group']['description'], group.description)
 def test_login_non_active_user(self):
     bob = User(self.email)
     res1 = bob.create()
     # change user to banned
     res2 = bob.update(status="banned")
     res3 = bob.login()
     self.assertEqual(res3.json()['success'], False)
     self.assertEqual(res3.json()['reason'], 'banned')
 def test_create_duplicate_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.create()
     self.assertEqual(res.json()['success'], False)
     self.assertEqual(res.json()['reason'], 'group-already-exists')
Exemple #28
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    admin = User(
        username=app.config["ADMIN_USERNAME"], email=app.config["ADMIN_EMAIL"], password=app.config["ADMIN_PASSWORD"]
    )
    admin.save()
    def test_get_all_users(self):
        bob = User(self.email)
        bob.create()

        res = Users().get()
        _expected = list(self.expected_inner_keys) + ["sites"]
        self.assertEqual(set(res.json()['users'][0].keys()),
            set(_expected))
        self.assertEqual(1, len(res.json()['users']))
 def test_create_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name, description=self.group_description)
     res = group.create()
     self.assertEqual(set(res.json().keys()), set(["success", "group"]))
     self.assertEqual(set(res.json()["group"].keys()),
         set(["id", "created", "name", "description", "users", "sites"]))
     self.assertEqual(res.json()['group']['name'], self.group_name)
     self.assertEqual(res.json()['group']['description'], self.group_description)
    def test_sender_not_found(self):
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()

        invite = Invite(self.email, recipient.email)
        res = invite.create()

        # sender self.email has not yet been created in minion
        self.assertEqual(res.json()['success'], False)
        self.assertEqual(res.json()['reason'], 'sender-not-found-in-user-record')
    def test_sender_not_found(self):
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()

        invite = Invite(self.email, recipient.email)
        res = invite.create()

        # sender self.email has not yet been created in minion
        self.assertEqual(res.json()['success'], False)
        self.assertEqual(res.json()['reason'],
                         'sender-not-found-in-user-record')
Exemple #33
0
 def create_plan(self):
     self.plan = Plan(self.TEST_PLAN)
     res = self.plan.create()
     self.assertEqual(res.json()["success"], True)
     self.user = User(self.email)
     self.user.create()
     self.site = Site(self.target_url, plans=[self.plan.plan["name"]])
     self.site.create()
     self.group = Group("testgroup",
                        sites=[self.site.url],
                        users=[self.user.email])
     self.group.create()
 def test_create_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name, description=self.group_description)
     res = group.create()
     self.assertEqual(set(res.json().keys()), set(["success", "group"]))
     self.assertEqual(
         set(res.json()["group"].keys()),
         set(["id", "created", "name", "description", "users", "sites"]))
     self.assertEqual(res.json()['group']['name'], self.group_name)
     self.assertEqual(res.json()['group']['description'],
                      self.group_description)
 def test_delete_user(self):
     # Create a user
     bob = User(self.email)
     r = bob.create()
     j = r.json()
     self.assertEqual(True, j['success'])
     # Delete the user
     r = bob.delete()
     self.assertEqual({'success': True}, r.json())
     # Make sure the user is gone
     r = bob.delete()
     self.assertEqual({'success': False, 'reason': 'no-such-user'}, r.json())
    def test_accept_invite_with_a_different_login_email(self):
        # we allow recipient to login with a different email address.
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group and a site and add the recipient to the group
        site = Site(self.target_url)
        res2 = site.create()

        # create a group in minion
        group = Group(self.group_name, sites=[site.url], users=[recipient.email])
        group.create()

        # ensure user and site are in this new group
        res3 = group.get()
        self.assertEqual(res3.json()["group"]["sites"], [site.url])
        self.assertEqual(res3.json()["group"]["users"], [recipient.email])

        # user should have access to the group and the site
        res4 = recipient.get()
        self.assertEqual(res4.json()["user"]["sites"], [site.url])
        self.assertEqual(res4.json()["user"]["groups"], [group.group_name])

        # recipient accepts the invitation with a different login email address
        actual_login = self.random_email()
        recipient_2 = User(actual_login)
        res5 = invite.update(invite_id, "accept", login=recipient_2.email)
        self.assertEqual(res5.json()["success"], True)

        # upon invitation acceptance, user status changed to active
        res6 = recipient_2.get()
        self.assertEqual(res6.json()['user']['email'], recipient_2.email)
        self.assertEqual(res6.json()['user']['status'], 'active')
        # the new email address has access to the group and site
        self.assertEqual(res6.json()["user"]["groups"], [group.group_name])
        self.assertEqual(res6.json()["user"]["sites"], [site.url])

        # if we query the old recipient email, it should not be found
        res7 = recipient.get()
        self.assertEqual(res7.json()["success"], False)
        self.assertEqual(res7.json()["reason"], "no-such-user")

        # group should agree that user and site are still member of the group
        res8 = group.get()
        self.assertEqual(res8.json()["group"]["sites"], [site.url])
        self.assertEqual(res8.json()["group"]["users"], [recipient_2.email])
    def test_get_scan_details_filter_with_incorrect_user(self):
        # Scan is started by Bob and only Bob's group has access to target_url.
        # Alice does not belong to Bob's group so she has no permission to the scan
        scan = Scan(self.user.email, self.TEST_PLAN["name"], {"target": self.target_url})
        res1 = scan.create()
        scan_id = res1.json()['scan']['id']

        alice = User("*****@*****.**")
        res2 = alice.create()
        self.assertEqual(res2.json()["success"], True)

        res2 = scan.get_scan_details(scan_id, email=alice.email)
        self.assertEqual(res2.json()["success"], False)
        self.assertEqual(res2.json()["reason"], "not-found")
Exemple #38
0
class KitTestCase(TestCase):

    def create_app(self):
        return AppFactory(TestingConfig).get_app(__name__)

    def setUp(self):
        db.create_all()
        self.user = User(username='******', email='*****@*****.**', password='******')
        self.user.save()

    def tearDown(self):
        db.session.remove()
        db.drop_all()

    def assertContains(self, response, text, count=None, status_code=200, msg_prefix=''):
        """
        Asserts that a response indicates that some content was retrieved
        successfully, (i.e., the HTTP status code was as expected), and that
        ``text`` occurs ``count`` times in the content of the response.
        If ``count`` is None, the count doesn't matter - the assertion is true
        if the text occurs at least once in the response.
        """

        if msg_prefix:
            msg_prefix += ": "

        self.assertEqual(
            response.status_code,
            status_code,
            msg_prefix + (
                "Couldn't retrieve content: Response code was %d "
                "(expected %wd)" % (response.status_code, status_code)
            )
        )

        real_count = response.data.count(text.encode())
        if count is not None:
            self.assertEqual(
                real_count,
                count,
                msg_prefix + (
                    "Found %d instances of '%s' in response "
                    "(expected %d)" % (real_count, text, count)
                )
            )
        else:
            self.assertTrue(
                real_count != 0,
                msg_prefix + "Couldn't find '%s' in response" % text
            )
    def test_post_invite(self):
        sender = User(self.email, name="Bob")
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()["success"], True)

        expected_inner_keys = ("id", "recipient", "sender", "sent_on", \
                "accepted_on", "sender_name", "recipient_name", \
                "status", "expire_on", "max_time_allowed", "notify_when")

        self.assertEqual(set(res.json()['invite'].keys()),
                         set(expected_inner_keys))

        self.assertEqual(res.json()['invite']['recipient'], recipient.email)
        self.assertEqual(res.json()['invite']['sender'], sender.email)
        self.assertEqual(res.json()['invite']['recipient_name'],
                         recipient.name)
        self.assertEqual(res.json()['invite']['sender_name'], sender.name)
        self.assertEqual(True, res.json()['invite']['accepted_on'] is None)
        self.assertEqual(True, res.json()['invite']['sent_on'] is not None)
        self.assertEqual(True, res.json()['invite']['id'] is not None)
        # issue 172
        self.assertEqual(res.json()['invite']['status'], 'pending')
    def test_decline_invite(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])

        # recipient has declined the invitation
        res3 = invite.update(invite_id, "decline", login=recipient.email)
        self.assertEqual(res3.json()['invite']['status'], 'declined')

        # when recipient declined, user account is deleted (bug #175)
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # when recipient declined, user is also not part of a group anymore (bug #175)
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
    def test_delete_not_used_invitation(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])
        # also, this user is still marked as "invited"
        self.assertEqual(res2.json()['user']['status'], 'invited')

        # admin deletes this invitation off minion
        res3 = invite.delete(invite_id)
        self.assertEqual(res3.json()["success"], True)

        # since invitation is gone, user should be gone too
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # recipient is also gone from any group association
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
 def test_delete_user(self):
     # Create a user
     bob = User(self.email)
     r = bob.create()
     j = r.json()
     self.assertEqual(True, j['success'])
     # Delete the user
     r = bob.delete()
     self.assertEqual({'success': True}, r.json())
     # Make sure the user is gone
     r = bob.delete()
     self.assertEqual({
         'success': False,
         'reason': 'no-such-user'
     }, r.json())
    def test_get_group(self):
        user = User(self.email)
        user.create()

        group = Group(self.group_name,
                      description=self.group_description,
                      users=[user.email])
        res1 = group.create()

        res2 = group.get()
        self.assertEqual(res2.json()["success"], True)
        self.assertEqual(res2.json()['group']['name'], group.group_name)
        self.assertEqual(res2.json()['group']['description'],
                         group.description)
        self.assertEqual(res2.json()['group']['users'], [user.email])
Exemple #44
0
def populate_users():
    session = DBSession()
    users = [
        ('umeboshi', 1, 'admin'),
        ('gpprine', 2, 'admin'),
        ('superman', 3, 'host'),
        ('batman', 4, 'host'),
        ('hubclerk', 5, 'host')
        ]
    with transaction.manager:
        for uname, id, role in users:
            user = User(uname, id)
            user.role = role
            user.default_audience_id = 1
            session.add(user)
Exemple #45
0
    def test_get_scan_details_filter_with_incorrect_user(self):
        # Scan is started by Bob and only Bob's group has access to target_url.
        # Alice does not belong to Bob's group so she has no permission to the scan
        scan = Scan(self.user.email, self.TEST_PLAN["name"],
                    {"target": self.target_url})
        res1 = scan.create()
        scan_id = res1.json()['scan']['id']

        alice = User("*****@*****.**")
        res2 = alice.create()
        self.assertEqual(res2.json()["success"], True)

        res2 = scan.get_scan_details(scan_id, email=alice.email)
        self.assertEqual(res2.json()["success"], False)
        self.assertEqual(res2.json()["reason"], "not-found")
Exemple #46
0
 def has_permission(self, per_name):
     self.user = User(self.user.username)
     if self.user.permission is not None and self.user.permission.get(
             per_name) == 1:
         return True
     else:
         return False
def start(bot, update):
	id = update.message.chat.id
	if id > 0: # groups ignored
		keyboard = [['Status', 'Media'], 
			        ['Settings', 'Chat'], 
			        ['Referral link']]
		reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
		welcome_text = '''Welcome to the AIRDROP CTLgroup bot!
						To get 25 CTLcoin please do the following:
						- specify in the bot settings the links to your reposts from our Facebook and Twitter pages
						- subscribe to our telegram channel @CryptoTradeLine and go to chat
						To get additional tokens invite your friends to the bot and get 1 CTLcoin for each one connected to the bot'''
		bot.send_message(chat_id=id, text=welcome_text, reply_markup=reply_markup)
		msg = update.message.text.replace('/start', '').strip()
		entered_user = User.query.filter(User.id==id).first()
		if entered_user == None:

			db_session.add(User(id=id, name=update.message.chat.username, inviter=msg))
			db_session.commit()
			print('commited')
			if msg != '' and msg != str(id):
				bonus = 1
				inviter = User.query.filter(User.id==msg).first()
				inviter.tokens_acc += bonus
				inviter.refs += 1
				tokens_left = Parametr.query.filter(Parametr.parametr=='Tokens_left').first()
				tokens_left.value_flt -= bonus
				db_session.commit()
				bot.send_message(chat_id=msg, text='+ %s tokens for friend inviting ' % bonus + update.message.chat.first_name)
			elif msg == str(id):
				update.message.text_reply('You have received a link to yourself, do /start')
		elif msg == str(id):
			bot.send_message(chat_id=id, text='You invited yourself')
 def create_plan(self):
     self.plan = Plan(self.TEST_PLAN)
     res = self.plan.create()
     self.assertEqual(res.json()["success"], True)
     self.user = User(self.email)
     self.user.create()
     self.site = Site(self.target_url, plans=[self.plan.plan["name"]])
Exemple #49
0
def createUser(login_session):
    newUser = User(name=login_session['username'], email=login_session[
        'email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
Exemple #50
0
def register():
    if request.method == "POST":
        name = request.form['name']
        login = request.form['login']
        password = request.form['password']
        token = hashlib.md5(bytes(random.randint(1, 10000000))).hexdigest()
        expiration = (datetime.now() + timedelta(days=30))
        user_id = int(User.query.order_by(User.id.desc()).first().id) + 1
        newUser = User(id=user_id,
                       name=name,
                       login=login,
                       password=password,
                       token=token,
                       expiration=expiration)

        if userReg(login):
            try:
                db.session.add(newUser)
                db.session.commit()
                return redirect('/')
            except:
                return print("При добавлении возникла ошибка")
        else:
            print('Not unique login')
    return render_template('register.html')
def createTeacher(info_dict):

    name = info_dict['tc_name']
    username = info_dict['tc_id']
    passkey = info_dict['tc_pass']
    subject = info_dict['tc_course']
    newTeacher = Teachers(name=name, id=username)
    newUser = User(id=username, pwd=passkey, role='Teacher')

    for key, pair in info_dict.items():

        if key.startswith('Section_name'):
            sec = pair
            sem = info_dict[f'Semester_name{key[12:]}']

            classroom = Class.query.filter_by(section=sec,
                                              semester=sem).first()
            sub = Subject.query.filter_by(name=subject).first()

            if classroom == None:
                classroom = createClass(sec, sem)

            if sub == None:
                sub = createSubject(subject)

            classroom.subjects.append(sub)
            newTeacher.classes.append(classroom)
            newTeacher.subject = sub.id

    db.session.add(newTeacher)
    db.session.add(newUser)
    db.session.commit()
Exemple #52
0
 def testUser(self):
     """
     The configured user should be kept in model
     """
     user1 = User.get_by_id(1)
     self.assertIsNotNone(user1)
     self.assertEquals(self.username, user1.username)
Exemple #53
0
 def from_row(cls, row):
     post = row['value']
     user = User.from_username(post['user'])
     created = datetime(*post['created'])
     published = post['published']
     if published:
         published = datetime(*published)
     return cls(title=post['title'], content=post['content'], user=user, created=created, published=published)
    def test_send_invite_with_groups_and_sites(self):
        sender = User(self.email, name="Bob")
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()

        # create the invitation
        invite = Invite(sender.email, recipient.email)
        res = invite.create() 
        invite_id = res.json()['invite']['id']

        # create a site in minion
        site = Site(self.target_url)
        res2 = site.create()
        site_id = res2.json()["site"]["id"]

        # Uncomment the following checks when #297 is resolved.
        # create a group in minion
        group = Group(self.group_name, sites=[site.url], users=[recipient.email])
        res3 = group.create()

        # site should exists in group and recipient should also be in the same group
        res4 = group.get()
        self.assertEqual(res4.json()['group']['users'], [recipient.email,])

        res5 = site.get(site_id)
        self.assertEqual(res5.json()["site"]["groups"], [group.group_name])

        # finally, if we query recipient's user object, user should be in
        # the group and have access to a site.
        res6 = recipient.get()
        self.assertEqual(res6.json()["user"]["sites"], [site.url])
        self.assertEqual(res6.json()["user"]["groups"], [group.group_name])
    def test_get_user(self):
        group = Group("foo")
        res = group.create()
        self.assertEqual(True, res.json()['success'])
        # Add a user
        bob = User(self.email, name="Bob", groups=["foo"])
        r = bob.create()
        j = r.json()
        self.assertEqual(True, r.json()['success'])

        # Make sure the user stored in the db is correct
        r = User(self.email).get()
        j = r.json()
        self.assertEqual(True, j['success'])
        self.assertEqual(self.email, j['user']['email'])
        self.assertEqual("Bob", j['user']['name'])
        self.assertEqual(['foo'], j['user']['groups'])
        self.assertEqual('user', j['user']['role'])
 def create_plan(self):
     self.plan = Plan(self.TEST_PLAN)
     res = self.plan.create()
     self.assertEqual(res.json()["success"], True)
     self.user = User(self.email)
     self.user.create()
     self.site = Site(self.target_url, plans=[self.plan.plan["name"]])
     self.site.create()
     self.group = Group("testgroup", sites=[self.site.url], users=[self.user.email])
     self.group.create()
    def test_delete_user_also_removes_group_membership(self):
        # Create a user and add it to a group
        bob = User(self.email)
        res = bob.create()
        self.assertEqual(res.json()['success'], True)

        group = Group(self.group_name, users=[bob.email])
        res2 = group.create()
        self.assertEqual(res2.json()['success'], True)

        # Make sure the user is in the group
        res3 = group.get()
        self.assertEqual(res3.json()['group']['users'], [bob.email])

        # Delete the user
        res4 = bob.delete()
        self.assertEqual(res4.json()["success"], True)

        # Make sure the user is not in the group anymore
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
    def test_post_invite(self):
        sender = User(self.email, name="Bob")
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()["success"], True)

        expected_inner_keys = ("id", "recipient", "sender", "sent_on", \
                "accepted_on", "sender_name", "recipient_name", \
                "status", "expire_on", "max_time_allowed", "notify_when")

        self.assertEqual(set(res.json()['invite'].keys()),
            set(expected_inner_keys))

        self.assertEqual(res.json()['invite']['recipient'], recipient.email)
        self.assertEqual(res.json()['invite']['sender'], sender.email)
        self.assertEqual(res.json()['invite']['recipient_name'], recipient.name)
        self.assertEqual(res.json()['invite']['sender_name'], sender.name)
        self.assertEqual(True, res.json()['invite']['accepted_on'] is None)
        self.assertEqual(True, res.json()['invite']['sent_on'] is not None)
        self.assertEqual(True, res.json()['invite']['id'] is not None)
        # issue 172
        self.assertEqual(res.json()['invite']['status'], 'pending')
    def test_invite_an_existing_user(self):
        sender = User(self.email)
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        # don't invite, do a physical creation
        recipient.create()

        # try invite recipient even though recipient is an active member
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()['success'], False)
        self.assertEqual(res.json()['reason'], 'recipient-already-joined')