示例#1
0
    def test_Card(self):
        u1 = User(name='djibril Keita',
                  email='*****@*****.**',
                  unhashpassword='******')
        u2 = User(name='ladji Keita',
                  email='*****@*****.**',
                  unhashpassword='******')
        u3 = User(name='hussein Keita',
                  email='*****@*****.**',
                  unhashpassword='******')
        u4 = User(name='rohit Keita',
                  email='*****@*****.**',
                  unhashpassword='******')
        self.s.add(u1)
        self.s.add(u2)
        self.s.add(u3)
        self.s.add(u4)
        c1 = Card(CardNumber='4000000000000077',
                  expYear='2017',
                  expMonth='12',
                  User_id=u1.id)
        c2 = Card(CardNumber='4000056655665556',
                  expYear='2018',
                  expMonth='10',
                  User_id=u2.id)
        self.s.add(c1)
        self.s.add(c2)
        self.s.commit()
        token = stripe.Token.create(card={
            "number": c1.CardNumber,
            "exp_month": c1.expMonth,
            "exp_year": c1.expYear,
        }, )

        assert token is not None
        token2 = stripe.Token.create(card={
            "number": c2.CardNumber,
            "exp_month": c2.expMonth,
            "exp_year": c2.expYear,
        }, )
        assert token2 is not None
        stripeAmount = 1000
        charged = stripe.Charge.create(description="test.py",
                                       amount=stripeAmount,
                                       currency="usd",
                                       source=token.id)
        assert charged is not None
        recipient = stripe.Recipient.create(name=u2.name,
                                            type="individual",
                                            email=u2.email,
                                            card=token2.id)

        transfer = stripe.Transfer.create(amount=stripeAmount,
                                          currency="usd",
                                          recipient=recipient.id,
                                          source_transaction=charged.id)
        assert transfer is not None
示例#2
0
 def test_follow(self):
     u1 = User(name='john',
               email='*****@*****.**',
               unhashpassword='******')
     u2 = User(name='susan',
               email='*****@*****.**',
               unhashpassword='******')
     self.s.add(u1)
     self.s.add(u2)
     self.s.commit()
     self.assertIsNone(u1.unfollow(u2))
     u = u1.follow(u2)
     self.s.add(u)
     self.s.commit()
     self.assertIsNone(u1.follow(u2))
     assert u1.is_following(u2)
     assert u1.followed.count() == 1
     assert u1.followed.first().name == 'Susan'
     assert u2.followers.count() == 1
     assert u2.followers.first().name == 'John'
     u = u1.unfollow(u2)
     assert u is not None
     self.s.add(u)
     self.s.commit()
     assert not u1.is_following(u2)
     assert u1.followed.count() == 0
     assert u2.followers.count() == 0
示例#3
0
 def liking_Post(self):
     u1 = User(name='djibril',
               email='*****@*****.**',
               unhashpassword='******')
     u2 = User(name='ladji',
               email='*****@*****.**',
               unhashpassword='******')
     u3 = User(name='hussein',
               email='*****@*****.**',
               unhashpassword='******')
     u4 = User(name='rohit',
               email='*****@*****.**',
               unhashpassword='******')
     self.s.add(u1)
     self.s.add(u2)
     self.s.add(u3)
     self.s.add(u4)
     utcnow = datetime.utcnow()
     p1 = Post(body="post from djibril",
               author=u1,
               timestamp=utcnow + timedelta(seconds=1))
     p2 = Post(body="post from ladji",
               author=u2,
               timestamp=utcnow + timedelta(seconds=2))
     p3 = Post(body="post from hussein",
               author=u3,
               timestamp=utcnow + timedelta(seconds=3))
     p4 = Post(body="post from rohit",
               author=u4,
               timestamp=utcnow + timedelta(seconds=4))
     self.s.add(p1)
     self.s.add(p2)
     self.s.add(p3)
     self.s.add(p4)
     self.s.commit()
     u1like = UserPostLike()
     u1like.like(u1, p2, self.s)
     u1like.like(u2, p2, self.s)
     u1like.like(u3, p2, self.s)
     self.s.add(u1like)
     self.s.add(p2)
     self.s.commit()
     assert p2.like_count == 3
