Exemplo n.º 1
0
    def test_create_two_non_unique_person(self):
        with self.app.test_request_context():

            DB.create_all()

            person1 = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            person2 = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            DB.session.add(person1)
            DB.session.add(person2)
            DB.session.commit()

            self.assertEqual(person1.id, 1)

            self.assertEqual(person2.id, 2)
Exemplo n.º 2
0
    def test_create_two_unique_person(self):
        with self.app.test_request_context():

            DB.create_all()

            person1 = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            person2 = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            DB.session.add(person1)
            DB.session.add(person2)

            try:
                DB.session.commit()
            except Exception:
                pass
            else:
                raise Exception("IntegrityError excepted but not thrown")
Exemplo n.º 3
0
    def setUp(self):

        self.maxDiff = None

        self.app = acmapi.create_app(SQLALCHEMY_DATABASE_URI='sqlite://')
        self.app.testing = True
        
        with self.app.test_request_context():
            DB.create_all()
            person = Person.create(
                name = None,
                username = '******',
                email = None,
                website = None,
                password = '******',
            )
            DB.session.add(person)
            DB.session.commit()

            officership = Officership.create(
                person = person,
                title = 'Vice Chair',        
                start_date = datetime.date.today(),
                end_date = None,
            )

            DB.session.add(person)
            DB.session.add(officership)
            DB.session.commit()
Exemplo n.º 4
0
    def test_create_post(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            DB.session.add(person)

            post = Post.create(
                title="Post 1",
                description="This is Post 1",
                content="This is Post 1 content",
                editor=person,
                edited_datetime=datetime.datetime.today(),
                hidden=False,
                list=0,
                index=0,
            )

            DB.session.add(post)

            DB.session.commit()

            DB.session.delete(post)

            DB.session.commit()
Exemplo n.º 5
0
    def test_create_person_with_null_username(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username=None,
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            self.assertEqual(person.id, None)

            self.assertEqual(repr(person), "<Person(None)>")

            DB.session.add(person)

            try:
                DB.session.commit()
            except Exception:
                pass
            else:
                raise Exception("IntegrityError excepted but not thrown")
Exemplo n.º 6
0
    def test_create_officership_with_null_title(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            officership = Officership.create(
                person=person, title=None, start_date=datetime.date(2000, 1, 2), end_date=datetime.date(2000, 1, 3)
            )

            DB.session.add(officership)

            try:
                DB.session.commit()
            except Exception:
                pass
            else:
                raise Exception("IntegrityError excepted but not thrown")
Exemplo n.º 7
0
    def test_create_officership_with_valid_end_date(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            officership = Officership.create(
                person=person,
                title="Vice Chair",
                start_date=datetime.date(2000, 1, 2),
                end_date=datetime.date(2000, 1, 3),
            )

            DB.session.add(officership)

            DB.session.commit()

            self.assertEqual(officership.id, 1)

            self.assertEqual(repr(officership), "<Officership(1)>")

            DB.session.delete(officership)

            DB.session.commit()
Exemplo n.º 8
0
    def test_create_membership_with_null_end_date(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            membership = Membership.create(person=person, start_date=datetime.date.today(), end_date=None)

            DB.session.add(membership)

            DB.session.commit()

            self.assertEqual(membership.id, 1)

            self.assertEqual(repr(membership), "<Membership(1)>")

            DB.session.delete(membership)

            DB.session.commit()
Exemplo n.º 9
0
    def test_create_two_non_unique_events(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            DB.session.add(person)

            event = Event.create(
                title="Event 1",
                description="This is Event 1",
                speaker="By the Event 1 speaker",
                location="In the Event Room",
                editor=person,
                edited_datetime=datetime.datetime.today(),
                start=datetime.datetime(2000, 1, 2),
                end=datetime.datetime(2000, 1, 3),
                canceled=False,
                hidden=False,
                list=0,
                index=0,
            )

            DB.session.add(event)

            event = Event.create(
                title="Event 1",
                description="This is Event 1",
                speaker="By the Event 1 speaker",
                location="In the Event Room",
                editor=person,
                edited_datetime=datetime.datetime.today(),
                start=datetime.datetime(2000, 1, 2),
                end=datetime.datetime(2000, 1, 3),
                canceled=False,
                hidden=False,
                list=0,
                index=0,
            )

            DB.session.add(event)

            try:
                DB.session.commit()
            except Exception:
                pass
            else:
                raise Exception("IntegrityError excepted but not thrown")
Exemplo n.º 10
0
    def test_create_event_with_start_before_end(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            event = Event.create(
                title="Event 1",
                description="This is Event 1",
                speaker="By the Event 1 speaker",
                location="In the Event Room",
                editor=person,
                edited_datetime=datetime.datetime.today(),
                start=datetime.datetime(2000, 1, 2),
                end=datetime.datetime(2000, 1, 3),
                canceled=False,
                hidden=False,
                list=0,
                index=0,
            )

            DB.session.add(person)

            DB.session.add(event)

            DB.session.commit()

            DB.session.delete(event)

            DB.session.commit()
Exemplo n.º 11
0
    def test_create_person(self):
        with self.app.test_request_context():

            DB.create_all()

            person = Person.create(
                name="John Doe",
                username="******",
                email="*****@*****.**",
                website="http://johnd.com",
                password="******",
            )

            self.assertEqual(person.id, None)

            self.assertEqual(repr(person), "<Person(None)>")

            DB.session.add(person)

            DB.session.commit()

            self.assertEqual(person.id, 1)

            self.assertEqual(repr(person), "<Person(1)>")

            self.assertEqual(person.name, "John Doe")

            self.assertEqual(person.username, "johnd")

            self.assertEqual(person.email, "*****@*****.**")

            self.assertEqual(person.website, "http://johnd.com")

            DB.session.delete(person)

            DB.session.commit()
Exemplo n.º 12
0
#!/bin/python2 
from acmapi import create_app, DB
from acmapi.models import Person, Officership
import datetime

app = create_app(SQLALCHEMY_DATABASE_URI='sqlite:///')

with app.test_request_context():
    DB.drop_all()
    DB.create_all()
    person = Person.create(
        name = None,
        username = '******',
        email = None,
        website = None,
        password = '******',
    )
    DB.session.add(person)
    DB.session.commit()

    officership = Officership.create(
        person = person,
        title = 'Root',        
        start_date = datetime.date.today(),
        end_date = None,
    )

    DB.session.add(person)
    DB.session.add(officership)
    DB.session.commit()