Ejemplo n.º 1
0
 def test_delete_fk(self):
     advertiser = Advertiser(name='hello')
     my_ad = Ad(advertiser=advertiser)
     Advertiser.get_objects().clear()
     try:
         my_ad.inc_clicks()
     except Exception:
         self.fail('failed to increase because of loss of fk')
    def test_get_total_clicks(self):
        self.re_init_models()
        clicks_list = [20, 42, 33, 14, 55]
        for clicks in clicks_list:
            self.add_clicks(Advertiser(), clicks)

        self.assertEqual(sum(clicks_list), Advertiser.get_total_clicks())
        Advertiser.get_objects().clear()
Ejemplo n.º 3
0
    def test_inc_views(self):
        self.re_init_models()

        advertiser = Advertiser()
        views = [40, 50, 10]
        self.create_ads_from_views_list(advertiser, views)

        self.assertEqual(sum(views), advertiser.get_views())
Ejemplo n.º 4
0
    def test_inc_clicks(self):
        self.re_init_models()

        advertiser = Advertiser()
        clicks = [20, 15, 30]
        self.create_ads_from_clicks_list(advertiser, clicks)

        self.assertEqual(sum(clicks), advertiser.get_clicks())
Ejemplo n.º 5
0
    def test_advertisers_total_clicks(self):
        self.re_init_models()

        advertiser1_clicks = [20, 10, 15, 60]
        self.create_ads_from_clicks_list(Advertiser(), advertiser1_clicks)

        advertiser2_clicks = [25, 5, 35, 40]
        self.create_ads_from_clicks_list(Advertiser(), advertiser2_clicks)

        self.assertEqual(sum(advertiser1_clicks + advertiser2_clicks),
                         Advertiser.get_total_clicks())
 def test_id_inc(self):
     self.re_init_models()
     try:
         Advertiser()
         advertisers = Advertiser.get_objects()
         self.assertEqual(1, len(advertisers))
         try:
             Advertiser()
             self.assertEqual(2, len(advertisers))
         except Exception:
             self.fail("Exception in making ID")
     except Exception:
         self.fail("Exception in making ID")
Ejemplo n.º 7
0
def login():
    if current_user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()

    if form.validate_on_submit():
        user = Advertiser.objects(email=form.email.data).first()

        print(user.password)
        print(form.password.data)
        if user.password != form.password.data:
          return render_template('login.html', form=form, error="Wrong username or password")

        else:
          login_user(user)
          return redirect(url_for('index'))

    return render_template('login.html', form=form)
Ejemplo n.º 8
0
def signup():
    if current_user.is_authenticated():
        return redirect(url_for('index'))

    form = RegisterForm()

    if form.validate_on_submit():
        newUser = Advertiser(
            first_name=form.first.data,
            last_name=form.last.data,
            cpf=form.cpf.data,
            address=form.address.data,
            country='Brazil',
            email=form.email.data,
            password=form.password.data,
        ).save()

        return redirect(url_for('index'))

    return render_template('signup.html', form=form)
Ejemplo n.º 9
0
def login():
    if current_user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()

    if form.validate_on_submit():
        user = Advertiser.objects(email=form.email.data).first()

        print(user.password)
        print(form.password.data)
        if user.password != form.password.data:
            return render_template('login.html',
                                   form=form,
                                   error="Wrong username or password")

        else:
            login_user(user)
            return redirect(url_for('index'))

    return render_template('login.html', form=form)
Ejemplo n.º 10
0
def load_user(user_id):
    return Advertiser.objects(id=user_id).first()
Ejemplo n.º 11
0
 def re_init_models():
     Advertiser.get_objects().clear()
Ejemplo n.º 12
0
 def add_clicks(advertiser: Advertiser, clicks: int):
     for i in range(clicks):
         advertiser.inc_clicks()
Ejemplo n.º 13
0
from models import Advertiser
from models.ad import Ad

if __name__ == '__main__':
    advertiser1 = Advertiser('name1')
    advertiser2 = Advertiser('name2')
    ad1 = Ad(title='title1',
             image_url='image-url1',
             link='link1',
             advertiser=advertiser1)
    ad2 = Ad(title='title2',
             image_url='image-url2',
             link='link2',
             advertiser=advertiser2)
    ad2.describe_me()
    advertiser1.describe_me()
    ad1.inc_views()
    ad1.inc_views()
    ad1.inc_views()
    ad1.inc_views()
    ad2.inc_views()
    ad1.inc_clicks()
    ad1.inc_clicks()
    ad2.inc_clicks()
    print(advertiser2.get_name())
    advertiser2.set_name('new name')
    print(advertiser2.get_name())
    print(ad1.get_clicks())
    print(advertiser2.get_clicks())
    print(Advertiser.get_total_clicks())
    print(Advertiser.help())
Ejemplo n.º 14
0
    def get(self):
        email = '*****@*****.**'
        password = '******'
        new_password = '******'

        # check for existing advertiser first, delete if necessary
        adv = Advertiser.get_by_auth_id(email)
        logging.error('found advertiser')
        if adv is not None:
            for auth_id in adv.auth_ids:
                uu = ndb.Key(Unique, 'Advertiser.auth_id:'+auth_id)
                uu.delete()
            logging.info('deleted auth ids')
            adv.key.delete()
            logging.info('deleted advertiser')
            time.sleep(3)

        data = {'email': email, 'password': password}
        r = requests.post(self.uri_for('createadvertiser', _full=True),
                                            data=json.dumps(data))
        logging.info('create advertiser')
        logging.info('r.status_code ' + str(r.status_code))
        logging.info('r.content ' + str(r.content))
        time.sleep(2)

        # sign in
        r = requests.post(self.uri_for('advertisersignin', _full=True),
                                            data=json.dumps(data))
        logging.info('sign in advertiser')
        logging.info('r.status_code ' + str(r.status_code))
        logging.info('r.content ' + str(r.content))
        # cookies = r.cookies

        # forget our password
        data = {'email': email}
        r = requests.post(self.uri_for('forgotadvertiserpassword', _full=True),
                                            data=json.dumps(data))
        logging.info('forgot advertiser password')
        logging.info('r.status_code ' + str(r.status_code))
        logging.info('r.content ' + str(r.content))
        response_data = json.loads(r.content)
        token = response_data['data']['token']

        # reset our password
        data = {'password': new_password, 'confirm_password': new_password}
        r = requests.post(self.uri_for('resetadvertiserpassword',
                                                                      email=email,
                                                                      token=token,
                                                                      _full=True),
                                            data=json.dumps(data))
        logging.info('reset advertiser password')
        logging.info('r.status_code ' + str(r.status_code))
        logging.info('r.content ' + str(r.content))
        time.sleep(2)

        # sign in with new password
        data = {'email': email, 'password': new_password}
        r = requests.post(self.uri_for('advertisersignin', _full=True),
                                            data=json.dumps(data))
        logging.info('sign in advertiser with new password')
        logging.info('r.status_code ' + str(r.status_code))
        logging.info('r.content ' + str(r.content))
Ejemplo n.º 15
0
def load_user(user_id):
    return Advertiser.objects(id=user_id).first()