Esempio n. 1
0
	def test_activate_via_login(self):
		self.assertFalse(Account.get_by_pk('test_u_name').is_activated)
		response = self.client.post('/api/v1/login', {
			'email': '*****@*****.**',
			'password': '******'
		})
		self.assertEqual(response.status_code, 200)
		self.assertTrue(Account.get_by_pk('test_u_name').is_activated)
    def test_expire_account(self):
        self.assertIsNotNone(Account.get_by_pk('test_user_1'))
        self.assertIsNotNone(Account.get_by_pk('test_user_2'))

        call_command('expire_account')

        self.assertIsNone(Account.get_by_pk('test_user_1'))
        self.assertIsNotNone(Account.get_by_pk('test_user_2'))
Esempio n. 3
0
	def test_post_201_created(self):
		account = Account.get_by_pk('test_user')
		self.assertEqual(account.max_backups, 5)
		response = self.client.post('/api/v1/accounts/edit', data={
			'max_backups': 7,
		}, **self.header)
		self.assertEqual(response.status_code, 201)
		self.assertTrue('detail' in response.json())
		account = Account.get_by_pk('test_user')
		self.assertEqual(account.max_backups, 7)
Esempio n. 4
0
	def test_post_400_max_backups_is_non_number(self):
		account = Account.get_by_pk('test_user')
		self.assertEqual(account.max_backups, 5)
		response = self.client.post('/api/v1/accounts/edit', data={
			'max_backups': 'f',
		}, **self.header)
		self.assertEqual(response.status_code, 400)
Esempio n. 5
0
 def get(request):
     account = Account.get_by_pk(request.user.username)
     if account is None:
         return Response({'detail': 'account is not found'},
                         status=status.HTTP_404_NOT_FOUND)
     serializer = AccountDetailsSerializer(account)
     return Response(serializer.data, status=status.HTTP_200_OK)
Esempio n. 6
0
 def post(request):
     account = Account.get_by_pk(request.user.username)
     if account is None:
         return Response({'detail': 'account is not found'},
                         status=status.HTTP_404_NOT_FOUND)
     serializer = AccountSerializer(instance=account, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response({'detail': 'account has been edited'},
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Esempio n. 7
0
 def post(request):
     serializer = BackupSerializer(data=request.data,
                                   context={'request': request})
     if serializer.is_valid():
         serializer.save()
         account = Account.get_by_pk(request.user.username)
         backups = Backup.objects.all().order_by('timestamp')
         if len(backups) > account.max_backups:
             Backup.remove(backups[0].digest)
         return Response({'detail': 'backup has been created'},
                         status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Esempio n. 8
0
 def test_get_by_pk_does_not_exist(self):
     self.assertIsNone(Account.get_by_pk('test_username1'))
Esempio n. 9
0
 def test_get_by_pk_exists(self):
     self.assertIsNotNone(Account.get_by_pk('test_username'))