Пример #1
0
class TestCommunity(unittest.TestCase):
    """ Test the Maker model. """

    def setUp(self):
        """ Setup Tests """
        self.community = Community(
            name='Test Community',
            slug=Community.get_slug_for_name('Test_Community')
            )

        self.community.put()

        self.maker = Maker(community=self.community,
                           store_name="Test Store",
                           store_description='A test store',
                           full_name="Tina Test",
                           email='*****@*****.**',
                           paypal_business_account_email = "*****@*****.**",
                           phone_number = "530111121",
                           location = "Right Here",
                           mailing_address = "111 Test Lane, Testable, CA 95945",
                           approval_status = 'Approved',
                           tags=['test', 'testy', 'testiferous'])
        self.maker.put()


    def tearDown(self):
        self.maker.delete()
        self.community.delete()

    def testEmailValidation(self):
        try:
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
        except db.BadValueError:
            self.fail('Threw exception for good email address: ' + self.maker.paypal_business_account_email)

        try:
            self.maker.paypal_business_account_email = "thisshouldfail"
            self.maker.put()
            self.maker.paypal_business_account_email = "badexample.com"
            self.maker.put()            
            self.maker.paypal_business_account_email = "*****@*****.**"
            self.maker.put()
            self.maker.paypal_business_account_email = "bad@example_host.com"
            self.maker.put()            
        except db.BadValueError:
            # We expect an exception, this is success
            return

        self.fail('Failed to throw exception for bad email address: ' + self.maker.paypal_business_account_email)
Пример #2
0
def question():
    """发帖页面:说出你的想法"""
    if request.method == 'GET':
        return render_template('question.html')
    else:
        title = request.form.get('title')
        context = request.form.get('context')
        community = Community(title=title, context=context)
        user_name = session.get('user_name')
        user = User.query.filter(User.username == user_name).first()
        community.author = user
        db.session.add(community)
        db.session.commit()
        return redirect(url_for('index'))
Пример #3
0
def create_community(community_name, community_description):
    """Create and return new community"""

    community = Community(community_name=community_name, community_description=community_description)

    db.session.add(community)
    db.session.commit()

    return community
Пример #4
0
    def setUp(self):
        """ Setup Tests """
        self.community = Community(
            name='Test Community',
            slug=Community.get_slug_for_name('Test_Community')
            )

        self.community.put()

        self.maker = Maker(community=self.community,
                           store_name="Test Store",
                           store_description='A test store',
                           full_name="Tina Test",
                           email='*****@*****.**',
                           paypal_business_account_email = "*****@*****.**",
                           phone_number = "530111121",
                           location = "Right Here",
                           mailing_address = "111 Test Lane, Testable, CA 95945",
                           approval_status = 'Approved',
                           tags=['test', 'testy', 'testiferous'])
        self.maker.put()
Пример #5
0
def load_communities():
    """ Load communities into our database """

    a = Community(user_id=1, community_name="guitar")
    b = Community(user_id=2, community_name="nintendo")
    c = Community(user_id=3, community_name="gameofthrones")
    d = Community(user_id=4, community_name="starwars")
    e = Community(user_id=5, community_name="python")
    f = Community(user_id=1, community_name="cplusplus")
    g = Community(user_id=1, community_name="marvel")
    h = Community(user_id=1, community_name="sanfrancisco")

    db.session.add_all([a, b, c, d, e, f, g, h])
    db.session.commit()
    print("Communities 😚")
Пример #6
0
 def setUp(self):
     """ Setup Tests """
     self.community = Community(name='Test Community',
                                slug=Community.get_slug_for_name('Test_Community'),
                                use_sandbox=True,
                                fee_percentage=10.0,
                                fee_minimum=0.3,
                                paypal_fee_percentage=2.9,
                                paypal_fee_minimum=0.3,
                                paypal_sandbox_business_id = '*****@*****.**',
                                paypal_sandbox_email_address = '*****@*****.**',
                                paypal_sandbox_api_username = '******',
                                paypal_sandbox_api_password = '******',
                                paypal_sandbox_api_signature = 'sand_api_sig',
                                paypal_sandbox_application_id = 'sand_api_app_id',
                                paypal_business_id = '*****@*****.**',
                                paypal_email_address = '*****@*****.**',
                                paypal_api_username = '******',
                                paypal_api_password = '******',
                                paypal_api_signature = 'api_sig',
                                paypal_application_id = 'api_app_id',
                                )
     self.community.put()
