Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Natay committed Sep 27, 2021
1 parent dcf24e4 commit 016ac54
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 66 deletions.
2 changes: 1 addition & 1 deletion biostar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .celery import app as celery_app
__all__ = ['celery_app']
except ImportError as exc:
print(f'celery error {exc}')
pass

VERSION = '2.3.6'
4 changes: 0 additions & 4 deletions biostar/accounts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
# Should the site allow signup.
ALLOW_SIGNUP = False

# Private key used to validate external logins. Must be changed in production
LOGIN_PRIVATE_KEY = "private-key"

ADMINS = [
("Admin User", "admin@localhost")
]
Expand Down Expand Up @@ -151,4 +148,3 @@
]

GOOGLE_TRACKER = ""

19 changes: 0 additions & 19 deletions biostar/accounts/test/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,6 @@ def test_invalid_creds(self):

self.assertEqual(resp.status_code, 200)

def test_external_login(self):
"""Test login with external login"""

signer = signing.Signer(settings.LOGIN_PRIVATE_KEY)
payload = signer.sign("[email protected]")

data = {"payload": payload}
url = reverse("external")

request = fake_request(url=url, data=data, user=self.user, method="GET")
response = views.external_login(request=request)

self.assertEqual(response.status_code, 302)

user = models.User.objects.filter(email="[email protected]")
self.assertTrue(user.exists())

return


@override_settings(RECAPTCHA_PRIVATE_KEY="", RECAPTCHA_PUBLIC_KEY="")
class SignUpTest(TestCase):
Expand Down
3 changes: 0 additions & 3 deletions biostar/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
# Message urls
path(r'inbox/', views.message_list, name='inbox'),

# External url login
path(r'external/', views.external_login, name="external"),

# Used for 3rd party logins.
path("social/", include('allauth.urls')),

Expand Down
31 changes: 1 addition & 30 deletions biostar/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def debug_user(request):
user = profile.user
login(request, user, backend="django.contrib.auth.backends.ModelBackend")

logger.info(f"""uid={request.user.profile.uid} impersonated
logger.info(f"""uid={request.user.profile.uid} impersonated
uid={profile.uid}.""")

return redirect("/")
Expand Down Expand Up @@ -317,34 +317,6 @@ def email_verify_account(request, uidb64, token):
return redirect("/")


def external_login(request):
"""Login or signup a user."""
payload = request.GET.get("payload", "")

try:
signer = signing.Signer(settings.LOGIN_PRIVATE_KEY)
user_email = signer.unsign(payload)
user = User.objects.filter(email=user_email).first()

if not user:
name = user_email.split("@")[0]
user = User.objects.create(email=user_email, first_name=name,
password=str(get_uuid(16)))
user.username = name.split()[0] + str(get_uuid(8))
user.save()
msg = f"Signed up, <a href={reverse('password_reset')}><b> Please reset your password.</b></a>"
messages.success(request, mark_safe(msg))

login(request, user, backend="django.contrib.auth.backends.ModelBackend")
messages.success(request, "Logged in!")
return redirect("/")

except Exception as exc:
logger.error(f"Error:{exc}")
messages.error(request, "Error unsigning.")

return redirect("/")


#@limited(key=RATELIMIT_KEY, rate=PASSWORD_RESET_RATE)
def password_reset(request):
Expand Down Expand Up @@ -380,4 +352,3 @@ def password_reset_complete(request):

return PasswordResetCompleteView.as_view(extra_context=context,
template_name="accounts/password_reset_complete.html")(request=request)

2 changes: 1 addition & 1 deletion biostar/forum/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def traffic(request):
"""
now = datetime.now()
start = now - timedelta(minutes=60)

start = start.now()
post_views = PostView.objects.filter(date__gt=start).exclude(date__gt=now).distinct('ip').count()

data = {
Expand Down
7 changes: 5 additions & 2 deletions biostar/forum/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def spam_check(uid):
post = Post.objects.filter(uid=uid).first()
author = post.author

if not settings.CLASSIFY_SPAM:
return

# Automated spam disabled in for trusted user
if author.profile.trusted or author.profile.score > 50:
return
Expand Down Expand Up @@ -316,8 +319,8 @@ def herald_emails(uid):
# Get the next set of emails
end = idx + batch_size
rec_list = emails[idx:end]
send_email(template_name=email_template, extra_context=context, name=author, from_email=from_email,
recipient_list=rec_list, mass=True)
send_email(template_name=email_template, extra_context=context, name=author,
from_email=from_email,recipient_list=rec_list, mass=True)

return

Expand Down
2 changes: 1 addition & 1 deletion biostar/forum/templates/banners/menu-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</a>

<a class="item {% activate tab "planet" %} " href="{% url 'blog_list' %}">
<i class="rss icon"></i> Planet {% count_badge counts.planet_count %}
<i class="rss icon"></i> Planet
</a>

{% if request.user.profile.is_moderator %}
Expand Down
2 changes: 1 addition & 1 deletion biostar/forum/templatetags/forum_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def form_errors(form, wmd_prefix='', override_content=False):
for field in form:
for error in field.errors:
# wmd_prefix is required when dealing with 'content' field.
field_id = wmd_prefix if (override_content and field.name is 'content') else field.id_for_label
field_id = wmd_prefix if (override_content and field.name == 'content') else field.id_for_label
errorlist.append((f'{field.name}:', error, field_id))

except Exception as exc:
Expand Down
1 change: 0 additions & 1 deletion biostar/recipes/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ def get_field_types(project=None):
const.TEXTBOX: char_field,
const.FLOAT: float_field,
const.CHECKBOX: checkbox_field,
const.SQL: sqlfield,
const.UPLOAD: upload_field
}

Expand Down
3 changes: 0 additions & 3 deletions biostar/recipes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# Django debug flag.
DEBUG = True

# Private key used to validate external logins
LOGIN_PRIVATE_KEY = SECRET_KEY

SEARCH_CHAR_MIN = 2

SOCIALACCOUNT_EMAIL_VERIFICATION = None
Expand Down

0 comments on commit 016ac54

Please sign in to comment.