<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from django.test import TestCase
from django.contrib.auth.models import User
from django.test.client import Client
import json


class CreateReadUpdateDeleteSurveyDraftsTests(TestCase):
    def setUp(self):
        test_user_credentials = {'username': 'user1', 'password': '<PASSWORD>'}
        if User.objects.count() is 0:
            new_user = User(username=test_user_credentials['username'], email="<EMAIL>")
            new_user.set_password(test_user_credentials['password'])
            new_user.save()
        # a client to test behavior when not logged in
        self.anonymousClient = Client()

        self.user = User.objects.all()[0]
        self.client = Client()
        self.client.post('/accounts/login/', test_user_credentials)

    def post_survey(self, client, survey={}):
        survey_dict = {u'name': "Test Form",
                        u'body': 'body',
                        u'description': 'description'}
        survey_dict.update(survey)
        return self.client.post('/api/survey_drafts', survey_dict)

    def test_anonymous_list(self):
        resp = self.anonymousClient.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 403)

    def test_empty_list(self):
        resp = self.client.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 200)
        # json_resp = json.loads(resp.content)
        self.assertEqual(len(resp.data), 0)

        rr = self.post_survey(self.client)
        print rr.content
        resp2 = self.client.get('/api/survey_drafts')
        self.assertEqual(len(resp2.data), 1)

    def test_create_survey_draft(self):
        # self.client.get
        self.assertEqual(User.objects.count(), 1)<commit_msg>testing survey_drafts api endpoints, and one test of library_assets endpoints<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from django.test import TestCase
from django.contrib.auth.models import User
from django.test.client import Client
import json


class CreateReadUpdateDeleteSurveyDraftsTests(TestCase):
    def setUp(self):
        test_user_credentials = {'username': 'user1', 'password': '<PASSWORD>'}
        if User.objects.count() is 0:
            new_user = User(username=test_user_credentials['username'], email="<EMAIL>")
            new_user.set_password(test_user_credentials['password'])
            new_user.save()
        self.anonymousClient = Client()

        self.user = User.objects.all()[0]
        self.client = Client()
        self.client.post('/accounts/login/', test_user_credentials)

    def post_survey(self, client, survey={}):
        survey_dict = {u'name': "Test Form",
                        u'body': 'body',
                        u'description': 'description'}
        survey_dict.update(survey)
        return self.client.post('/api/survey_drafts', survey_dict)

    def test_anonymous_list(self):
        resp = self.anonymousClient.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 403)

    def test_empty_list(self):
        resp = self.client.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(len(resp.data), 0)

        self.post_survey(self.client)
        resp2 = self.client.get('/api/survey_drafts')
        self.assertEqual(len(resp2.data), 1)

    def test_retrieve_survey(self):
        self.post_survey(self.client)

        resp = self.client.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.data[0]['id'], 1)

        resp = self.client.get('/api/survey_drafts/1')
        self.assertEqual(resp.data.get('id'), 1)

    def test_library_assets(self):
        # post a library_asset (question)
        resp = self.client.get('/api/library_assets')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(len(resp.data), 0)

        # ensure library_assets was incremented
        self.post_survey(self.client, {u'asset_type': 'question'})
        resp = self.client.get('/api/library_assets')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(len(resp.data), 1)

        # ensure that survey_drafts was not incremented
        resp = self.client.get('/api/survey_drafts')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(len(resp.data), 0)

{'fraction_non_alphanumeric': 0.12872877466727856, 'fraction_numerical': 0.01101422670949977, 'mean_word_length': 2.8507067137809186, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1342112', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1313, 'n_words': 233}