本文整理汇总了Python中atados_core.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_apply_volunteer_to_project_view_already_apply
def test_apply_volunteer_to_project_view_already_apply(self):
"""
Unaply when apply already exists.
"""
u = User(email="[email protected]", name="test", slug="test")
u.is_email_verified = True
u.save()
volunteer = Volunteer(user=u)
volunteer.save()
project = self.create_project()
factory = APIRequestFactory()
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
project = Project.objects.get(pk=project.id)
nonprofit = Nonprofit.objects.get(user__slug="hahah")
self.assertEqual(response.data, {'Applied'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(project.applied_count, 1)
# We only test if volunteer count increases, we don't test if it lowers
# when unapplying because Nonprofit.get_volunteers and N.get_volunteers_numbers
# doesn't filter applies by cancelled
self.assertEqual(nonprofit.volunteer_count, 1)
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
project = Project.objects.get(pk=project.id)
self.assertEqual(response.data, {'Canceled'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(project.applied_count, 0)
示例2: test_create_two_project_same_slug
def test_create_two_project_same_slug(self):
"""
Creating two projects with same name to see if different slugs are created..
"""
factory = APIRequestFactory()
project = {
'name': "Name",
'details': 'This needs to be big',
'description': 'This needs to be big',
'responsible': 'Marjor',
'phone': '123123',
'email': '[email protected]',
'skills': [1],
'causes': [2],
'job': {
'start_date': 20140416,
'end_date': 20140417
}
}
u = User()
u.save()
n = Nonprofit(user=u)
n.save()
request = factory.post("/create/project/", {'project': project})
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
request = factory.post("/create/project/", {'project': project})
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.data['detail'], 'Project succesfully created.')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
示例3: test_create_project_view_with_only_required_fields_work
def test_create_project_view_with_only_required_fields_work(self):
"""
Project work with only required fields and no availabilites.
"""
factory = APIRequestFactory()
project = {
'name': "Name",
'details': 'This needs to be big',
'description': 'This needs to be big',
'responsible': 'Marjor',
'phone': '11987456321',
'email': '[email protected]',
'skills': [{'id': 1}],
'causes': [{'id': 1}],
'work': {
'weekly_hours': 1,
'can_be_done_remotely': True
}
}
request = factory.post("/create/project/", {'project': json.dumps(project)})
u = User()
u.save()
n = Nonprofit(user=u)
n.save()
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.data['detail'], 'Project succesfully created.')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
示例4: test_apply_volunteer_to_project_view_after_canceled
def test_apply_volunteer_to_project_view_after_canceled(self):
"""
Apply again after canceled.
"""
u = User(email="[email protected]", name="test", slug="test")
u.is_email_verified = True
u.save()
volunteer = Volunteer(user=u)
volunteer.save()
project = self.create_project()
factory = APIRequestFactory()
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.data, {'Applied'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.data, {'Canceled'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.data, {'Applied'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
示例5: create_nonprofit
def create_nonprofit():
address = create_address()
u = User(googleaddress=address, is_active=True)
u.save()
n = Nonprofit(user=u, published=True)
n.save()
return n
示例6: test_apply_volunteer_to_project_view
def test_apply_volunteer_to_project_view(self):
"""
Ensure we can apply a volunteer to a project.
"""
a = ApplyStatus(name="Candidato", id=2)
a.save()
u = User(email="[email protected]", name="test", slug="test")
u.is_email_verified = True
u.save()
volunteer = Volunteer(user=u)
volunteer.save()
project = self.create_project()
factory = APIRequestFactory()
request = factory.post("/apply_volunteer_to_project/", {"project": project.id, 'name': 'new name', 'phone': '3444-3434'})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.data, {'Applied'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
u = User.objects.get(slug='test')
self.assertEqual('new name', u.name)
self.assertEqual('3444-3434', u.phone)
project = Project.objects.get(pk=project.id)
self.assertEqual(project.applied_count, 1)
示例7: test_create_project_view_with_only_required_fields_job
def test_create_project_view_with_only_required_fields_job(self):
"""
Project job with only required fields and no availabilites.
"""
factory = APIRequestFactory()
project = {
'name': "Name",
'details': 'This needs to be big',
'description': 'This needs to be big',
'responsible': 'Marjor',
'phone': '123123',
'email': '[email protected]',
'skills': [1],
'causes': [2],
'job': {
'start_date': 20140416,
'end_date': 20140417
}
}
request = factory.post("/create/project/", {'project': project})
u = User()
u.save()
n = Nonprofit(user=u)
n.save()
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.data['detail'], 'Project succesfully created.')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
示例8: test_create_project_view_not_nonprofit_authenticated
def test_create_project_view_not_nonprofit_authenticated(self):
"""
Project with user that is not nonprofit.
"""
factory = APIRequestFactory()
request = factory.post("/create/project/", {"project": ""})
u = User()
u.save()
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
示例9: test_apply_creation
def test_apply_creation(self):
"""
Tests Apply.
"""
u = User(name="Voluntario", slug="voluntario")
u.save()
v = Volunteer(user=u)
v.save()
p = Project(name="Project")
a = Apply(status=ApplyStatus(), volunteer=v, project=p)
self.assertTrue(isinstance(a, Apply))
self.assertEqual(a.__unicode__(), "[False] Voluntario - Project")
示例10: create_project
def create_project(self):
u = User(email="[email protected]", name="what", slug="hahah")
u.save()
n = Nonprofit(user=u, name="hahah")
n.save()
from random import randint
random = randint(1,100)
project = Project(nonprofit=n, name='name' + str(random))
project.nonprofit = n
project.save()
project.job = Job(start_date=datetime.now().replace(tzinfo=pytz.timezone("America/Sao_Paulo")), end_date=datetime.now().replace(tzinfo=pytz.timezone("America/Sao_Paulo")))
project.job.save()
return project
示例11: test_create_project_view_bad_request
def test_create_project_view_bad_request(self):
"""
Project with bad data being sent.
"""
factory = APIRequestFactory()
request = factory.post("/create/project/", {"project": ""})
u = User()
u.save()
n = Nonprofit(user=u)
n.save()
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例12: test_create_project_view_to_test_address_creation
def test_create_project_view_to_test_address_creation(self):
"""
Project to test address creation.
"""
skill = Skill(name="Programming")
skill.save()
cause = Cause(name="Atados")
cause.save()
factory = APIRequestFactory()
project = {
'name': "Name",
'details': 'This needs to be big',
'description': 'This needs to be big',
'responsible': 'Marjor',
'phone': '11987456321',
'email': '[email protected]',
'skills': [{'id': 1}],
'causes': [{'id': 1}],
'work': {
'weekly_hours': 1,
'can_be_done_remotely': True
},
'address': {
'addr': {
'formatted_address': 'R. Capote Valente, 701, São Paulo'
},
'typed_address2': 'Complemento'
}
}
s = State(name="sao paulo")
s.save()
c = City(id=9422, name="sao paulo", state=s)
c.save()
request = factory.post("/create/project/", {'project': json.dumps(project)})
u = User()
u.save()
n = Nonprofit(user=u)
n.save()
force_authenticate(request, user=u)
response = views.create_project(request)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
p = Project.objects.all()[0]
self.assertEqual(p.phone, "11987456321")
self.assertEqual(p.name, "Name")
self.assertTrue(p.googleaddress)
self.assertEqual(p.googleaddress.typed_address, u"R. Capote Valente, 701, São Paulo")
self.assertEqual(p.googleaddress.typed_address2, u"Complemento")
示例13: test_apply_volunteer_to_project_view_without_project
def test_apply_volunteer_to_project_view_without_project(self):
"""
Apply volunteer to project without project id.
"""
u = User(email="[email protected]", name="test", slug="test")
u.is_email_verified = True
u.save()
volunteer = Volunteer(user=u)
volunteer.save()
factory = APIRequestFactory()
request = factory.post("/apply_volunteer_to_project/", {"project": ''})
force_authenticate(request, user=volunteer.user)
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例14: test_project_date_creation
def test_project_date_creation(self):
"""
Tests Project date creation.
"""
u = User()
u.save()
n = Nonprofit(user=u, name="Nonprofit 1")
n.save()
p = self.create_project(n, "Project 1")
now = datetime.utcnow().replace(tzinfo=pytz.timezone("America/Sao_Paulo"))
self.assertTrue(isinstance(p, Project))
self.assertEqual(p.__unicode__(), "Project 1 - Nonprofit 1")
self.assertTrue(datesAreEqual(p.created_date, now))
self.assertTrue(datesAreEqual(p.modified_date, now))
示例15: test_apply_volunteer_to_project_view_without_auth
def test_apply_volunteer_to_project_view_without_auth(self):
"""
Apply no volunteer to a project.
"""
a = ApplyStatus(name="Candidato", id=2)
a.save()
u = User(email="[email protected]", name="test", slug="test")
u.save()
volunteer = Volunteer(user=u)
volunteer.save()
project = self.create_project()
factory = APIRequestFactory()
request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
response = views.apply_volunteer_to_project(request)
self.assertEqual(response.data, {"No user logged in."})
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)