当前位置: 首页>>代码示例>>Python>>正文


Python User.save方法代码示例

本文整理汇总了Python中atados_core.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在atados_core.models.User的用法示例。


在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_apply_volunteer_to_project_view_already_apply

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
  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)
开发者ID:atados,项目名称:api,代码行数:34,代码来源:test_core.py

示例2: test_create_project_view_with_only_required_fields_job

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:30,代码来源:tests.py

示例3: test_create_project_view_with_only_required_fields_work

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:atados,项目名称:api,代码行数:30,代码来源:test_core.py

示例4: test_apply_volunteer_to_project_view

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
  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)
开发者ID:atados,项目名称:api,代码行数:27,代码来源:test_core.py

示例5: test_create_two_project_same_slug

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:34,代码来源:tests.py

示例6: test_apply_volunteer_to_project_view_after_canceled

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:28,代码来源:tests.py

示例7: create_nonprofit

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
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
开发者ID:atados,项目名称:api,代码行数:9,代码来源:helpers.py

示例8: test_create_project_view_not_nonprofit_authenticated

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:13,代码来源:tests.py

示例9: test_apply_creation

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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")
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:14,代码来源:tests.py

示例10: create_project

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:15,代码来源:tests.py

示例11: test_create_project_view_bad_request

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:15,代码来源:tests.py

示例12: test_create_project_view_to_test_address_creation

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
  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")
开发者ID:atados,项目名称:api,代码行数:53,代码来源:test_core.py

示例13: test_apply_volunteer_to_project_view_without_project

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:16,代码来源:tests.py

示例14: test_project_date_creation

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 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))
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:16,代码来源:tests.py

示例15: test_close_project

# 需要导入模块: from atados_core.models import User [as 别名]
# 或者: from atados_core.models.User import save [as 别名]
 def test_close_project(self):
   """
   Tests closing project that is open.
   """
   u = User()
   u.save()
   n = Nonprofit(user=u, name="Nonprofit 1")
   n.save()
   p = self.create_project(n, "Project 1")
   p.closed = False;
   factory = APIRequestFactory()
   request = factory.put("/close/project/", {'project': p.id})
   force_authenticate(request, user=u)
   response = views.close_project(request)
   self.assertEqual(response.data, True)
   self.assertEqual(response.status_code, status.HTTP_200_OK)
开发者ID:fidelisrafael,项目名称:atados-api,代码行数:18,代码来源:tests.py


注:本文中的atados_core.models.User.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。