<commit_before>import sys
import os
import datetime 
import simplejson as json

from lettuce import step, world

sys.path.append("../../../")
os.environ['DJANGO_SETTINGS_MODULE'] = 'newebe.settings'

from tornado.httpclient import HTTPClient

from newebe.lib import date_util
from newebe.activities.models import Activity, ActivityManager
from newebe.core.models import Contact
from newebe.settings import TORNADO_PORT

ROOT_URL = "http://localhost:%d/" % TORNADO_PORT

@step('Take the default activity')
def get_default_activity(step):

    if not hasattr(world, "activity"):
        world.activity = Activity(
            author = "me",
            docId = "aaavvvbbbb",
            verb = "write",
            method = "POST",
            isMine = False,
            errors = [],
            docType = "Micropost",
            date = datetime.datetime(2010, 9, 01, 11, 05, 12)
        )

@step('Take the default contact')
def get_default_contact(step):

    if not hasattr(world, "contact"):
        world.contact = Contact(
            name = "<NAME>",
            key = "contact_key",
            url = "contact_url",
            state = "TRUSTED",
            slug = "contact_url"
        )

@step('Add an error for this contact to the activity')
def add_error_to_contact(step):

    world.activity.add_error(world.contact)

@step(u'Assert that activity error infos are the same as contact info.')
def assert_that_activity_error_infos_are_the_same_as_contact_info(step):

    assert world.activity.errors
    
    error = world.activity.errors[0]

    assert error["contactKey"] == world.contact.key
    assert error["contactName"] == world.contact.name
    assert error["contactUrl"] == world.contact.url


@step(u'Save current activity')
def save_current_activity(step):

    world.activity.save()

@step(u'Get activity with default activity id')
def get_activity_with_default_activity_id(step):

    world.new_activity = ActivityManager.get_activity(world.activity._id)
    assert world.new_activity is not None

@step(u'Assert that current activity is the same as retrieved activity')
def assert_that_current_activity_is_the_same_as_retrieved_activity(step):
    assert world.activity.docType == world.new_activity.docType
    assert world.activity._id == world.new_activity._id
    assert world.activity.date == world.new_activity.date
    assert world.activity.verb == world.new_activity.verb

@step(u'Clear all activities from database')
def clear_all_activities_from_database(step):
    
    activities = ActivityManager.get_all()
    while activities:
        for activity in activities:
            activity.delete()
        activities = ActivityManager.get_all()

@step(u'Retrieve last activities')
def retrieve_last_activities(step):
    world.activities = ActivityManager.get_all()

@step(u'Assert that there is 0 activities retrieved.')
def assert_that_there_is_0_activities_retrieved(step):
    assert not world.activities

@step(u'Creates (\d+) activities - (\d+) for owner, at ([0-9A-Za-z-:]+)')
def creates_x_activities(step, nb_activities, nb_owner_activities, date):
    for i in range(int(nb_activities)):
        activity = Activity(
            author = "me",
            docId = "aaavvvbbbb%d" % i,
            verb = "write",
            method = "POST",
            isMine = i < int(nb_owner_activities),
            errors = [],
            docType = "micropost",
            date = date_util.getDateFromDbDate(date)
        )<commit_msg>change get db date methode name<commit_after>import sys
import os
import datetime 
import simplejson as json

from lettuce import step, world

sys.path.append("../../../")
os.environ['DJANGO_SETTINGS_MODULE'] = 'newebe.settings'

from tornado.httpclient import HTTPClient

from newebe.lib import date_util
from newebe.activities.models import Activity, ActivityManager
from newebe.core.models import Contact
from newebe.settings import TORNADO_PORT

ROOT_URL = "http://localhost:%d/" % TORNADO_PORT

@step('Take the default activity')
def get_default_activity(step):

    if not hasattr(world, "activity"):
        world.activity = Activity(
            author = "me",
            docId = "aaavvvbbbb",
            verb = "write",
            method = "POST",
            isMine = False,
            errors = [],
            docType = "Micropost",
            date = datetime.datetime(2010, 9, 01, 11, 05, 12)
        )

@step('Take the default contact')
def get_default_contact(step):

    if not hasattr(world, "contact"):
        world.contact = Contact(
            name = "<NAME>",
            key = "contact_key",
            url = "contact_url",
            state = "TRUSTED",
            slug = "contact_url"
        )

@step('Add an error for this contact to the activity')
def add_error_to_contact(step):

    world.activity.add_error(world.contact)

@step(u'Assert that activity error infos are the same as contact info.')
def assert_that_activity_error_infos_are_the_same_as_contact_info(step):

    assert world.activity.errors
    
    error = world.activity.errors[0]

    assert error["contactKey"] == world.contact.key
    assert error["contactName"] == world.contact.name
    assert error["contactUrl"] == world.contact.url


@step(u'Save current activity')
def save_current_activity(step):

    world.activity.save()

@step(u'Get activity with default activity id')
def get_activity_with_default_activity_id(step):

    world.new_activity = ActivityManager.get_activity(world.activity._id)
    assert world.new_activity is not None

@step(u'Assert that current activity is the same as retrieved activity')
def assert_that_current_activity_is_the_same_as_retrieved_activity(step):
    assert world.activity.docType == world.new_activity.docType
    assert world.activity._id == world.new_activity._id
    assert world.activity.date == world.new_activity.date
    assert world.activity.verb == world.new_activity.verb

@step(u'Clear all activities from database')
def clear_all_activities_from_database(step):
    
    activities = ActivityManager.get_all()
    while activities:
        for activity in activities:
            activity.delete()
        activities = ActivityManager.get_all()

@step(u'Retrieve last activities')
def retrieve_last_activities(step):
    world.activities = ActivityManager.get_all()

@step(u'Assert that there is 0 activities retrieved.')
def assert_that_there_is_0_activities_retrieved(step):
    assert not world.activities

@step(u'Creates (\d+) activities - (\d+) for owner, at ([0-9A-Za-z-:]+)')
def creates_x_activities(step, nb_activities, nb_owner_activities, date):
    for i in range(int(nb_activities)):
        activity = Activity(
            author = "me",
            docId = "aaavvvbbbb%d" % i,
            verb = "write",
            method = "POST",
            isMine = i < int(nb_owner_activities),
            errors = [],
            docType = "micropost",
            date = date_util.get_date_from_db_date(date)
        )
{'fraction_non_alphanumeric': 0.10597357840321654, 'fraction_numerical': 0.005169442848937392, 'mean_word_length': 3.23661800486618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5917123', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2073, 'n_words': 509}