def createUser():
    data = request.get_json(force=True)
    userName = unicodedata.normalize('NFKD', data['userName']).encode(
        'ascii', 'ignore')
    #must validate email and passwords
    #
    ####
    userPassword = unicodedata.normalize('NFKD', data['userPassword']).encode(
        'ascii', 'ignore')
    userEmail = unicodedata.normalize('NFKD', data['userEmail']).encode(
        'ascii', 'ignore')
    # userCardNumber=unicodedata.normalize('NFKD', data['userCardNumber']).encode('ascii','ignore')
    # userExpMonth=unicodedata.normalize('NFKD', data['userExpMonth']).encode('ascii','ignore')
    # userExpYear=unicodedata.normalize('NFKD', data['userExpYear']).encode('ascii','ignore')
    try:
        if session.query(User).filter(User.email == userEmail).first() is None:
            new_person = User(name=userName,
                              email=userEmail,
                              unhashpassword=userPassword)
            session.add(new_person)
            session.commit()
            #create and add User Card
            # new_person_card = Card(CardNumber=userCardNumber,expMonth=userExpMonth,expYear=userExpYear,user=new_person)

            # session.add(new_person_card)
            # session.commit()
            return jsonify(success=True,
                           data={
                               'msg': 'Success!! created User!',
                           })
        else:
            return Response(json.dumps("User email is taken!"))

    except IntegrityError, e:
        session.rollback()
        return Response(e)
示例#5
0
 def test_follow(self):
     u1 = User(name='john', email='*****@*****.**',unhashpassword='******')
     u2 = User(name='susan', email='*****@*****.**',unhashpassword='******')
     self.s.add(u1)
     self.s.add(u2)
     self.s.commit()
     self.assertIsNone(u1.unfollow(u2))  
     u = u1.follow(u2)
     self.s.add(u)
     self.s.commit()
     self.assertIsNone(u1.follow(u2))
     assert u1.is_following(u2)
     assert u1.followed.count() == 1
     assert u1.followed.first().name == 'Susan'
     assert u2.followers.count() == 1
     assert u2.followers.first().name == 'John'
     u = u1.unfollow(u2)
     assert u is not None
     self.s.add(u)
     self.s.commit()
     assert not u1.is_following(u2)
     assert u1.followed.count() == 0
     assert u2.followers.count() == 0
示例#6
0
    def test_follow_posts(self):

        u1 = User(name='djibril',
                  email='*****@*****.**',
                  unhashpassword='******')
        u2 = User(name='ladji',
                  email='*****@*****.**',
                  unhashpassword='******')
        u3 = User(name='hussein',
                  email='*****@*****.**',
                  unhashpassword='******')
        u4 = User(name='rohit',
                  email='*****@*****.**',
                  unhashpassword='******')
        self.s.add(u1)
        self.s.add(u2)
        self.s.add(u3)
        self.s.add(u4)
        utcnow = datetime.utcnow()
        p1 = Post(myPost="post from djibril",
                  author=u1,
                  dueDate='131',
                  startTime='2015-08-22T05:05:25 +0000',
                  timestamp=utcnow + timedelta(seconds=1),
                  task={'first': 'my poat'})
        p2 = Post(myPost="post from ladji",
                  author=u2,
                  dueDate='131',
                  startTime='2015-08-22T05:05:25 +0000',
                  timestamp=utcnow + timedelta(seconds=2),
                  task={'first': 'my poat'})
        p3 = Post(myPost="post from hussein",
                  author=u3,
                  dueDate='131',
                  startTime='2015-08-22T05:05:25 +0000',
                  timestamp=utcnow + timedelta(seconds=3),
                  task={'first': 'my poat'})
        p4 = Post(myPost="post from rohit",
                  author=u4,
                  dueDate='131',
                  startTime='2015-08-22T05:05:25 +0000',
                  timestamp=utcnow + timedelta(seconds=4),
                  task={'first': 'my poat'})

        self.s.add(p1)
        self.s.add(p2)
        self.s.add(p3),
        self.s.add(p4)
        self.s.commit()

        u1.follow(u1)  # djibril follows himself
        u1.follow(u2)  # djibril follows susan
        u1.follow(u4)  # djibril follows david
        u2.follow(u2)  # ladji follows herself
        u2.follow(u3)  # ladji follows mary
        u3.follow(u3)  # hussein follows herself
        u3.follow(u4)  # hussein follows david
        u4.follow(u4)  #rohit follows himself

        self.s.add(u1)
        self.s.add(u2)
        self.s.add(u3)
        self.s.add(u4)
        self.s.commit()
        f1 = u1.followed_posts(self.s)
        print f1
        f2 = u2.followed_posts(self.s)
        f3 = u3.followed_posts(self.s)
        f4 = u4.followed_posts(self.s)
        print p1.task
        assert len(p1.task) != 0
        assert len(f2) == 2
        assert len(f3) == 2
        assert len(f4) == 1
        assert f1 == [p4, p2, p1]
        assert f2 == [p3, p2]
        assert f3 == [p4, p3]
        assert f4 == [p4]
