Esempio n. 1
0
 def test_multiple(self):
     formats = [
         'Hello @{0} @{1}',
         '@{0}@{1}',
         '@{0}@{0}@{1}',
     ]
     for frmt in formats:
         message = Message(user=self.users[0], text=frmt.format(self.users[0].get_username(), self.users[1].get_username()))
         self.assertListEqual(message.parse_anchors(), [self.users[0], self.users[1]], msg='format: %s' % frmt)
Esempio n. 2
0
 def test_invalid(self):
     anchored = self.users[:2]
     formats = [
         '@{0}abcdefghijklmnopqrstuvwxyz', # ... and expect this is not a valid username
         '@ {0}',
     ]
     for frmt in formats:
         message = Message(user=self.users[0], text=frmt.format(anchored[0].get_username(), anchored[1].get_username()))
         self.assertListEqual(message.parse_anchors(), [], msg='format: %s' % frmt)
Esempio n. 3
0
 def test_single(self):
     anchored = self.users[1]
     formats = [
         'Hello @{}!',
         'Hello@{}!',
         '@{}',
         '@@{}',
         '@{}@',
     ]
     for frmt in formats:
         message = Message(user=self.users[0], text=frmt.format(anchored.get_username()))
         self.assertListEqual(message.parse_anchors(), [anchored], msg='format: %s' % frmt)
Esempio n. 4
0
def new_message(message_body):
    message = Message(author=current_user._get_current_object(),
                      body=message_body)
    db.session.add(message)
    db.session.commit()
    emit('new message', {
        'message_html': render_template('chat/_message.html', message=message)
    },
         broadcast=True)
Esempio n. 5
0
    def test_message_selection(self):
        # Create new message from another author
        other_message = Message(user=self.users[1], text='Another message')
        other_message.save()

        message = Message(user=self.author, text='s/nothing/todo')
        modified = message.substitute()

        self.assertEqual(modified.user, self.author)
        self.assertEqual(modified.text, 'Hello World!')

        # Remove the other message
        other_message.delete()
Esempio n. 6
0
    def forge(message):
        """Generate fake data."""
        import random
        from sqlalchemy.exc import IntegrityError

        from faker import Faker

        fake = Faker()

        click.echo('Initializing the database...')
        db.drop_all()
        db.create_all()

        click.echo('Forging the data...')
        admin = User(nickname='Tartaurs', email='*****@*****.**')
        admin.set_password('tartarus')
        db.session.add(admin)
        db.session.commit()

        click.echo('Generating users...')
        for i in range(50):
            user = User(nickname=fake.name(),
                        bio=fake.sentence(),
                        github=fake.url(),
                        email=fake.email())
            db.session.add(user)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

        click.echo('Generating messages...')
        for i in range(message):
            message = Message(
                author=User.query.get(random.randint(1, User.query.count())),
                body=fake.sentence(),
                timestamp=fake.date_time_between('-30d', '-2d'),
            )
            db.session.add(message)

        db.session.commit()
        click.echo('Done.')
Esempio n. 7
0
 def test_valid_substitution(self):
     message = Message(user=self.author, text='s/World!/Universe!?')
     self.assertEqual(message.substitute().text, 'Hello Universe!?')
Esempio n. 8
0
 def test_no_message(self):
     message = Message(user=self.users[1], text='s/nothing/todo')
     self.assertIsNone(message.substitute())
Esempio n. 9
0
 def test_no_match(self):
     message = Message(user=self.author, text='s/bye/nothing')
     self.assertEqual(message.substitute().text, 'Hello World!')
Esempio n. 10
0
 def test_empty_match(self):
     message = Message(user=self.author, text='s//o')
     self.assertIsNone(message.substitute())
Esempio n. 11
0
 def test_empty_pattern(self):
     message = Message(user=self.author, text='s/o/')
     self.assertEqual(message.substitute().text, 'Hell World!')
Esempio n. 12
0
 def test_valid_multiple_substitutions(self):
     message = Message(user=self.author, text='s/o/p')
     self.assertEqual(message.substitute().text, 'Hellp World!')