Пример #7
0
def new_community():
    form = CommunityForm()

    if form.validate_on_submit():

        name = (form.community_name.data).lower()
        name = name.replace(" ", "")
        # Check if Commmunity name exists. Redirect if it does. Otherwise, process.
        if Community.query.filter_by(community_name=name).first():
            flash('Community name taken. Please try again.', 'danger')
            redirect('/community/new')
        else:
            community = Community(user_id=current_user.id, community_name=name)
            db.session.add(community)
            db.session.commit()
            flash('Your community has been created!', 'success')
            return redirect(url_for('community_list'))

    return render_template('create_community.html', form=form)
Пример #8
0
]

# input some meanings and forms into the languages
for eachlanguage in languageList:
    eachlanguage.formMeaningDict = {}

language1.add_meaning("Lizard", ([("wiri-wiri", 75, 0), ("mirdi", 10, 0)]))
language2.add_meaning("Lizard", ([("wiri-wiri", 15, 0)]))
language3.add_meaning("Lizard", ([("wiri-wiri", 50, 0), ("mirdi", 10, 0)]))
language4.add_meaning("Lizard", ([("julirri", 80, 0), ("jindararda", 40, 0)]))
language5.add_meaning("Lizard", ([("jindararda", 70, 0),
                                  ("wiri-wiri", 50, 0)]))
language6.add_meaning("Lizard", ([("mirdi", 60, 0), ("jindararda", 60, 0)]))

# define the communities which
community1 = Community("Com1", language1, 10)
community2 = Community("Com2", language2, 10)
community3 = Community("Com3", language3, 10)
community4 = Community("Com4", language4, 10)
community5 = Community("Com5", language5, 10)
community6 = Community("Com6", language6, 10)

communityList = [
    community1, community2, community3, community4, community5, community6
]
# create network
socialNet = nx.Graph()
# create nodes from list of community objects
# community objects ARE the nodes in this model
socialNet.add_nodes_from(communityList)
# add weighted connections between the nodes.
Пример #9
0
class TestCommunity(unittest.TestCase):
    """ Test the Community model. """

    def setUp(self):
        """ Setup Tests """
        self.community = Community(name='Test Community',
                                   slug=Community.get_slug_for_name('Test_Community'),
                                   use_sandbox=True,
                                   fee_percentage=10.0,
                                   fee_minimum=0.3,
                                   paypal_fee_percentage=2.9,
                                   paypal_fee_minimum=0.3,
                                   paypal_sandbox_business_id = '*****@*****.**',
                                   paypal_sandbox_email_address = '*****@*****.**',
                                   paypal_sandbox_api_username = '******',
                                   paypal_sandbox_api_password = '******',
                                   paypal_sandbox_api_signature = 'sand_api_sig',
                                   paypal_sandbox_application_id = 'sand_api_app_id',
                                   paypal_business_id = '*****@*****.**',
                                   paypal_email_address = '*****@*****.**',
                                   paypal_api_username = '******',
                                   paypal_api_password = '******',
                                   paypal_api_signature = 'api_sig',
                                   paypal_application_id = 'api_app_id',
                                   )
        self.community.put()

    def tearDown(self):
        memcache.flush_all()
        self.community.delete()

    def testSlugs(self):
        name = 'name with a space'
        slug = Community.get_slug_for_name(name)
        self.assertTrue(slug == 'name-with-a-space')

    def testAdImpressions(self):
        advertisement = Advertisement(name='Test')
        advertisement.put()
        self.assertTrue(advertisement.remaining_impressions() == 0)
        advertisement.refill_impressions(10000)
        self.assertTrue(advertisement.remaining_impressions() == 10000)
        advertisement.decrement_impressions()
        advertisement.decrement_impressions()
        self.assertTrue(advertisement.remaining_impressions() == 9998)

    def testCredentials(self):
        self.community.use_sandbox = True
        self.assertTrue(self.community.business_id == self.community.paypal_sandbox_business_id)
        self.assertTrue(self.community.email_address == self.community.paypal_sandbox_email_address)
        self.assertTrue(self.community.api_username == self.community.paypal_sandbox_api_username)
        self.assertTrue(self.community.api_password == self.community.paypal_sandbox_api_password)
        self.assertTrue(self.community.api_signature == self.community.paypal_sandbox_api_signature)
        self.assertTrue(self.community.application_id == self.community.paypal_sandbox_application_id)

        self.community.use_sandbox = False
        self.assertTrue(self.community.business_id == self.community.paypal_business_id)
        self.assertTrue(self.community.email_address == self.community.paypal_email_address)
        self.assertTrue(self.community.api_username == self.community.paypal_api_username)
        self.assertTrue(self.community.api_password == self.community.paypal_api_password)
        self.assertTrue(self.community.api_signature == self.community.paypal_api_signature)
        self.assertTrue(self.community.application_id == self.community.paypal_application_id)
Пример #10
0
 def testSlugs(self):
     name = 'name with a space'
     slug = Community.get_slug_for_name(name)
     self.assertTrue(slug == 'name-with-a-space')