示例#7
0
 def test_make_unique_email(self):
     u = User(name='john',
              email='*****@*****.**',
              unhashpassword='******')
     self.s.add(u)
     self.s.commit()
示例#8
0
 def test_follow_posts(self):
      
      u1 = User(name='djibril', email='*****@*****.**',unhashpassword='******')
      u2 = User(name='ladji', email='*****@*****.**',unhashpassword='******')
      u3 = User(name='hussein', email='*****@*****.**',unhashpassword='******')
      u4 = User(name='rohit', email='*****@*****.**',unhashpassword='******')
      self.s.add(u1)
      self.s.add(u2)
      self.s.add(u3)
      self.s.add(u4)
      utcnow = datetime.utcnow()
      p1 = Post(myPost="post from djibril", author=u1,dueDate='131',startTime='2015-08-22T05:05:25 +0000',timestamp=utcnow + timedelta(seconds=1), task ={'first':'my poat'})
      p2 = Post(myPost="post from ladji", author=u2,dueDate='131',startTime='2015-08-22T05:05:25 +0000', timestamp=utcnow + timedelta(seconds=2), task ={'first':'my poat'})
      p3 = Post(myPost="post from hussein", author=u3,dueDate='131',startTime='2015-08-22T05:05:25 +0000', timestamp=utcnow + timedelta(seconds=3), task ={'first':'my poat'})
      p4 = Post(myPost="post from rohit", author=u4, dueDate='131',startTime='2015-08-22T05:05:25 +0000',timestamp=utcnow + timedelta(seconds=4), task ={'first':'my poat'})
      
      self.s.add(p1)
      self.s.add(p2)
      self.s.add(p3),
      self.s.add(p4)
      self.s.commit()
      
      u1.follow(u1)  # djibril follows himself
      u1.follow(u2)  # djibril follows susan
      u1.follow(u4)  # djibril follows david
      u2.follow(u2)  # ladji follows herself
      u2.follow(u3)  # ladji follows mary
      u3.follow(u3)  # hussein follows herself
      u3.follow(u4)  # hussein follows david
      u4.follow(u4)  #rohit follows himself
      
      self.s.add(u1)
      self.s.add(u2)
      self.s.add(u3)
      self.s.add(u4)
      self.s.commit()
      f1 = u1.followed_posts(self.s)
      print f1
      f2 = u2.followed_posts(self.s)
      f3 = u3.followed_posts(self.s)
      f4 = u4.followed_posts(self.s)
      print p1.task
      assert len(p1.task) != 0
      assert len(f2) == 2
      assert len(f3) == 2
      assert len(f4) == 1
      assert f1 == [p4, p2, p1]
      assert f2 == [p3, p2]
      assert f3 == [p4, p3]
      assert f4 == [p4]