forked from codeforamerica/cfapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactories.py
83 lines (64 loc) · 3.49 KB
/
factories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf8 -*-
from random import choice
from datetime import datetime, timedelta
import factory
from factory.alchemy import SQLAlchemyModelFactory
from app import Organization, Project, Event, Story, db, Issue, Label
class OrganizationFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Organization
FACTORY_SESSION = db.session
name = factory.Sequence(lambda n: u'Civiç Örganizatioñ {0}'.format(n))
website = factory.Sequence(lambda n: u'http://www.civicorganization{0}.com'.format(n))
events_url = factory.Sequence(lambda n: u'http://www.meetup.com.com/events/civicproject{0}'.format(n))
rss = factory.Sequence(lambda n: u'http://www.civicorganization{0}.rss'.format(n))
projects_list_url = factory.Sequence(lambda n: u'http://www.civicorganization{0}.com/projects.csv'.format(n))
city = u'San Francisco, CA'
latitude = 37.7749
longitude = -122.4194
type = u'Brigade'
class ProjectFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Project
FACTORY_SESSION = db.session
name = u'Civic Project'
code_url = u'http://www.github.com/civic-project'
link_url = u'http://www.civicproject.com'
description = u'This is a description'
type = factory.LazyAttribute(lambda n: choice([u'web service', u'api', u'data standard']))
categories = factory.LazyAttribute(lambda n: choice([u'housing', u'community engagement', u'criminal justice', u'education']))
github_details = {'repo': u'[email protected]:codeforamerica/civic-project.git'}
organization_name = factory.LazyAttribute(lambda e: OrganizationFactory().name)
status = u'Project status'
class EventFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Event
FACTORY_SESSION = db.session
FACTORY_HIDDEN_ARGS = ('now',)
name = factory.Sequence(lambda n: u'Civic Event {0}'.format(n))
description = u'A civic event'
event_url = factory.Sequence(lambda n: u'http://www.meetup.com/civic-project-hack-night{0}'.format(n))
location = u'155 9th St., San Francisco, CA'
now = factory.LazyAttribute(lambda o: datetime.utcnow())
start_time_notz = factory.LazyAttribute(lambda o: o.now + timedelta(hours=10))
end_time_notz = factory.LazyAttribute(lambda o: o.now + timedelta(hours=12))
utc_offset = -28800
created_at = factory.LazyAttribute(lambda o: o.now)
organization_name = factory.LazyAttribute(lambda e: OrganizationFactory().name)
class StoryFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Story
FACTORY_SESSION = db.session
title = factory.Sequence(lambda n: u'Civic Story {0}'.format(n))
link = u'http://www.codeforamerica.org/blog/2014/03/19/thanks-again-for-your-support-esri/'
type = u'blog'
organization_name = factory.LazyAttribute(lambda e: OrganizationFactory().name)
class IssueFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Issue
FACTORY_SESSION = db.session
title = factory.Sequence(lambda n: u'Civic Issue {0}'.format(n))
html_url = factory.Sequence(lambda n: u'http://www.github.com/codeforamerica/cfapi/issues/{0}'.format(n))
body = factory.Sequence(lambda n: u'Civic Issue blah blah blah {0}'.format(n))
project_id = factory.LazyAttribute(lambda e: ProjectFactory().id)
class LabelFactory(SQLAlchemyModelFactory):
FACTORY_FOR = Label
FACTORY_SESSION = db.session
name = factory.Sequence(lambda n: u'enhancement {0}'.format(n))
url = factory.Sequence(lambda n: u'https://api.github.com/repos/codeforamerica/cfapi/labels/enhancement{0}'.format(n))
color = factory.Sequence(lambda n: u'FFF {0}'.format(n))